简体   繁体   中英

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.

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 , eg 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.")
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM