Skip to content

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

Description

@jenkins-infra-bot

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?


Originally reported by abcfy2, imported from: The environment variables of git plugin not working in pipeline script.
  • status: Closed
  • priority: Minor
  • component(s): git-plugin, workflow-scm-step-plugin
  • label(s): pipeline
  • resolution: Duplicate
  • resolved: 2017-02-15T16:52:30+00:00
  • votes: 29
  • watchers: 45
  • imported: 2025-12-02
Raw content of original issue

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions