Pipeline token macro expansion fails for GIT_BRANCH and GIT_REVISION

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: Minor
    • None
    • Environment:
      Token macro plugin 266.v44a80cf277fd
      Git plugin 4.8.2
    • 4.10.0

      The token macro plugin provides a pipeline task, tm that can expand token macros. It works very well for the BUILD_NUMBER token, but does not work for the GIT_BRANCH token.

      Working example

      node {
          stage('Working example') {
              echo('Build number value is ' + tm('${BUILD_NUMBER}'))
              echo('Build number length is ' + tm('${#BUILD_NUMBER}'))
              echo('Build number first character is ' + tm('${BUILD_NUMBER:0:1}'))
          }
      }
      

      The output lists the build number, the length of the build number string, and the first character of the build number. Those are good results and as described in the token macro plugin documentation.

      Failing example

      node {
          stage('Failing example') {
              git 'https://github.com/jenkinsci/git-client-plugin.git'
              echo('Git branch value is ' + tm('${GIT_BRANCH}'))
              echo('Git branch length is ' + tm('${#GIT_BRANCH}'))
              echo('Git branch first character is ' + tm('${GIT_BRANCH:0:1}'))
          }
      }
      

      The failing output is 'GIT_BRANCH is not supported in this context'.

      I've not found any syntax that will allow the GIT_BRANCH token macro to be evaluated by the tm pipeline step.

            Assignee:
            Alex Earl
            Reporter:
            Mark Waite
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: