-
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 ?
[JENKINS-49174] Declarative Pipeline: GIT_* have the value 'null' when using "agent none"
Assignee | Original: Mark Waite [ markewaite ] |
Component/s | New: pipeline-model-definition-plugin [ 21706 ] | |
Component/s | Original: git-plugin [ 15543 ] | |
Component/s | Original: pipeline [ 21692 ] |
I'm honestly not sure where this would go in the docs?