GitLab trigger will not allow the same commit to be built twice.
Issue
Context
- Gitlab plugin version: 1.5.12
- Gitlab version: 11.10.4
- Jenkins version: 2.176.1
- Job type: Pipeline
Logs & Traces
None available (job does not trigger)
Problem description
I have a job set up to build merge requests. It should build under the following circumstances:
- When a merge request is opened
- When either the source or target branch of a merge request changes
- When a merge request is merged
The primary issue is that merged MRs are not causing a build to trigger, unless a secondary job is created purely for that purpose. The GitLab hook is fired and Jenkins responds with a 200 response, but no build occurs.
Further digging and googling suggests that this is due to the GitLab trigger not allowing a job to be triggered twice for the same commit (which is effectively the case when an opened MR is built and then the MR is merged). This is supported by the fact that re-sending the webhook for either the opening of the merge request or the merging of it gives similar results - a 200 response from Jenkins, but no job triggered.
Hello did you try Jenkins please try a rebuild as comment in Open Merge Requests
No. However, this would be of no use to me. I need a build to be triggered when a merge request is opened and also when it is merged - at the moment, this does not happen if both situations are handled by one Jenkins job.
Hi. I see similar behavior (Jenkins 2.186, Gitlab Plugin 1.5.13, GitLab CE 12.2.5, Groovy-pipeline, Merge method: Merge commit):
$class: 'GitLabPushTrigger',
branchFilterType: 'All',
triggerOnPush: false,
triggerOnMergeRequest: true,
triggerOnAcceptedMergeRequest: true,
triggerOpenMergeRequestOnPush: "both",
triggerOnNoteRequest: true,
noteRegex: "Jenkins please retry a build"
in the jenkins log when I've merged (i.e. accepted) Merge Request:
FINE com.dabsquared.gitlabjenkins.webhook.build.PushBuildAction
FINE com.dabsquared.gitlabjenkins.webhook.build.MergeRequestBuildAction
// "action" : "merge"
INFO com.dabsquared.gitlabjenkins.trigger.handler.merge.MergeRequestHookTriggerHandlerImpl isLastCommitNotYetBuild
// Last commit in Merge Request has already been built in build #320
IMHO, the problem may be in isLastCommitNotYetBuild, how to disable it? Perhaps the similar issues: https://github.com/jenkinsci/gitlab-plugin/issues/891 https://github.com/jenkinsci/gitlab-plugin/issues/636 Possible nasty-workaround: to trigger in every push (to master in my case) and in the Jenkins Job check if it's a merge commit and implement the logic needed:
if(env?.gitlabActionType == "PUSH" && env.gitlabBranch != "master") {
currentBuild.result = 'NOT_BUILT'
return
}
or you can filter all source branches and keep only master (protected) by means of triggerOnPush and triggerOnMergeRequest:
$class: 'GitLabPushTrigger',
branchFilterType: 'NameBasedFilter', // NameBasedFilter, All or RegexBasedFilter
includeBranchesSpec: "master",
excludeBranchesSpec: "",
triggerOnPush: true,
triggerOnMergeRequest: true,
Hi team, is the Merge Request https://github.com/jenkinsci/gitlab-plugin/pull/951 fix the issue and we can close this now?