Jenkins get variable GIT_URL is not available if "Skip default checkout" is marked

Viewed 1702

If I set in Jenkinsfile:

options { skipDefaultCheckout() }

then in steps in pipeline below, variable ${env.GIT_URL} appeared do not available. For example cannot complete step:

stage('Clean checkout') {
            steps {
                checkout([$class: 'GitSCM', branches: [[name: "master"]],
                         userRemoteConfigs: [[url: "${env.GIT_URL}"]]])
            }
        }

in this step variable ${env.GIT_URL} = null due to build console log.

But if you enable back default checkout, so delete:

options { skipDefaultCheckout() }

Then ${env.GIT_URL} became available. Is it expected behaviour? I cannot see Git plugin variables in Pipeline where disabled declarative checkout?

2 Answers

In our Jenkinsfile, we have

    options {
        skipDefaultCheckout true
    }

    environment {
        GIT_URL = 'git@github.com:mycompany/myproject.git'
    }

After this, the variable GIT_URL is available and populated.

Related