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

Can't trigger builds on Accepted, Approved & Closed Merge Requests #734

Closed
isurugiu opened this issue Mar 28, 2018 · 26 comments
Closed

Can't trigger builds on Accepted, Approved & Closed Merge Requests #734

isurugiu opened this issue Mar 28, 2018 · 26 comments
Labels
bug For changelog: Minor bug. Will be listed after features

Comments

@isurugiu
Copy link

isurugiu commented Mar 28, 2018

Issue

Hi, I am finding it impossible to trigger up jobs upon Accepted, Approved & Closed MRs however the Opened MR triggers work great.

Context

  • Gitlab plugin version: 1.5.4
  • Gitlab version: 10.5.2-ee
  • Jenkins version: 2.60.3
  • Job type: Pipeline

Problem description

So I have 2 hooks configured in GitLab both configured to trigger upon MRs but different jobs:

  • some-project-BUILD listens for Opened MRs
  • some-project-TESTS listens for Accepted MRs (tried with Closed MRs & Approved MRs)

some-project-BUILD is triggered fine but some-project-TESTS is not, see the log below:

Mar 28, 2018 3:36:43 PM INFO com.dabsquared.gitlabjenkins.webhook.GitLabWebHook getDynamic
WebHook called with url: /project/framework/some-project-BUILD-TESTS
Mar 28, 2018 3:36:43 PM FINE com.dabsquared.gitlabjenkins.webhook.build.MergeRequestBuildAction
MergeRequest: {
  "object_kind" : "merge_request",
  "user" : {
    "name" : "some_user, Iulian (ELS-LON)",
    "username" : "some_userI",
    "avatar_url" : "https://gitlab.some_gitlab.com/uploads/-/system/user/avatar/1954/avatar.png"
  },
  "project" : {
    "id" : 5939,
    "name" : "some-project-BUILD",
    "description" : "",
    "web_url" : "https://gitlab.some_gitlab.com/some_group/some-project-BUILD",
    "avatar_url" : null,
    "git_ssh_url" : "git@gitlab.some_gitlab.com:some_group/some-project-BUILD.git",
    "git_http_url" : "https://gitlab.some_gitlab.com/some_group/some-project-BUILD.git",
    "namespace" : "some_group",
    "visibility_level" : 0,
    "path_with_namespace" : "some_group/some-project-BUILD",
    "default_branch" : "develop",
    "ci_config_path" : null,
    "homepage" : "https://gitlab.some_gitlab.com/some_group/some-project-BUILD",
    "url" : "git@gitlab.some_gitlab.com:some_group/some-project-BUILD.git",
    "ssh_url" : "git@gitlab.some_gitlab.com:some_group/some-project-BUILD.git",
    "http_url" : "https://gitlab.some_gitlab.com/some_group/some-project-BUILD.git"
  },
  "object_attributes" : {
    "assignee_id" : null,
    "author_id" : 1954,
    "created_at" : "2018-03-28 15:35:43 UTC",
    "description" : "This reverts merge request !163",
    "head_pipeline_id" : null,
    "id" : 28105,
    "iid" : 164,
    "last_edited_at" : null,
    "last_edited_by_id" : null,
    "merge_commit_sha" : "2b83ff8e71cfe4c393897e3cea36e41f4fac606c",
    "merge_error" : null,
    "merge_params" : {
      "force_remove_source_branch" : "0"
    },
    "merge_status" : "can_be_merged",
    "merge_user_id" : null,
    "merge_when_pipeline_succeeds" : false,
    "milestone_id" : null,
    "source_branch" : "revert-b49b9dbc",
    "source_project_id" : 5939,
    "state" : "merged",
    "target_branch" : "develop",
    "target_project_id" : 5939,
    "time_estimate" : 0,
    "title" : "Revert \"Merge branch 'revert-8ef67a2c' into 'develop'\"",
    "updated_at" : "2018-03-28 15:36:42 UTC",
    "updated_by_id" : null,
    "url" : "https://gitlab.some_gitlab.com/some_group/some-project-BUILD/merge_requests/164",
    "source" : {
      "id" : 5939,
      "name" : "some-project-BUILD",
      "description" : "",
      "web_url" : "https://gitlab.some_gitlab.com/some_group/some-project-BUILD",
      "avatar_url" : null,
      "git_ssh_url" : "git@gitlab.some_gitlab.com:some_group/some-project-BUILD.git",
      "git_http_url" : "https://gitlab.some_gitlab.com/some_group/some-project-BUILD.git",
      "namespace" : "some_group",
      "visibility_level" : 0,
      "path_with_namespace" : "some_group/some-project-BUILD",
      "default_branch" : "develop",
      "ci_config_path" : null,
      "homepage" : "https://gitlab.some_gitlab.com/some_group/some-project-BUILD",
      "url" : "git@gitlab.some_gitlab.com:some_group/some-project-BUILD.git",
      "ssh_url" : "git@gitlab.some_gitlab.com:some_group/some-project-BUILD.git",
      "http_url" : "https://gitlab.some_gitlab.com/some_group/some-project-BUILD.git"
    },
    "target" : {
      "id" : 5939,
      "name" : "some-project-BUILD",
      "description" : "",
      "web_url" : "https://gitlab.some_gitlab.com/some_group/some-project-BUILD",
      "avatar_url" : null,
      "git_ssh_url" : "git@gitlab.some_gitlab.com:some_group/some-project-BUILD.git",
      "git_http_url" : "https://gitlab.some_gitlab.com/some_group/some-project-BUILD.git",
      "namespace" : "some_group",
      "visibility_level" : 0,
      "path_with_namespace" : "some_group/some-project-BUILD",
      "default_branch" : "develop",
      "ci_config_path" : null,
      "homepage" : "https://gitlab.some_gitlab.com/some_group/some-project-BUILD",
      "url" : "git@gitlab.some_gitlab.com:some_group/some-project-BUILD.git",
      "ssh_url" : "git@gitlab.some_gitlab.com:some_group/some-project-BUILD.git",
      "http_url" : "https://gitlab.some_gitlab.com/some_group/some-project-BUILD.git"
    },
    "last_commit" : {
      "id" : "6a2bb4033e5425c7d03f9490c4de91efc08ae0a7",
      "message" : "Revert \"Merge branch 'revert-8ef67a2c' into 'develop'\"\n\nThis reverts merge request !163",
      "timestamp" : "2018-03-28T15:35:36+00:00",
      "url" : "https://gitlab.some_gitlab.com/some_group/some-project-BUILD/commit/6a2bb4033e5425c7d03f9490c4de91efc08ae0a7",
      "author" : {
        "name" : "some_user, Iulian (ELS-LON)",
        "email" : "i.some_user@some_company.com"
      }
    },
    "work_in_progress" : false,
    "total_time_spent" : 0,
    "human_total_time_spent" : null,
    "human_time_estimate" : null,
    "action" : "merge"
  },
  "labels" : [ ],
  "changes" : {
    "state" : {
      "previous" : "locked",
      "current" : "merged"
    },
    "updated_at" : {
      "previous" : "2018-03-28 15:36:42 UTC",
      "current" : "2018-03-28 15:36:42 UTC"
    },
    "total_time_spent" : {
      "previous" : null,
      "current" : 0
    }
  },
  "repository" : {
    "name" : "some-project-BUILD",
    "url" : "git@gitlab.some_gitlab.com:some_group/some-project-BUILD.git",
    "description" : "",
    "homepage" : "https://gitlab.some_gitlab.com/some_group/some-project-BUILD"
  }
}

So I did a little experiment and used Postman to trigger the TESTS job with having the OMR json as the model which is actually POSTed via the hook targeting the BUILD job upon an OMR. So if I change the "state" from below from "opened" to "merged" and target the TESTS job it works:

{
  "object_kind" : "merge_request",
  "user" : {
    "name" : "some_user, Iulian (ELS-LON)",
    "username" : "some_userI",
    "avatar_url" : "https://gitlab.some_gitlab.com/uploads/-/system/user/avatar/1954/avatar.png"
  },
  "project" : {
    "id" : 5939,
    "name" : "some-project",
    "description" : "",
    "web_url" : "https://gitlab.some_gitlab.com/some_group/some-project",
    "avatar_url" : null,
    "git_ssh_url" : "git@gitlab.some_gitlab.com:some_group/some-project.git",
    "git_http_url" : "https://gitlab.some_gitlab.com/some_group/some-project.git",
    "namespace" : "some_group",
    "visibility_level" : 0,
    "path_with_namespace" : "some_group/some-project",
    "default_branch" : "develop",
    "ci_config_path" : null,
    "homepage" : "https://gitlab.some_gitlab.com/some_group/some-project",
    "url" : "git@gitlab.some_gitlab.com:some_group/some-project.git",
    "ssh_url" : "git@gitlab.some_gitlab.com:some_group/some-project.git",
    "http_url" : "https://gitlab.some_gitlab.com/some_group/some-project.git"
  },
  "object_attributes" : {
    "assignee_id" : null,
    "author_id" : 1954,
    "created_at" : "2018-03-28 16:12:00 UTC",
    "description" : "This reverts merge request !164",
    "head_pipeline_id" : null,
    "id" : 28109,
    "iid" : 165,
    "last_edited_at" : null,
    "last_edited_by_id" : null,
    "merge_commit_sha" : null,
    "merge_error" : null,
    "merge_params" : {
      "force_remove_source_branch" : "1"
    },
    "merge_status" : "unchecked",
    "merge_user_id" : null,
    "merge_when_pipeline_succeeds" : false,
    "milestone_id" : null,
    "source_branch" : "revert-2b83ff8e",
    "source_project_id" : 5939,
    "state" : "opened",
    "target_branch" : "develop",
    "target_project_id" : 5939,
    "time_estimate" : 0,
    "title" : "Revert \"Merge branch 'revert-b49b9dbc' into 'develop'\"",
    "updated_at" : "2018-03-28 16:12:00 UTC",
    "updated_by_id" : null,
    "url" : "https://gitlab.some_gitlab.com/some_group/some-project/merge_requests/165",
    "source" : {
      "id" : 5939,
      "name" : "some-project",
      "description" : "",
      "web_url" : "https://gitlab.some_gitlab.com/some_group/some-project",
      "avatar_url" : null,
      "git_ssh_url" : "git@gitlab.some_gitlab.com:some_group/some-project.git",
      "git_http_url" : "https://gitlab.some_gitlab.com/some_group/some-project.git",
      "namespace" : "some_group",
      "visibility_level" : 0,
      "path_with_namespace" : "some_group/some-project",
      "default_branch" : "develop",
      "ci_config_path" : null,
      "homepage" : "https://gitlab.some_gitlab.com/some_group/some-project",
      "url" : "git@gitlab.some_gitlab.com:some_group/some-project.git",
      "ssh_url" : "git@gitlab.some_gitlab.com:some_group/some-project.git",
      "http_url" : "https://gitlab.some_gitlab.com/some_group/some-project.git"
    },
    "target" : {
      "id" : 5939,
      "name" : "some-project",
      "description" : "",
      "web_url" : "https://gitlab.some_gitlab.com/some_group/some-project",
      "avatar_url" : null,
      "git_ssh_url" : "git@gitlab.some_gitlab.com:some_group/some-project.git",
      "git_http_url" : "https://gitlab.some_gitlab.com/some_group/some-project.git",
      "namespace" : "some_group",
      "visibility_level" : 0,
      "path_with_namespace" : "some_group/some-project",
      "default_branch" : "develop",
      "ci_config_path" : null,
      "homepage" : "https://gitlab.some_gitlab.com/some_group/some-project",
      "url" : "git@gitlab.some_gitlab.com:some_group/some-project.git",
      "ssh_url" : "git@gitlab.some_gitlab.com:some_group/some-project.git",
      "http_url" : "https://gitlab.some_gitlab.com/some_group/some-project.git"
    },
    "last_commit" : {
      "id" : "87d1b5bb6d8f09cf316cab342120d0bbced80bcd",
      "message" : "Revert \"Merge branch 'revert-b49b9dbc' into 'develop'\"\n\nThis reverts merge request !164",
      "timestamp" : "2018-03-28T16:11:54+00:00",
      "url" : "https://gitlab.some_gitlab.com/some_group/some-project/commit/87d1b5bb6d8f09cf316cab342120d0bbced80bcd",
      "author" : {
        "name" : "some_user, Iulian (ELS-LON)",
        "email" : "i.some_user@some_company.com"
      }
    },
    "work_in_progress" : false,
    "total_time_spent" : 0,
    "human_total_time_spent" : null,
    "human_time_estimate" : null,
    "action" : "open"
  },
  "labels" : [ ],
  "changes" : {
    "total_time_spent" : {
      "previous" : null,
      "current" : 0
    }
  },
  "repository" : {
    "name" : "some-project",
    "url" : "git@gitlab.some_gitlab.com:some_group/some-project.git",
    "description" : "",
    "homepage" : "https://gitlab.some_gitlab.com/some_group/some-project"
  }
}
@mice33
Copy link

mice33 commented Mar 29, 2018

the same problem

@mojocorp
Copy link

mojocorp commented Apr 3, 2018

same problem.

@rtrys
Copy link

rtrys commented Apr 3, 2018

I have the same problem

@davidh87
Copy link

davidh87 commented Apr 4, 2018

Same problem. My possibly-completely wrong 2 cents:

I believe it's related to the changes brought in on 554bb61 - that seems to change how the logic around Action is handled, but the Action enum is incomplete and is missing (at least) a "merge" option

@omehegan
Copy link
Member

omehegan commented Apr 5, 2018

If @davidh87 is right (thanks for digging into it!), plugin version 1.5.3 might work. You can download that from the archive at https://updates.jenkins.io/download/plugins/gitlab-plugin/ and install it manually using the Advanced tab of the Jenkins plugin manager. Can some of you test that and see if it fixes the issue? #726 introduced this change, if anyone wants to look at the discussion.

@pdudits can you comment on this?

@mtmargala
Copy link

mtmargala commented Apr 5, 2018 via email

@omehegan
Copy link
Member

omehegan commented Apr 5, 2018

@mtmargala thanks for testing. @pdudits it sounds like your PR may have introduced a bug. Can you investigate?

@omehegan omehegan added bug For changelog: Minor bug. Will be listed after features and removed awaiting feedback labels Apr 5, 2018
@pdudits
Copy link
Contributor

pdudits commented Apr 5, 2018

I would rather say, that it disclosed different issue -- namely, that there's no reference specification of Webhook payloads :)

@davidh87 is completely right about missing Action value. It should be possible to make a test case from the provided hook payloads, and see if adding the new value fixes that.

Generally, Gitlab API documentation doesn't enumerate all possible actions, so using the enum is not entirely ok and may bring more surprises in the future.

@mojocorp
Copy link

mojocorp commented Apr 5, 2018

1.5.3 worked for me but stopped after a couple of hours. Back to the original problem, none of the 'close' requests trigger the job. The jenkins log shows that gitlab sent the right infos to jenkins.

@pdudits
Copy link
Contributor

pdudits commented Apr 5, 2018

@mojocorp would you share the hook payload? Or at least action and State attributes of it?

@mojocorp
Copy link

mojocorp commented Apr 5, 2018

While looking more carefully at the log, it always ends with: Last commit in Merge Request has already been built in build #31

So, as soon as the pipeline succeed, it does not trigger the job anymore.
Is it an expected behaviour ?

@pdudits
Copy link
Contributor

pdudits commented Apr 5, 2018

The check for last commit is done after checking for status and action, so it's not caused by changes in 1.5.4

@omehegan
Copy link
Member

omehegan commented Apr 6, 2018

@mojocorp not rebuilding commits that were already built is expected. This is a "feature." Changing it has been discussed at #636.

@mojocorp
Copy link

mojocorp commented Apr 6, 2018

@omehega This would explain why nothing happen on re-'open' state but this feature prevent 'close' to trigger the job since it's already built, and I guess 'merge' too.
Is there a way to make it less smart and just trigger open/merge/close whatever the plugin think is 'built' ?

@omehegan
Copy link
Member

omehegan commented Apr 9, 2018

@mojocorp my idea was to create a config option to disable that "skipped because already built" feature if people want to do that. I just have not gotten to it yet. PRs welcome :) Follow #636 for updates on that.

@joesus
Copy link

joesus commented Apr 17, 2018

Other than polling are there any workarounds people are using? Also, thanks for taking the time to sort this out. 🥇

@ayashjorden
Copy link

Same issue as reported in #770

@ilanni2460
Copy link

ilanni2460 commented May 30, 2018

I have the same problem,but gitlab plugin 1.5.3 does work, I confirmed reverting to that works today.
gitlab version 10.8.1
jenkins version 2.125

@philmosquera
Copy link

Can confirm that on version 1.5.6 merge request webhooks are not working for me. Reverting back to 1.5.3 seems to do the trick.
Gitlab version: 10.7.1
jenkins: 2.89.2

@omehegan
Copy link
Member

The issue with Accepted merge requests should be fixed by #762 which was just released in version 1.5.7. It's not clear to me if that is also going to fix triggering on Approved and Closed states. @keijohyttinen can you explain about this?

@keijohyttinen
Copy link
Contributor

@omehegan I tested only accepted state but based on root cause it prevented also closed state to be triggered.

Actually also took a look into tests and verified also closed state is working fine.
In fact, it seems unit tests need to be modified so that they match with actual implementation of MergeRequestHookTriggerHandlerFactory and verify correctly combinations of allowed states and actions, i.e. same problem does not occur in the future.
Created PR #790

@omehegan
Copy link
Member

omehegan commented Jul 1, 2018

@keijohyttinen thanks very much for clarifying, and for fixing the unit tests! Unfortunately version 1.5.7 of the plugin is broken for Pipeline jobs, hopefully that will get fixed soon or I will have to revert the PR that broke it and deploy again.

@omehegan
Copy link
Member

omehegan commented Jul 9, 2018

@chinhodado reports this is still broken in 1.5.8, maybe he can explain what he is seeing.

Disregard, I misunderstood the issue that was being reported.

@chinhodado
Copy link
Contributor

If this issue was fixed recently it may be responsible for #796

@jenkinsci jenkinsci deleted a comment from nemui Aug 3, 2018
@omehegan
Copy link
Member

This was released today in 1.5.10.

@TonyNoble
Copy link

Slight thread resurrection here - but there still seems to be the issue that the trigger will not allow the same commit to be built twice by the same job. ie. If the job builds an opened merge request and then the merge request is approved, the job will not trigger again. Similarly, it is not possible to get gitlab to resend a hook to re-trigger a build. There should, at the very least, be an option to disable this behaviour, even if it is enabled by default.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug For changelog: Minor bug. Will be listed after features
Projects
None yet
Development

No branches or pull requests