In Jenkins, how can I set the "Branches to build" configuration option of the Pipeline plugin identical to the value of ${BRANCH_NAME}

Viewed 5724

As you can see in the attached screenshot, I want my pipeline to fetch the Jenkinsfile from the same branch that is passed in as a parameter and saved in the BRANCH_NAME variable:

Jenkins Pipeline

2 Answers

I had to uncheck "Lightweight checkout" to make Jenkins parse the ${BRANCH_NAME} parameter under the Pipeline SCM settings:

Pipeline SCM settings - Lightweight checkout

See below:

checkout([$class: 'GitSCM', branches: [[name: "${BRANCH_NAME}"]],  [[credentialsId: 'CRED_ID', url: 'https://url.goes.here']]])

To be more explicit, you could use ${params.BRANCH_NAME}

Related