As the question says. I can't access it.
Tries:
#1:
def env = System.getenv()
def BUILD_NUMBER= env["BUILD_NUMBER"]
Result:
Null when I access BUILD_NUMBER
#2:
def BUILD_NUMBER= params["BUILD_NUMBER"]
Result:
Null when I access BUILD_NUMBER This solution however works for environment variables I create
Listing Environment Variables Every Jenkins installation has this page called env-vars. html; if you open it in your Jenkins installation, you will see this list of environment variables with some short explanation. You can find variables like BUILD_ID, JOB_NAME, JOB_BASE_NAME, BUILD_URL, JENKINS_URL, and a few others.
Like if I need to inject a value within Steps/Script section, in Jenkins pipeline, I can define globally in the environment variables or using Jenkins project Configure General Check mark Prepare an environment for the run Check mark Keep Jenkins environment variables I can provide the environment variable in the ...
This will work with recent versions of Jenkins and DSL plugin:
def BUILD_NUMBER = getBinding().getVariables()['BUILD_NUMBER']
Jenkins ver. 2.138.2
def gitUrl = binding.variables.get("GITLAB_URL")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With