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

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

XMLWordPrintable

      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?

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

              Created:
              Updated:
              Resolved: