Status: Resolved (View Workflow)
Resolution: Not A Defect
Pipeline: Multibranch 716.vc692a_e52371b_
As seen in Freestyle jobs, a run has access to all environment variables of the executor (also optionally configured in the node configuration). This is not the case for multibranch pipelines. They merely get the environment variables that are dynamically set by Jenkins.
How to reproduce this bug:
- Setup a Jenkins instance with Pipeline plugin.
- Create a freestyle job and a pipeline job.
- Set a break point here: jenkins/Run.java at master · jenkinsci/jenkins (github.com).
- Run Jenkins in Debug mode and compare the populated environment variables. Freestlye jobs will have access to the node's env vars, pipeline not.
For Pipeline builds, environment variables from agents are set only inside node blocks, for the EnvVars contextual object passed to steps running inside that block. You cannot use Run-level methods to get this information.
The problem is that some processes like the git checkout need proxy information before the evaluation of the Jenkinsfile. The proxy inherited from the Jenkins Controller may work on the controller but not necessarily on the agent.
Apparently, a system-wide git config entry is respected by the git-client plugin. This will be an acceptable workaround for us.
some processes like the git checkout need proxy information before the evaluation of the Jenkinsfile
You mean for Git checkouts run on the controller, say to get Jenkinsfile itself or some library? Not much to be done about that, since before the program starts it is unknown which agent will be used—or if any agent will be used, or many.
A checkout or git step run inside a node block ought to have access to environment variables defined on the corresponding computer (whatever is exposed to the agent JVM process). If that does not seem to be the case, file a bug in git-plugin with complete and exact steps to reproduce from scratch.
Fix: [JENKINS-68704] Give Multibranch pipelines access to environment variables by meiswjn · Pull Request #6626 · jenkinsci/jenkins (github.com)