Gitlab-plugin: Can't trigger builds on Accepted, Approved & Closed Merge Requests

Created on 28 Mar 2018  Â·  26Comments  Â·  Source: jenkinsci/gitlab-plugin

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" : "[email protected]_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" : "[email protected]_gitlab.com:some_group/some-project-BUILD.git",
    "ssh_url" : "[email protected]_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" : "[email protected]_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" : "[email protected]_gitlab.com:some_group/some-project-BUILD.git",
      "ssh_url" : "[email protected]_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" : "[email protected]_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" : "[email protected]_gitlab.com:some_group/some-project-BUILD.git",
      "ssh_url" : "[email protected]_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" : "[email protected]_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" : "[email protected]_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" : "[email protected]_gitlab.com:some_group/some-project.git",
    "ssh_url" : "[email protected]_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" : "[email protected]_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" : "[email protected]_gitlab.com:some_group/some-project.git",
      "ssh_url" : "[email protected]_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" : "[email protected]_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" : "[email protected]_gitlab.com:some_group/some-project.git",
      "ssh_url" : "[email protected]_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" : "[email protected]_gitlab.com:some_group/some-project.git",
    "description" : "",
    "homepage" : "https://gitlab.some_gitlab.com/some_group/some-project"
  }
}
bug

Most helpful comment

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.

All 26 comments

the same problem

same problem.

I have the same problem

Same problem. My possibly-completely wrong 2 cents:

I believe it's related to the changes brought in on https://github.com/jenkinsci/gitlab-plugin/commit/554bb618a554850c73a2e636928bbb7df15cdb5f - 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

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?

1.5.3 does work, I confirmed reverting to that works today.
On Thu, Apr 5, 2018 at 12:17 AM Owen Mehegan notifications@github.com
wrote:

If @davidh87 https://github.com/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
https://github.com/jenkinsci/gitlab-plugin/pull/726 introduced this
change, if anyone wants to look at the discussion.

@pdudits https://github.com/pdudits can you comment on this?

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/jenkinsci/gitlab-plugin/issues/734#issuecomment-378815853,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ACLU5zve0GkjxUVHRQVtnoZ2Nh_r1_QYks5tlZrtgaJpZM4S-9Rt
.

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

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.

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.

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

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 ?

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

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

@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' ?

@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.

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

Same issue as reported in #770

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

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

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?

@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 https://github.com/jenkinsci/gitlab-plugin/pull/790

@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.

@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.

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

This was released today in 1.5.10.

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

asagi687 picture asagi687  Â·  4Comments

dblessing picture dblessing  Â·  3Comments

pablobirukov picture pablobirukov  Â·  5Comments

dcuenot picture dcuenot  Â·  5Comments

ffrddrll picture ffrddrll  Â·  6Comments