-
Improvement
-
Resolution: Unresolved
-
Major
-
None
-
CloudBees Jenkins 2.89.3-4-rolling (using Jenkins LTS 2.89.3), with recommended plugins installed (Declarative Pipeline 1.2.6)
On a declarative pipeline, if you set a custom environment variable
with some of the "GIT_" variables in the value, along with "agent none" directive , the the value "null" will be set to those "GIT_" .
It make sense (thanks abayer for the explanation) since with no agent scheduled (so no executor), then no git initialization is done.
The following pipeline illustrate this:
pipeline { agent none environment { MY_VARIABLE="${GIT_COMMIT}" } stages { stage('Show Must Go On') { agent any steps { echo "${GIT_COMMIT}" echo "${MY_VARIABLE}" } } } }
will output the following (461023f607c0bf73b3b6cdd4d5561b42b04b1937 is my commit ID):
{code)
...
[Pipeline] withEnv
[Pipeline]
...
Problem solved by switching "agent none" to "agent any" on the top-level declaration, so the git repo is initialized, and so the "GIT_*" variables are as well, on the top declaration:
pipeline {
agent any
environment {
MY_VARIABLE="${GIT_COMMIT}"
}
stages {
stage('Show Must Go On') {
agent any
steps {
echo "${GIT_COMMIT}"
echo "${MY_VARIABLE}"
}
}
}
}
Should we might materialize this on the doc ?
I'm honestly not sure where this would go in the docs?