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 master branch). I have a Jenkinsfile for a multibranch pipeline with:

steps {
$class: ‘GitSCM’,
branches: [[name: env.BRANCH_NAME]],
extensions: [[$class: ‘LocalBranch’]],
userRemoteConfigs: [[credentialsId: ‘XXX’, url: ‘’]]

I keep getting the following error:
Error when executing failure post condition: 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.