简体   繁体   English

Jenkins 多分支管道拉取请求

[英]Jenkins Multibranch pipeline pull request

I am using multibranch pipeline for pullrequest.我正在为 pullrequest 使用多分支管道。 When a pr is created it triggers the pullrequest job.创建 pr 时,它会触发 pullrequest 作业。 Is there anyway to trigger the job only on specific pull requests instead of all.无论如何,是否仅针对特定的拉取请求而不是全部触发作业。 example: I have three branches develop, fb and master.示例:我有三个分支 develop、fb 和 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.我只想在创建从 develop 到 master 的拉取请求时触发作业,而不是在创建从 fb 到开发或 fb 到 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.环境变量CHANGE_ID由 github 分支源插件设置,以防分支是拉取请求。

If it's set, you can explore the global object named pullRequest , eg like this:如果已设置,您可以探索名为pullRequest ,例如:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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