Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitLab trigger will not allow the same commit to be built twice. #958

Open
TonyNoble opened this issue Aug 2, 2019 · 4 comments
Open

GitLab trigger will not allow the same commit to be built twice. #958

TonyNoble opened this issue Aug 2, 2019 · 4 comments

Comments

@TonyNoble
Copy link

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.

@jensamberg
Copy link

jensamberg commented Sep 3, 2019

Hello did you try Jenkins please try a rebuild as comment in Open Merge Requests

@TonyNoble
Copy link
Author

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.

@amdokamal
Copy link

amdokamal commented Oct 10, 2019

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:
#891
#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,

interone-ms added a commit to interone-ms/gitlab-plugin that referenced this issue Oct 30, 2019
This parameter allows overriding the check isLastCommitNotYetBuild in MergeRequestHookTriggerHandlerImpl.

This commit fixes issue jenkinsci#636 and jenkinsci#734, probably also jenkinsci#958.
@dinhanhhuy
Copy link

Hi team, is the Merge Request #951 fix the issue and we can close this now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants