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

Environment variables are always NULL

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Duplicate
    • Component/s: git-plugin
    • Labels:
      None
    • Environment:
      Jenkins 2.8
      Git plugin 2.5.2
      Git client plugin 1.19.6
    • Similar Issues:

      Description

      The environment variables documented here https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin#GitPlugin-AdvancedFeaturesorigin%2Fmaster are always NULL

      Example script

      node (){
          echo "${env.PATH}";
          git branch: 'develop', credentialsId: 'xxxxx', url: 'git@xxx.com:org/repo.git'
          echo "${env.GIT_BRANCH}";
          echo "${env.GIT_URL}";
          echo "${env.JAVA_HOME}";
          echo "${env.NODE_NAME}";
          echo "${env.JOB_NAME}";
      }
      

      Produces this output in the console

      Started by user xxxx
      [Pipeline] node
      Running on xxxx in /home/jenkagent01/jenkinsroot/workspace/pipeline-example
      [Pipeline] {
      [Pipeline] echo
      /usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/opt/dell/srvadmin/bin
      [Pipeline] git
       > git rev-parse --is-inside-work-tree # timeout=10
      Fetching changes from the remote Git repository
       > git config remote.origin.url xxxxx # timeout=10
      Fetching upstream changes from xxxx
       > git --version # timeout=10
      using GIT_SSH to set credentials 
       > git -c core.askpass=true fetch --tags --progress git@xxxx +refs/heads/*:refs/remotes/origin/*
       > git rev-parse refs/remotes/origin/develop^{commit} # timeout=10
       > git rev-parse refs/remotes/origin/origin/develop^{commit} # timeout=10
      Checking out Revision b4d38494c725ccbdc1d66a68a31eb65eb23b3dae (refs/remotes/origin/develop)
       > git config core.sparsecheckout # timeout=10
       > git checkout -f b4d38494c725ccbdc1d66a68a31eb65eb23b3dae # timeout=10
       > git branch -a -v --no-abbrev # timeout=10
       > git branch -D develop # timeout=10
       > git checkout -b develop b4d38494c725ccbdc1d66a68a31eb65eb23b3dae
       > git rev-list b4d38494c725ccbdc1d66a68a31eb65eb23b3dae # timeout=10
      [Pipeline] echo
      null
      [Pipeline] echo
      null
      [Pipeline] echo
      null
      [Pipeline] echo
      xxxxx
      [Pipeline] echo
      pipeline-example
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] End of Pipeline
      Finished: SUCCESS
      

      Searching only leads me to this which seems like a hack -> https://github.com/jenkinsci/pipeline-examples/blob/master/pipeline-examples/gitcommit/gitcommit.groovy

      For example http://stackoverflow.com/questions/35554983/git-variables-in-jenkins-workflow-plugin

        Attachments

          Issue Links

            Activity

            Hide
            cleclerc Cyrille Le Clerc added a comment -

            Note: I humbly edited the ticket and used {code} and {noformat} to ease readibility

            Show
            cleclerc Cyrille Le Clerc added a comment - Note: I humbly edited the ticket and used {code} and {noformat} to ease readibility

              People

              • Assignee:
                Unassigned
                Reporter:
                haddad Haddad Said
              • Votes:
                11 Vote for this issue
                Watchers:
                17 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: