简体   繁体   English

Jenkins Gitlab 集成 - 仅建立在推送到主分支的基础上

[英]Jenkins Gitlab integration - build on pushes to master branch only

I have the same question as this one: Trigger build only on pushes to master我有同样的问题: Trigger build only on pushes to master

Only the answer there is not correct.只有那里的答案不正确。 Does anybody know a solution?有人知道解决方案吗? What sense does it even make to build a certain branch on pushes to any other branch than itself?甚至在推送到除自身之外的任何其他分支时构建某个分支有什么意义? What I mean to say is that this should really be a very common thing...我想说的是,这真的应该是一件很普通的事情……

In the advanced section of Build Triggers, there's this section, that really looks like the thing:在构建触发器的高级部分,有这个部分,它看起来像这样:

在此处输入图片说明

However, it doesn't work for me.但是,它对我不起作用。 Like this, it does not trigger the build at all.像这样,它根本不会触发构建。 I also tried putting there just master (without the asterisk) but that doesn't help.我也试过把master (没有星号)放在那里,但这没有帮助。

If I select the first option (Allow all branches...) then it works, but obviously all the pushes to any branch triggers the build on master which makes no sense.如果我选择第一个选项(允许所有分支...),那么它可以工作,但显然所有对任何分支的推送都会触发 master 上的构建,这是没有意义的。

Any help appreciated.任何帮助表示赞赏。

Thanks!谢谢!

To integrate GitLab with Jenkins I'd suggest using Gitlab Plugin要将 GitLab 与 Jenkins 集成,我建议使用Gitlab 插件

  1. Install Gitlab plugin on Jenkins and configure Gitlab Connection (Manage Jenkins -> Configure -> Gitlab), for this you need to create new credentials of type GitLab API token .在 Jenkins 上安装 Gitlab 插件并配置 Gitlab 连接(管理 Jenkins -> 配置 -> Gitlab),为此您需要创建新的GitLab API token类型的凭据。
  2. Select trigger in Jenkins job configuration Build when a change is pushed to GitLab (when you click on advanced options there is Secret token which should be used together with webhook URL in Gitlab Webhooks). Build when a change is pushed to GitLab时,在 Jenkins 作业配置Build when a change is pushed to GitLab选择触发器(当您单击高级选项时,应与 Gitlab Webhooks 中的 Webhook URL 一起使用的Secret 令牌)。
  3. Add webhook (Push Events) in Gitlab project Settings -> Integrations , with url and token from Jenkins job and filter them by branch name .在 Gitlab project Settings -> Integrations添加 webhook (推送事件),使用来自 Jenkins 作业的 url 和令牌,并按分支名称过滤它们

Update: So my original point was to filter push events on GitLab so Jenkins doesn't need to do it but as you pointed out it should work with Jenkins filter as well.更新:所以我最初的观点是在 GitLab 上过滤推送事件,因此 Jenkins 不需要这样做,但正如您指出的那样,它也应该与 Jenkins 过滤器一起使用。

I tried filtering branch in my job and Jenkins displayed dropdown list with suggested branches after I started typing, then when I choose brach a label appeared Matching 1 branch :我尝试在我的工作中过滤分支,詹金斯在我开始输入后显示带有建议分支的下拉列表,然后当我选择Matching 1 branch出现了一个标签Matching 1 branch 过滤 Jenkins 推送触发器 On the other hand in your screenshot there is some ERROR indicator which would suggest that your GitLab connection is improperly configured.另一方面,在您的屏幕截图中,有一些ERROR指示器表明您的 GitLab 连接配置不正确。 I'd suggest to go to test your connection to GitLab and fix it.我建议去测试你与 GitLab 的连接并修复它。

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

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