Webhook to run Jenkins CI when target branch changes

I’m trying to set up Webhooks from GitLab to Jenkins to run jobs when merge requests are created/updated.

Everything runs fine, except that (as the documentation says) it is triggered (amongst other reasons) when “A commit is added in the source branch.”

However, we also want to trigger one when a commit is added in the target branch. After all, there’s no point having green unit tests when actually it’s all going to go red when you merge, because a change has happened to the target branch.

The Jenkins Gitlab plugin has a setting “Rebuild open Merge Requests” which has a setting “On push to source or target branches” - but even with that set, it only seems to run on pushes to source branches.

On the GitLab side I can see Webhooks being fired for “Push hook” and Merge Request hook" when I push to the source, and only a “Push hook” when I push to the target.

On the jenkins side I’m building on Opened Merge Request Events, Comments, and “On push to source or target branches”.

Any idea why it’s not rebuilding when there’s a push to the target branch?

This is on a local instance of GitLab 14.6.1 and Jenkins 2.319.1 and GitLab Plugin for Jenkins 1.5.28

Thank you for any help you can give.

1 Like