Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitLab: Editing the merge request description triggers a merge request hook being sent

For my repository on GitLab I have a Merge Request Hook configured which triggers a build on a Jenkins CI machine. The hooks works as expected when a merge request is opened.

The webhook is configured with the following triggers:

  • URL: https://example.com/project/ExampleApp_merge_requests
  • Push events: Enabled
  • Merge request events: Enabled
  • Enable SSL verification: Off

Lately, when I edit the description of the merge requests then the hook also notifies the CI machine.
Here is an example POST request:

Request headers:

Content-Type: application/json
X-Gitlab-Event: Merge Request Hook

Request body:

{
  "object_kind": "merge_request",
  "event_type": "merge_request",
  "user": {
    "name": "User Name",
    "username": "username",
    "avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/145/avatar.png"
  },
  "project": {
    "id": 39,
    "name": "app",
    "description": "Lorem ipsum.",
    "web_url": "https://gitlab.example.com/projects/app",
    "avatar_url": "https://gitlab.example.com/uploads/-/system/project/avatar/39/app.png",
    "git_ssh_url": "[email protected]:projects/app.git",
    "git_http_url": "https://gitlab.example.com/projects/app.git",
    "namespace": "projects",
    "visibility_level": 0,
    "path_with_namespace": "projects/app",
    "default_branch": "develop",
    "ci_config_path": null,
    "homepage": "https://gitlab.example.com/projects/app",
    "url": "[email protected]:projects/app.git",
    "ssh_url": "[email protected]:projects/app.git",
    "http_url": "https://gitlab.example.com/projects/app.git"
  },
  "object_attributes": {
    "assignee_id": null,
    "author_id": 5,
    "created_at": "2019-03-19 16:42:28 UTC",
    "description": "- s. https://fabric.io/development/projects/apps/com.example.app/issues/5974e5ffbe077a4dcc044254?time=last-thirty-days\r\n- Lorem ipsum.",
    "head_pipeline_id": 7473,
    "id": 9258,
    "iid": 844,
    "last_edited_at": "2019-03-20 09:00:21 UTC",
    "last_edited_by_id": 145,
    "merge_commit_sha": null,
    "merge_error": null,
    "merge_params": {
      "force_remove_source_branch": "1"
    },
    "merge_status": "can_be_merged",
    "merge_user_id": null,
    "merge_when_pipeline_succeeds": false,
    "milestone_id": null,
    "source_branch": "fix/random",
    "source_project_id": 39,
    "state": "opened",
    "target_branch": "develop",
    "target_project_id": 39,
    "time_estimate": 0,
    "title": "Fix random",
    "updated_at": "2019-03-20 09:00:21 UTC",
    "updated_by_id": 145,
    "url": "https://gitlab.example.com/projects/app/merge_requests/844",
    "source": {
      "id": 39,
      "name": "app",
      "description": "Lorem ipsum.",
      "web_url": "https://gitlab.example.com/projects/app",
      "avatar_url": "https://gitlab.example.com/uploads/-/system/project/avatar/39/app.png",
      "git_ssh_url": "[email protected]:projects/app.git",
      "git_http_url": "https://gitlab.example.com/projects/app.git",
      "namespace": "projects",
      "visibility_level": 0,
      "path_with_namespace": "projects/app",
      "default_branch": "develop",
      "ci_config_path": null,
      "homepage": "https://gitlab.example.com/projects/app",
      "url": "[email protected]:projects/app.git",
      "ssh_url": "[email protected]:projects/app.git",
      "http_url": "https://gitlab.example.com/projects/app.git"
    },
    "target": {
      "id": 39,
      "name": "app",
      "description": "Lorem ipsum.",
      "web_url": "https://gitlab.example.com/projects/app",
      "avatar_url": "https://gitlab.example.com/uploads/-/system/project/avatar/39/app.png",
      "git_ssh_url": "[email protected]:projects/app.git",
      "git_http_url": "https://gitlab.example.com/projects/app.git",
      "namespace": "projects",
      "visibility_level": 0,
      "path_with_namespace": "projects/app",
      "default_branch": "develop",
      "ci_config_path": null,
      "homepage": "https://gitlab.example.com/projects/app",
      "url": "[email protected]:projects/app.git",
      "ssh_url": "[email protected]:projects/app.git",
      "http_url": "https://gitlab.example.com/projects/app.git"
    },
    "last_commit": {
      "id": "cdda6f7d200468955ecbd224f0437932db607087",
      "message": "Fix random\n\n",
      "timestamp": "2019-03-20T08:45:40Z",
      "url": "https://gitlab.example.com/projects/app/commit/cdda6f7d200468955ecbd224f0437932db607087",
      "author": {
        "name": "User Name",
        "email": "username"
      }
    },
    "work_in_progress": false,
    "total_time_spent": 0,
    "human_total_time_spent": null,
    "human_time_estimate": null,
    "action": "update"
  },
  "labels": [
    {
      "id": 22,
      "title": "Bug fix",
      "color": "#FF0000",
      "project_id": null,
      "created_at": "2018-10-19 09:55:26 UTC",
      "updated_at": "2018-11-05 15:17:08 UTC",
      "template": false,
      "description": "",
      "type": "GroupLabel",
      "group_id": 15
    }
  ],
  "changes": {
    "description": {
      "previous": "s. https://fabric.io/development/projects/apps/com.example.app/issues/5974e5ffbe077a4dcc044254?time=last-thirty-days\r\nLorem ipsum.",
      "current": "- s. https://fabric.io/development/projects/apps/com.example.app/issues/5974e5ffbe077a4dcc044254?time=last-thirty-days\r\n- Lorem ipsum."
    },
    "last_edited_at": {
      "previous": "2019-03-19 16:42:50 UTC",
      "current": "2019-03-20 09:00:21 UTC"
    },
    "last_edited_by_id": {
      "previous": 5,
      "current": 145
    },
    "updated_at": {
      "previous": "2019-03-20 08:52:38 UTC",
      "current": "2019-03-20 09:00:21 UTC"
    },
    "updated_by_id": {
      "previous": 5,
      "current": 145
    }
  },
  "repository": {
    "name": "app",
    "url": "[email protected]:projects/app.git",
    "description": "Lorem ipsum.",
    "homepage": "https://gitlab.example.com/projects/app"
  }
}

Response headers:

Server: nginx/1.10.3 (Ubuntu)
Date: Wed, 20 Mar 2019 09:00:21 GMT
Transfer-Encoding: chunked
Connection: close
X-Content-Type-Options: nosniff

The Jenkins plugin looks like this:

Jenkins GitLab plugin

On the Jenkins machine the following GitLab plugins are installed:

Installed Jenkins GitLab plugins

  • Jenkins GitLab OAuth Plugin
  • Jenkins GitLab Hook Plugin
  • Jenkins GitLab Logo Plugin
  • GitLab Merge Request Builder Plugin
  • GitLab Plugin

How can I configure that a POST request is only sent to the CI machine when I create or update the branch of the pull request?

like image 826
JJD Avatar asked Mar 21 '19 16:03

JJD


People also ask

How do you trigger a pipeline on a merge request?

Create a new merge request from a source branch with one or more commits. Push a new commit to the source branch for a merge request. Select Run pipeline from the Pipelines tab in a merge request.

How do I update a merge request?

Revise a merge request If you need to update a merge request (for example in response to a request from the review shifter), simply push to the same branch again after editing (and testing) the files.


2 Answers

The issue was suddenly resolved by doing nothing. At the current software stack I do no longer experience the problem.

Here is the software versions:

  • Jenkins 2.204
    • GitLab Plugin 1.5.13
  • GitLab Enterprise 12.4.2-ee

I hope this is helpful for others.

like image 117
JJD Avatar answered Oct 20 '22 19:10

JJD


Under triggers (Settings -> integrations) perform the below:

  1. Enable push events (optional branch name - Branch is created via push events even before MR is possible)
  2. Enable MR event triggers in your project repo

This URL will be triggered when a merge request is created/updated/merged

enter image description here

In Jenkins Plugin configuration -

  1. Check "Push Events" (Any commits by way of direct Push or Creation)
  2. Un-check "Opened Merge Request Events"
  3. Check "Accepted Merge Request Events" (Any commits by way of Merge Request)
like image 45
takrishna Avatar answered Oct 20 '22 21:10

takrishna