gitlab-plugin icon indicating copy to clipboard operation
gitlab-plugin copied to clipboard

Closed Merge Request Events does not trigger job

Open dsiragusa opened this issue 4 years ago • 8 comments

Issue

Context

  • Gitlab plugin version: 1.5.12
  • Gitlab version: 11.11.2-ce
  • Jenkins version: 2.181
  • Job type: Freestyle

Logs & Traces

Jul 16, 2019 2:13:55 PM INFO com.dabsquared.gitlabjenkins.webhook.GitLabWebHook getDynamic
WebHook called with url: /project/MY_PROJECT
Jul 16, 2019 2:13:55 PM FINE com.dabsquared.gitlabjenkins.webhook.build.MergeRequestBuildAction
MergeRequest: {
  "object_kind" : "merge_request",
  "event_type" : "merge_request",
  "user" : {
    "name" : "Daniele Siragusa",
    "username" : "dsiragusa",
    "avatar_url" : "URL"
  },
  "project" : {
    "id" : 4777,
    "name" : "NAME",
    "description" : "DESC",
    "web_url" : "WEB_URL",
    "avatar_url" : "AVATAR_URL",
    "git_ssh_url" : "GIT_SSH_URL",
    "git_http_url" : "GIT_HTTP_URL",
    "namespace" : "NAMESPACE",
    "visibility_level" : 0,
    "path_with_namespace" : "ORG/PROJECT",
    "default_branch" : "develop",
    "ci_config_path" : "",
    "homepage" : "HOMEPAGE",
    "url" : "URL",
    "ssh_url" : "SSH_URL",
    "http_url" : "URL"
  },
  "object_attributes" : {
    "assignee_id" : null,
    "author_id" : 119,
    "created_at" : "2019-07-16 07:14:18 UTC",
    "description" : "",
    "head_pipeline_id" : 40341,
    "id" : 31292,
    "iid" : 650,
    "last_edited_at" : null,
    "last_edited_by_id" : null,
    "merge_commit_sha" : null,
    "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" : "SRC_BRANCH",
    "source_project_id" : 4777,
    "state" : "closed",
    "target_branch" : "develop",
    "target_project_id" : 4777,
    "time_estimate" : 0,
    "title" : "TITLE",
    "updated_at" : "2019-07-16 12:13:55 UTC",
    "updated_by_id" : null,
    "url" : "MR_URL",
    "source" : {
      "id" : 4777,
      "name" : "NAME",
      "description" : "DESC",
      "web_url" : "WEB_URL",
      "avatar_url" : "AVATAR_URL",
      "git_ssh_url" : "GIT_SSH_URL",
      "git_http_url" : "GIT_HTTP_URL",
      "namespace" : "NAMESPACE",
      "visibility_level" : 0,
      "path_with_namespace" : "ORG/PROJECT",
      "default_branch" : "develop",
      "ci_config_path" : "",
      "homepage" : "HOMEPAGE",
      "url" : "URL",
      "ssh_url" : "SSH_URL",
      "http_url" : "HTTP_URL"
    },
    "target" : {
      "id" : 4777,
      "name" : "NAME",
      "description" : "DESC",
      "web_url" : "WEB_URL",
      "avatar_url" : "AVATAR_URL",
      "git_ssh_url" : "GIT_SSH_URL",
      "git_http_url" : "GIT_HTTP_URL",
      "namespace" : "NAMESPACE",
      "visibility_level" : 0,
      "path_with_namespace" : "ORG/PROJECT",
      "default_branch" : "develop",
      "ci_config_path" : "",
      "homepage" : "HOMEPAGE",
      "url" : "URL",
      "ssh_url" : "SSH_URL",
      "http_url" : "HTTP_URL"
    },
    "last_commit" : {
      "id" : "COMMIT_ID",
      "message" : "MESSAGE",
      "timestamp" : "2019-07-16T07:13:59Z",
      "url" : "URL",
      "author" : {
        "name" : "Daniele Siragusa",
        "email" : "EMAIL"
      }
    },
    "work_in_progress" : false,
    "total_time_spent" : 0,
    "human_total_time_spent" : null,
    "human_time_estimate" : null,
    "assignee_ids" : [ ],
    "action" : "close"
  },
  "labels" : [ ],
  "changes" : {
    "state" : {
      "previous" : "opened",
      "current" : "closed"
    },
    "updated_at" : {
      "previous" : "2019-07-16 12:12:38 UTC",
      "current" : "2019-07-16 12:13:55 UTC"
    },
    "total_time_spent" : {
      "previous" : null,
      "current" : 0
    }
  },
  "repository" : {
    "name" : "NAME",
    "url" : "URL",
    "description" : "DESC",
    "homepage" : "HOMEPAGE"
  }
}

Problem description

Hello, I'd like to trigger a job on Accepted Merge Request Events and Closed Merge Request Events. Accepted Merge Request Events correctly trigger the job but that's not the case for Closed Merge Request Events: the webhook is correctly sent by Gitlab, Jenkins answers with a 200 status code but does nothing.

dsiragusa avatar Jul 16 '19 12:07 dsiragusa

Have you checked the Jenkins log for the Gitlab plugin, in Jenkins > System Log > Gitlab plugin?

jdillard avatar May 28 '20 23:05 jdillard

Experiencing the same issue here, and the log in Jenkins is the same as @dsiragusa provided, i.e. no further log after MergeRequestBuildAction. This feels like the logic did not go beyond the isAllowedByConfig check in isExecutable function of MergeRequestHookTriggerHandlerImpl, and looking at the object_attributes in webhook payload, the action is close, so would the issue be related to that the Action model defines closed instead of close?

scramboy avatar Oct 14 '20 11:10 scramboy

In addition to the above observation, should the close action be part of the skipBuiltYetCheckActions list? My personal guess is that users triggering job execution on close action would very likely have done a 'prebuild merge' in the merge action already. This would cause job execution of close action to be skipped.

scramboy avatar Oct 14 '20 13:10 scramboy

Still an issue 2 years later. Are there no plans for this to be fixed?

VengefulAncient avatar May 21 '21 12:05 VengefulAncient

I am having the same issue.

shurkanTwo avatar Oct 12 '21 13:10 shurkanTwo

Same issue here..

teodor20 avatar Jan 05 '22 13:01 teodor20

I've tried to enable this setting, and it worked

Approved Merge Requests (EE-only)

image

leandrofrs avatar Apr 22 '22 16:04 leandrofrs

Can confirm that Approved Merge Requests (EE-only) works to allow closed events to trigger (unintuitively).

Unfortunately, this also makes "Approve" events trigger the job (but not revoking Approval for some reason), and this is undesirable.

And while the plugin does know the state change because GitLab sends it in the webhook, the plugin does not expose it to the pipeline in any variable.

Thus, a job triggered by an Approval looks identical to a job triggered by the MR being (re)opened, or a new commit being pushed, etc. Would prefer a way to trigger the job on closed/merged events without also triggering on Approval, but even if we wanted to check this in the job itself, there's no way to determine that the job was triggered by an approval vs. another event.

Additionally, the triggerOnlyIfNewCommitsPushed: true does affect close/(re)open events, and they won't trigger if this is set, however, it does not affect the Approved event at all. This is frustratingly inconsistent, and if anything it's the opposite effect of what I actually want.

briantist avatar Jan 18 '23 16:01 briantist