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

The environment variables of git plugin not working in pipeline script.

    XMLWordPrintable

Details

    Description

      Here is my pipeline code:

      node {
          checkout changelog: true,
              poll: true,
              scm: [
                  $class: 'GitSCM', 
                  branches: [[name: "${env.gitlabSourceRepoName}/${env.gitlabSourceBranch}"]],
                  doGenerateSubmoduleConfigurations: false, 
                  extensions: [
                      [$class: 'PruneStaleBranch'],
                      [
                          $class: 'PreBuildMerge', options: [
                              fastForwardMode: 'FF', 
                              mergeRemote: 'origin', 
                              mergeStrategy: 'default', 
                              mergeTarget: "${env.gitlabTargetBranch}"
                          ]
                      ],
                      [$class: 'CleanCheckout']
                  ], 
                  userRemoteConfigs: [
                      [name: 'origin', url: 'git@gitlab.mydomain.com:user/project.git', credentialsId: '8949144f-cca9-4385-8597-ad3c14bbd7ce'],
                      [name: "${env.gitlabSourceRepoName}", url: "${env.gitlabSourceRepoURL}", credentialsId: '8949144f-cca9-4385-8597-ad3c14bbd7ce']
                  ],
                  browser: [$class: 'GitLab', repoUrl: 'http://gitlab.mydomain.com', version: '8.8']
              ]
      
          echo """
                   |GIT_COMMIT: ${GIT_COMMIT}
                   |GIT_BRANCH: ${GIT_BRANCH }
                   """.stripMargin('|')
      }
      
      

      But finally it gives me this error:

      groovy.lang.MissingPropertyException: No such property: GIT_BRANCH for class: WorkflowScript
      

      Is the environment variables still working for pipeline?

      Attachments

        Issue Links

          Activity

            Thanks Mark,

            As suggested, I can able to get the Git details with Pipeline SCM plugin 2.6,

            <snip>

            map_vars = checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'admin', url: 'http://test.git.url']])|http://test.git.url%27]]]%29/]

            print map_vars

            </snip>

            Is there a way to send/inject these details into Jenkins AbstractBuild/Run or TaskListener object? Actually I need to use these details in my plugin.

             

             

            hariharan Hariharan Kuppusamy added a comment - Thanks Mark, As suggested, I can able to get the Git details with Pipeline SCM plugin 2.6, <snip> map_vars = checkout([$class: 'GitSCM', branches: [ [name: '*/master'] ], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'admin', url: ' http://test.git.url' ]])|http://test.git.url%27]]]%29/] print map_vars </snip> Is there a way to send/inject these details into Jenkins AbstractBuild/Run or TaskListener object? Actually I need to use these details in my plugin.    
            markewaite Mark Waite added a comment - - edited

            hariharan, I don't know the technique you would use to obtain those values in your plugin by calling the git plugin. Possibly @jglick could offer a suggestion?

            markewaite Mark Waite added a comment - - edited hariharan , I don't know the technique you would use to obtain those values in your plugin by calling the git plugin. Possibly @jglick could offer a suggestion?
            jglick Jesse Glick added a comment -

            The values will not be accessible from another plugin, by design. Your plugin may accept standard data-bound parameters, and a user’s script may pass variables from checkout (in original or modified form) to your plugin, or not.

            jglick Jesse Glick added a comment - The values will not be accessible from another plugin, by design. Your plugin may accept standard data-bound parameters, and a user’s script may pass variables from checkout (in original or modified form) to your plugin, or not.
            shmup Jared Miller added a comment -

            This is not at all obvious if you just glance over: https://wiki.jenkins.io/display/JENKINS/Git+Plugin

            You'd never expect that to access those ENV variables you have to capture the output of checkout.

            Or am I mistaken? 

            shmup Jared Miller added a comment - This is not at all obvious if you just glance over: https://wiki.jenkins.io/display/JENKINS/Git+Plugin You'd never expect that to access those ENV variables you have to capture the output of checkout. Or am I mistaken? 
            markewaite Mark Waite added a comment -

            shmup, the wiki is not the preferred location for Pipeline documentation. Refer to the Pipeline: SCM Step page for an example using the environment variables as a map returned from the `checkout` step. There is a Jenkins Minute video that describes it as well. You can also read about it (briefly) in the Pipeline: SCM Step plugin page.

            If you'd like to add it to the Git plugin Wiki, you're welcome to do that as well.

            markewaite Mark Waite added a comment - shmup , the wiki is not the preferred location for Pipeline documentation. Refer to the Pipeline: SCM Step page for an example using the environment variables as a map returned from the `checkout` step. There is a Jenkins Minute video that describes it as well. You can also read about it (briefly) in the Pipeline: SCM Step plugin page . If you'd like to add it to the Git plugin Wiki, you're welcome to do that as well.

            People

              Unassigned Unassigned
              abcfy2 feng yu
              Votes:
              29 Vote for this issue
              Watchers:
              45 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: