Abhilash
Abhilash

Reputation: 15

Jenkins Multibranch pipeline pull request

I am using multibranch pipeline for pullrequest. When a pr is created it triggers the pullrequest job. Is there anyway to trigger the job only on specific pull requests instead of all. example: I have three branches develop, fb and master. I want to trigger the job only when I create a pull request from develop to master, not when I create a pullrequest from fb to develop or fb to master.

Upvotes: 0

Views: 1856

Answers (1)

MaratC
MaratC

Reputation: 6869

In this case you may want to run your pipeline, analyze the base branch, and stop if the base branch is not to your liking.

The environment variable CHANGE_ID is set by the github branch source plugin in case the branch is a pull request.

If it's set, you can explore the global object named pullRequest, e.g. like this:

    if (env.CHANGE_ID) {
        echo("Looking for PR: PR detected, change id is ${env.CHANGE_ID}")
        def prBase = pullRequest.base
        if (prBase != 'master') {
            currentBuild.result = 'ABORTED'
            error("This PR is over ${prBase} branch, not 'master'. Aborting.")
        }
    }

Upvotes: 2

Related Questions