Checkout with environmental variable

I have a Multibranch pipeline using a Jenkinsfile and I would like to control the checkout to use SSH url for GitHub repo. Would like to build a feature branch (the current branch) that is triggering the job (not the controller branch). I have a Jenkinsfile for a multibranch pipeline with:

steps {
checkout([
$class: ‘GitSCM’,
branches: [[name: env.BRANCH_NAME]],
extensions: [[$class: ‘LocalBranch’]],
userRemoteConfigs: [[credentialsId: ‘XXX’, url: ‘git@github.com:XXX.git’]]
])

I keep getting the following error:
Error when executing failure post condition:
java.io.IOException: Cannot retrieve Git metadata for the build

I believe the issue is with “branches: [[name: env.BRANCH_NAME]],” but not sure what it should be instead. I have tried env.BRANCH_NAME and {env.BRANCH_NAME} as well.

Additionally, this is in the log:

git rev-parse “origin/feature-0001^{commit}” # timeout=10
git rev-parse “feature-0001^{commit}” # timeout=10

Not sure where the “^{commit}” is coming from or if it’s causing any issues.

Any guidance would be appreciated. Thank you.

Since you’re in a multibranch Pipeline, you can use the properties that are already on the scm global variable.

An example is available at

Alternately, you might use a declarative Pipeline and rely on the default checkout that is performed by declarative Pipeline.

1 Like

Hi,
I am trying to git checkout of one my feature branch of bitbucket on unix remote server using jenkins.

1)My jenkins server is running on local node.
2)SIT server is resided on unix server.
3)I am trying to checkout shell scripts from bitbucket repo(feature branch) on unix using jenkins job.

What could be the best possible approach to perform the activity?

Thanks ,

Sanket