I have a shared global function on PublishGitHub.groovy looks like this:
#!/usr/bin/env groovy
def call(body)
{
def config = [:]
body.resolveStrategy = Closure.DELEGATE_FIRST
body.delegate = config
echo "\u001B[32mINFO: Publishing...\u001B[m"
body()
echo "\u001B[32mINFO: End Publish...\u001B[m"
}
And a code on my JenkinsFile:
environment {
VERSION = "v1.3.${env.BUILD_NUMBER}"
}
stages {
stage ('Publish WebAPI'){
steps{
echo "\u001B[32mINFO: Start Publish...\u001B[m"
PublishGitHub{
echo "This is a body with version: ${env.VERSION}"
}
}
}
}
And this is my output:
[Pipeline] echo
INFO: Start Publish...
[Pipeline] echo
INFO: Publishing...
[Pipeline] }
And follow next error:
java.lang.NullPointerException: Cannot get property 'VERSION' on null object
Because inside the body I do not have access to the environment variables?