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

[Git Plugin] Environment variables are not set when using pipelines

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Minor
    • Resolution: Not A Defect
    • Component/s: git-plugin
    • Labels:
      None
    • Environment:
      Jenkins ver. 2.121.1
      Blue Ocean 1.6.2
      Git plugin 3.9.1
    • Similar Issues:

      Description

      Considering the docs:

      GIT_LOCAL_BRANCH - Name of the branch on Jenkins. When the "checkout to specific local branch" behavior is configured, the variable is published.  If the behavior is configured as null or **, the property will contain the resulting local branch name sans the remote name.

      I have set the checkout to specific local branch to ** using an SCM managed Jenkinsfile (not multibranch). In the Jenkinsfile I try to access the GIT_LOCAL_BRANCH variable but it is set to null. Same goes for the other env variables mentioned in the [docs|https://wiki.jenkins.io/display/JENKINS/Git+Plugin.]

      On printing all the env variables using:

      echo bat(script: 'env|sort', returnStdout: true)
      

      none of the a fore mentioned env variable are available.

      If I try to access the env variable in a normal job, it is set correctly.

       

        Attachments

          Activity

          Hide
          markewaite Mark Waite added a comment -

          Pipeline allows multiple checkout operations to be performed. Environment variables from earlier checkout steps would be overwritten by environment variables from later checkout steps.

          Rather than use environment variables, the Pipeline checkout step returns a map of name/value pairs that are the result of that specific checkout operation. Refer to the checkout step documentation for more details.

          A Jenkins Minute video is also available which shows how to use the map returned by checkout.

          Show
          markewaite Mark Waite added a comment - Pipeline allows multiple checkout operations to be performed. Environment variables from earlier checkout steps would be overwritten by environment variables from later checkout steps. Rather than use environment variables, the Pipeline checkout step returns a map of name/value pairs that are the result of that specific checkout operation. Refer to the checkout step documentation for more details. A Jenkins Minute video is also available which shows how to use the map returned by checkout.

            People

            Assignee:
            markewaite Mark Waite
            Reporter:
            incubusattax Joshua Bromme
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: