简体   繁体   中英

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

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.

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.

Any help appreciated.

Thanks!

To integrate GitLab with Jenkins I'd suggest using Gitlab Plugin

  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 .
  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).
  3. Add webhook (Push Events) in Gitlab project Settings -> Integrations , with url and token from Jenkins job and filter them by branch name .

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.

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 : 过滤 Jenkins 推送触发器 On the other hand in your screenshot there is some ERROR indicator which would suggest that your GitLab connection is improperly configured. I'd suggest to go to test your connection to GitLab and fix it.

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