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

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

      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?

          [JENKINS-35230] The environment variables of git plugin not working in pipeline script.

          feng yu created issue -
          feng yu made changes -
          Description Original: Here is my pipeline code:

          {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('|')
          {code}

          But finally it gives me this error:

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

          Is the environment variables still working for pipeline?
          New: Here is my pipeline code:

          {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('|')
          }

          {code}

          But finally it gives me this error:

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

          Is the environment variables still working for pipeline?
          Mark Waite made changes -
          Assignee Original: Mark Waite [ markewaite ]
          Mark Waite made changes -
          Link New: This issue is duplicated by JENKINS-36436 [ JENKINS-36436 ]
          R. Tyler Croy made changes -
          Workflow Original: JNJira [ 171461 ] New: JNJira + In-Review [ 184315 ]
          Patrick Wolf made changes -
          Component/s New: workflow-scm-step-plugin [ 21717 ]
          Patrick Wolf made changes -
          Labels New: pipeline
          Jesse Glick made changes -
          Link New: This issue duplicates JENKINS-26100 [ JENKINS-26100 ]
          Jesse Glick made changes -
          Resolution New: Duplicate [ 3 ]
          Status Original: Open [ 1 ] New: Resolved [ 5 ]
          Mark Waite made changes -
          Assignee New: Mark Waite [ markewaite ]
          Mark Waite made changes -
          Assignee Original: Mark Waite [ markewaite ]

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

              Created:
              Updated:
              Resolved: