Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-68704

Multibranch Pipeline jobs lack executor's environment variables

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved (View Workflow)
    • Major
    • Resolution: Not A Defect
    • core, pipeline
    • None
    • Jenkins 2.303.3
      Pipeline 2.7
      Pipeline: Multibranch 716.vc692a_e52371b_

    Description

      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. 

      Attachments

        Activity

          meiswjn Jan added a comment - - edited Fix: [JENKINS-68704] Give Multibranch pipelines access to environment variables by meiswjn · Pull Request #6626 · jenkinsci/jenkins (github.com)
          jglick Jesse Glick added a comment -

          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.

          jglick Jesse Glick added a comment - 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.
          meiswjn Jan added a comment -

          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 

          meiswjn Jan added a comment - 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  
          meiswjn Jan added a comment -

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

          meiswjn Jan added a comment - Apparently, a system-wide git config entry is respected by the git-client plugin. This will be an acceptable workaround for us.
          jglick Jesse Glick added a comment -

          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.

          jglick Jesse Glick added a comment - 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.
          meiswjn Jan added a comment -

          I mean the git checkout on the agent.

          meiswjn Jan added a comment - I mean the git checkout on the agent.
          jglick Jesse Glick added a comment -

          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.

          jglick Jesse Glick added a comment - 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.

          People

            meiswjn Jan
            meiswjn Jan
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: