Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 353
Behrang Avatar asked Nov 08 '17 06:11

Behrang


People also ask

What is branches to build in Jenkins pipeline?

When the pipeline build starts, Jenkins uses the Jenkinsfile in that branch for build stages. SCM (Source Control) can be Github, Bitbucket, or a Gitlab repo. You can choose to exclude selected branches if you don't want them to be in the automated pipeline with Java regular expressions.

How do I add a branch to Jenkins build?

Login to your Jenkins installation and go you your job and click configure. In the Source Code Management section under Build Triggers check the Generic Webhook Trigger. Click Add next to the Post content parameters. Once a push is made, GitHub passes the branch name in the JSON format with the ref key.

What is build pipeline plugin in Jenkins?

Summary. This plugin provides a Build Pipeline View of upstream and downstream connected jobs that typically form a build pipeline. In addition, it offers the ability to define manual triggers for jobs that require intervention prior to execution, e.g. an approval process outside of Jenkins.

How can I see Jenkins pipeline configuration?

Click New Item on your Jenkins home page, enter a name for your (pipeline) job, select Pipeline, and click OK. In the Script text area of the configuration screen, enter your pipeline syntax.


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

like image 180
Behrang Avatar answered Nov 04 '22 20:11

Behrang


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}

like image 40
Rob Hales Avatar answered Nov 04 '22 20:11

Rob Hales