timja / jenkins-gh-issues-poc-06-18

0 stars 0 forks source link

[JENKINS-68704] Multibranch Pipeline jobs lack executor's environment variables #6054

Closed timja closed 2 years ago

timja commented 2 years ago

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:


Originally reported by meiswjn, imported from: Multibranch Pipeline jobs lack executor's environment variables
  • assignee: meiswjn
  • status: Resolved
  • priority: Major
  • resolution: Not A Defect
  • resolved: 2022-06-08T20:23:59+00:00
  • imported: 2022/01/10
timja commented 2 years ago

JIRAUSER133599:

Fix: [JENKINS-68704] Give Multibranch pipelines access to environment variables by meiswjn · Pull Request #6626 · jenkinsci/jenkins (github.com)

timja commented 2 years ago

jglick:

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.

timja commented 2 years ago

JIRAUSER133599:

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.
jglick 

timja commented 2 years ago

JIRAUSER133599:

Apparently, a system-wide git config entry is respected by the git-client plugin. This will be an acceptable workaround for us.

timja commented 2 years ago

jglick:

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.

timja commented 2 years ago

JIRAUSER133599:

I mean the git checkout on the agent.

timja commented 2 years ago

jglick:

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.