• Icon: Bug Bug
    • Resolution: Not A Defect
    • Icon: Major Major
    • tfs-plugin
    • None
    • tfs_plugin version 5.126.0
      jenkins version 2.75

      Using Jenkins pipeline job, I am trying to print the TFS_CHANGESET but I get {{null }}

      I also notice environment variables TFS_WORKSPACE / TFS_WORKFOLDER / TFS_PROJECTPATH / TFS_SERVERURL / TFS_USERNAME show "null" as well.

      example code:

      import hudson.plugins.tfs.TeamFoundationServerScm
      node {
        serverUrl = "http://SERVERNAME:8080/tfs/ORG"
        projectPath = "\$/DigitalPlatforms/Syndication/Dev"
          try {
              deleteDir()
              stage 'download-from-scm'
              def workspace = pwd() + '/' + "Hudson-testingtfs-MASTER"
              ws("/var/lib/jenkins/testing/testingtfs" + '/' + "Hudson-testingtfs-MASTER") {
              def out = checkout changelog: false, poll: false, scm: [$class: 'TeamFoundationServerScm', credentialsConfigurer: [$class: 'AutomaticCredentialsConfigurer'], projectPath: "${projectPath}", serverUrl: "${serverUrl}", useOverwrite: true, useUpdate: true, workspaceName: 'Hudson-${JOB_NAME}-${NODE_NAME}']
      
      echo "${workspace}/${env.TFS_CHANGESET}"  //null for TFS_CHANGESET
      echo "${env.TFS_CHANGESET}"  //null
      }
              } catch (err) {
                   currentBuild.result = 'FAILED'
                   throw err
                   }
      }
      

          [JENKINS-48847] tfs_changeset not working

          can you try the following code to print out the env vars that are available?

          code:

          node {
              sh 'env > env.txt'
              readFile('env.txt').split("\r?\n").each {
                  println it
              }
          }
          

          Jason Prickett added a comment - can you try the following code to print out the env vars that are available? code: node { sh 'env > env.txt' readFile( 'env.txt' ).split( "\r?\n" ).each { println it } }

          Roshan Shetty added a comment -

          Sure here it is..

          // code placeholder
          

          Querying for remote changeset at '$/EditorialApplications/Exposure/DotNet/release' as of 'D2018-01-10T14:34:08Z'...
          Query result is: Changeset #59779 by 'XXX\SXXX' on '2017-12-13T22:59:19Z'.
          Checking if there exists a mapping for /var/lib/jenkins/workspace/testing/testingtfs@2...yes, in workspace 'Hudson-testingtfs-MASTER'.
          Downloading list of workspaces from
          http://XXXX.XX.org:8080/tfs/eAP
          ...
          Getting version 'C59779' to '/var/lib/jenkins/workspace/testing/testingtfs@2'...
          Finished getting version 'C59779'. Retrieved 0 resources.
          [Pipeline] sh
          [testingtfs@2] Running shell script
          + env
          [Pipeline] readFile
          [Pipeline] echo
          JENKINS_NODE_COOKIE=a956f8c4-92ee-474e-a0a7-1eec2fe6a5ee
          [Pipeline] echo
          BUILD_URL=
          http://dnejenkinsqa.aptechlab.com:8080/job/testing/job/testingtfs/152/
          [Pipeline] echo
          GEM_HOME=/usr/local/rvm/gems/ruby-2.4.2
          [Pipeline] echo
          SHELL=/bin/bash
          [Pipeline] echo
          HUDSON_SERVER_COOKIE=5846e538d44542f5
          [Pipeline] echo
          UNIX_STACKUTILS=/var/lib/jenkins/UploadUtilitiesUnix/Ruby/stack_utilsv2.rb
          [Pipeline] echo
          BUILD_TAG=jenkins-testing-testingtfs-152
          [Pipeline] echo
          JOB_URL=
          http://dnejenkinsqa.aptechlab.com:8080/job/testing/job/testingtfs/
          [Pipeline] echo
          WORKSPACE=/var/lib/jenkins/workspace/testing/testingtfs@2
          [Pipeline] echo
          RUN_CHANGES_DISPLAY_URL=
          http://dnejenkinsqa.aptechlab.com:8080/job/testing/job/testingtfs/152/display/redirect?page=changes
          [Pipeline] echo
          USER=jenkins
          [Pipeline] echo
          JENKINS_HOME=/var/lib/jenkins
          [Pipeline] echo
          NLSPATH=/usr/dt/lib/nls/msg/%L/%N.cat
          [Pipeline] echo
          PATH=/usr/local/rvm/gems/ruby-2.4.2/bin:/usr/local/rvm/gems/ruby-2.4.2@global/bin:/usr/local/rvm/rubies/ruby-2.4.2/bin:/usr/local/rvm/bin:/opt/maven/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin
          [Pipeline] echo
          RUN_DISPLAY_URL=
          http://dnejenkinsqa.aptechlab.com:8080/job/testing/job/testingtfs/152/display/redirect
          [Pipeline] echo
          library.dne-shared-library.version=cleanup
          [Pipeline] echo
          _=/bin/env
          [Pipeline] echo
          PWD=/var/lib/jenkins/workspace/testing/testingtfs@2
          [Pipeline] echo
          HUDSON_URL=
          http://dnejenkinsqa.aptechlab.com:8080/
          [Pipeline] echo
          LANG=en_US.UTF-8
          [Pipeline] echo
          JOB_NAME=testing/testingtfs
          [Pipeline] echo
          XFILESEARCHPATH=/usr/dt/app-defaults/%L/Dt
          [Pipeline] echo
          BUILD_DISPLAY_NAME=#152
          [Pipeline] echo
          BUILD_ID=152
          [Pipeline] echo
          JENKINS_URL=
          http://dnejenkinsqa.aptechlab.com:8080/
          [Pipeline] echo
          JOB_BASE_NAME=testingtfs
          [Pipeline] echo
          HOME=/var/lib/jenkins
          [Pipeline] echo
          SHLVL=4
          [Pipeline] echo
          EXECUTOR_NUMBER=0
          [Pipeline] echo
          JENKINS_SERVER_COOKIE=durable-3683e36d0e611daacc6261e5245009e2
          [Pipeline] echo
          NODE_LABELS=master
          [Pipeline] echo
          LOGNAME=jenkins
          [Pipeline] echo
          HUDSON_HOME=/var/lib/jenkins
          [Pipeline] echo
          GEM_PATH=/usr/local/rvm/gems/ruby-2.4.2:/usr/local/rvm/gems/ruby-2.4.2@global
          [Pipeline] echo
          NODE_NAME=master
          [Pipeline] echo
          BUILD_NUMBER=152
          [Pipeline] echo
          JOB_DISPLAY_URL=
          http://dnejenkinsqa.aptechlab.com:8080/job/testing/job/testingtfs/display/redirect
          [Pipeline] echo
          HUDSON_COOKIE=6b520e39-d72d-4da7-aa99-edcdd3b68c78
          [Pipeline] }
          [Pipeline] // ws
          [Pipeline] }
          [Pipeline] // node
          [Pipeline] End of Pipeline

          Roshan Shetty added a comment - Sure here it is.. // code placeholder Querying for remote changeset at '$/EditorialApplications/Exposure/DotNet/release' as of 'D2018-01-10T14:34:08Z'... Query result is: Changeset #59779 by 'XXX\SXXX' on '2017-12-13T22:59:19Z'. Checking if there exists a mapping for /var/lib/jenkins/workspace/testing/testingtfs@2...yes, in workspace 'Hudson-testingtfs-MASTER'. Downloading list of workspaces from http://XXXX.XX.org:8080/tfs/eAP ... Getting version 'C59779' to '/var/lib/jenkins/workspace/testing/testingtfs@2'... Finished getting version 'C59779'. Retrieved 0 resources. [Pipeline] sh [testingtfs@2] Running shell script + env [Pipeline] readFile [Pipeline] echo JENKINS_NODE_COOKIE=a956f8c4-92ee-474e-a0a7-1eec2fe6a5ee [Pipeline] echo BUILD_URL= http://dnejenkinsqa.aptechlab.com:8080/job/testing/job/testingtfs/152/ [Pipeline] echo GEM_HOME=/usr/local/rvm/gems/ruby-2.4.2 [Pipeline] echo SHELL=/bin/bash [Pipeline] echo HUDSON_SERVER_COOKIE=5846e538d44542f5 [Pipeline] echo UNIX_STACKUTILS=/var/lib/jenkins/UploadUtilitiesUnix/Ruby/stack_utilsv2.rb [Pipeline] echo BUILD_TAG=jenkins-testing-testingtfs-152 [Pipeline] echo JOB_URL= http://dnejenkinsqa.aptechlab.com:8080/job/testing/job/testingtfs/ [Pipeline] echo WORKSPACE=/var/lib/jenkins/workspace/testing/testingtfs@2 [Pipeline] echo RUN_CHANGES_DISPLAY_URL= http://dnejenkinsqa.aptechlab.com:8080/job/testing/job/testingtfs/152/display/redirect?page=changes [Pipeline] echo USER=jenkins [Pipeline] echo JENKINS_HOME=/var/lib/jenkins [Pipeline] echo NLSPATH=/usr/dt/lib/nls/msg/%L/%N.cat [Pipeline] echo PATH=/usr/local/rvm/gems/ruby-2.4.2/bin:/usr/local/rvm/gems/ruby-2.4.2@global/bin:/usr/local/rvm/rubies/ruby-2.4.2/bin:/usr/local/rvm/bin:/opt/maven/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin [Pipeline] echo RUN_DISPLAY_URL= http://dnejenkinsqa.aptechlab.com:8080/job/testing/job/testingtfs/152/display/redirect [Pipeline] echo library.dne-shared-library.version=cleanup [Pipeline] echo _=/bin/env [Pipeline] echo PWD=/var/lib/jenkins/workspace/testing/testingtfs@2 [Pipeline] echo HUDSON_URL= http://dnejenkinsqa.aptechlab.com:8080/ [Pipeline] echo LANG=en_US.UTF-8 [Pipeline] echo JOB_NAME=testing/testingtfs [Pipeline] echo XFILESEARCHPATH=/usr/dt/app-defaults/%L/Dt [Pipeline] echo BUILD_DISPLAY_NAME=#152 [Pipeline] echo BUILD_ID=152 [Pipeline] echo JENKINS_URL= http://dnejenkinsqa.aptechlab.com:8080/ [Pipeline] echo JOB_BASE_NAME=testingtfs [Pipeline] echo HOME=/var/lib/jenkins [Pipeline] echo SHLVL=4 [Pipeline] echo EXECUTOR_NUMBER=0 [Pipeline] echo JENKINS_SERVER_COOKIE=durable-3683e36d0e611daacc6261e5245009e2 [Pipeline] echo NODE_LABELS=master [Pipeline] echo LOGNAME=jenkins [Pipeline] echo HUDSON_HOME=/var/lib/jenkins [Pipeline] echo GEM_PATH=/usr/local/rvm/gems/ruby-2.4.2:/usr/local/rvm/gems/ruby-2.4.2@global [Pipeline] echo NODE_NAME=master [Pipeline] echo BUILD_NUMBER=152 [Pipeline] echo JOB_DISPLAY_URL= http://dnejenkinsqa.aptechlab.com:8080/job/testing/job/testingtfs/display/redirect [Pipeline] echo HUDSON_COOKIE=6b520e39-d72d-4da7-aa99-edcdd3b68c78 [Pipeline] } [Pipeline] // ws [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline

          Roshan Shetty added a comment -

          changeset id 59779 is there in the output just not available in TFS_CHANGESET variable seems like.

          Roshan Shetty added a comment - changeset id 59779 is there in the output just not available in TFS_CHANGESET variable seems like.

          The problem here was documentation and plugin version

          The first hurdle is knowing that you must use the returned Map object from the call the checkout to get the SCM environment variables. They are NOT just added to the environment when you call checkout.

          The second hurdle is getting the latest version of the Pipeline: SCM Step plugin. The env vars are only returned from checkout in Version 2.6 and higher. Since this plugin is part of the Pipeline plugin you have to have a compatible version of Jenkins that can support Pipeline version 2.5 or later.

          I was able to repro the problem and then upgrade the versions of everything and verify that the "out" variable in the Pipeline code above did have the SCM env vars like TFS_CHANGESET.

          Jason Prickett added a comment - The problem here was documentation and plugin version The first hurdle is knowing that you must use the returned Map object from the call the checkout to get the SCM environment variables. They are NOT just added to the environment when you call checkout. The second hurdle is getting the latest version of the Pipeline: SCM Step plugin. The env vars are only returned from checkout in Version 2.6 and higher. Since this plugin is part of the Pipeline plugin you have to have a compatible version of Jenkins that can support Pipeline version 2.5 or later. I was able to repro the problem and then upgrade the versions of everything and verify that the "out" variable in the Pipeline code above did have the SCM env vars like TFS_CHANGESET.

          See my other comment. Upgrading the version of the Pipeline plugins and using the return value from checkin works.

          Jason Prickett added a comment - See my other comment. Upgrading the version of the Pipeline plugins and using the return value from checkin works.

          Roshan Shetty added a comment -

          Yes works well after the plugin update to 2.6, thank you Jason.

          Roshan Shetty added a comment - Yes works well after the plugin update to 2.6, thank you Jason.

            jpricketmsft Jason Prickett
            rshetty Roshan Shetty
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: