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

Environment variables are always NULL

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Duplicate
    • git-plugin
    • None
    • Jenkins 2.8
      Git plugin 2.5.2
      Git client plugin 1.19.6

    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

            haddad Haddad Said created issue -
            markewaite Mark Waite made changes -
            Field Original Value New Value
            Assignee Mark Waite [ markewaite ]
            markewaite Mark Waite made changes -
            Link This issue duplicates JENKINS-35230 [ JENKINS-35230 ]
            rtyler R. Tyler Croy made changes -
            Workflow JNJira [ 173143 ] JNJira + In-Review [ 184961 ]
            cleclerc Cyrille Le Clerc made changes -
            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

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

            Example script
            {code}
            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}";
            }
            {code}

            Produces this output in the console


            {noformat}
            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
            {noformat}

            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

            jglick Jesse Glick made changes -
            Link This issue duplicates JENKINS-26100 [ JENKINS-26100 ]
            jglick Jesse Glick made changes -
            Resolution Duplicate [ 3 ]
            Status Open [ 1 ] Resolved [ 5 ]
            cloudbees CloudBees Inc. made changes -
            Remote Link This issue links to "CloudBees Internal OSS-1639 (Web Link)" [ 18617 ]
            markewaite Mark Waite made changes -
            Status Resolved [ 5 ] Closed [ 6 ]

            People

              Unassigned Unassigned
              haddad Haddad Said
              Votes:
              11 Vote for this issue
              Watchers:
              18 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: