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

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

    Details

    • Similar Issues:

      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

            abcfy2 feng yu created issue -
            abcfy2 feng yu made changes -
            Field Original Value New Value
            Description 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?
            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?
            markewaite Mark Waite made changes -
            Assignee Mark Waite [ markewaite ]
            markewaite Mark Waite made changes -
            Link This issue is duplicated by JENKINS-36436 [ JENKINS-36436 ]
            rtyler R. Tyler Croy made changes -
            Workflow JNJira [ 171461 ] JNJira + In-Review [ 184315 ]
            hrmpw Patrick Wolf made changes -
            Component/s workflow-scm-step-plugin [ 21717 ]
            hrmpw Patrick Wolf made changes -
            Labels pipeline
            jglick Jesse Glick made changes -
            Link This issue duplicates JENKINS-26100 [ JENKINS-26100 ]
            jglick Jesse Glick made changes -
            Status Open [ 1 ] Resolved [ 5 ]
            Resolution Duplicate [ 3 ]
            markewaite Mark Waite made changes -
            Assignee Mark Waite [ markewaite ]
            markewaite Mark Waite made changes -
            Assignee Mark Waite [ markewaite ]
            cloudbees CloudBees Inc. made changes -
            Remote Link This issue links to "CloudBees Internal OSS-1639 (Web Link)" [ 18616 ]
            markewaite Mark Waite made changes -
            Status Resolved [ 5 ] Closed [ 6 ]

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: