仅在提交到母版时触发Jenkins Pipeline作业 [英] Only trigger Jenkins Pipeline job on commit to master

查看:154
本文介绍了仅在提交到母版时触发Jenkins Pipeline作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由github webhook触发的Jenkins Pipeline作业,因此在对Github的提交中,该构建被触发.但是,我只希望在对master分支进行提交时触发构建.当前,即使在功能分支上进行提交,任何提交都会触发构建.

I have a Jenkins Pipeline job which is triggered of a github webhook, so on a commit to Github the build gets triggered. However, I only want the build to be triggered when a commit is made to the master branch. Currently any commit triggers a build even if the commit is made on a feature branch.

有什么方法可以不借助多分支机构的工作来实现这一目标吗?

Is there any way to achieve this without resorting to a multibranch job?

在Jenkins配置,jenkins文件或Github存储库的webhook中,我看不到任何方法可以过滤分支(用于触发器).

I can't see any way to filter on branch (for the trigger) in the Jenkins config, the jenkinsfile or in the Github repo's webhook.

我可以找到的唯一的分支特定信息是代码将从哪个分支构建,但是对任何其他分支的提交仍将触发"构建.

The only branch specific information I can find is which branch the code will build from but a commit to any other branch will still 'trigger' a build.

任何人都可以帮忙吗?

推荐答案

因此,我对这一点的研究越多,我就越意识到斯蒂芬是对的,我应该使用多分支流水线方法.实际上,在较新的Blue Ocean UI中,默认情况下所有管道都是多分支的,这进一步表明这是可行的方法.

So the more I looked into this, the more i realised that Stephen was right and I should be using the multibranch pipeline approach. Indeed, in the newer Blue Ocean UI, all pipelines are multibranch by default, further suggesting this is the way to go.

关于触发构建的第二个问题,这似乎与已设置的分支源有关.这最初是使用git分支源.一旦将其更改为github分支源,并在jenkins中正确配置了github服务器,则触发器将按预期工作.

As to the second issue around triggering the build, this did seem to be related to the branch source that has been set up. This was originally using the git branch source. Once this was changed to a github branch source and the github server configured correctly in jenkins then the trigger worked as expected.

这篇关于仅在提交到母版时触发Jenkins Pipeline作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆