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

Configuring triggerOnAcceptedMergeRequest webhook only doesn't work #770

Closed
ayashjorden opened this issue May 28, 2018 · 4 comments
Closed

Comments

@ayashjorden
Copy link

ayashjorden commented May 28, 2018

Issue

Context

  • Gitlab plugin version: 1.5.6
  • Gitlab version: GitLab Enterprise Edition 10.5.6-ee 9a19fbe
  • Jenkins version: 2.73.3
  • Job type: Pipeline

Logs & Traces

Jenkins Gitlab webhook log (level=all)

May 28, 2018 6:21:38 AM INFO com.dabsquared.gitlabjenkins.webhook.GitLabWebHook getDynamic
WebHook called with url: /project/common/tag_on_merge

May 28, 2018 6:21:38 AM FINE com.dabsquared.gitlabjenkins.webhook.build.MergeRequestBuildAction 

MergeRequest: {
  "object_kind" : "merge_request",
  "user" : {
    "name" : "FULL_NAME",
    "username" : "USERNAME",
    "avatar_url" : "AVATAR_URL"
  },
  "project" : {
    "id" : 12717,
    "name" : "tag_on_merge",
    "description" : "",
    "web_url" : "https://gitlab.CORP_HOSTNAME/MY_GROUP_NAME/tag_on_merge",
    "avatar_url" : null,
    "git_ssh_url" : "git@gitlab.CORP_HOSTNAME:MY_GROUP_NAME/tag_on_merge.git",
    "git_http_url" : "https://gitlab.CORP_HOSTNAME/MY_GROUP_NAME/tag_on_merge.git",
    "namespace" : "MY_GROUP_NAME",
    "visibility_level" : 10,
    "path_with_namespace" : "MY_GROUP_NAME/tag_on_merge",
    "default_branch" : "master",
    "ci_config_path" : null,
    "homepage" : "https://gitlab.CORP_HOSTNAME/MY_GROUP_NAME/tag_on_merge",
    "url" : "git@gitlab.CORP_HOSTNAME:MY_GROUP_NAME/tag_on_merge.git",
    "ssh_url" : "git@gitlab.CORP_HOSTNAME:MY_GROUP_NAME/tag_on_merge.git",
    "http_url" : "https://gitlab.CORP_HOSTNAME/MY_GROUP_NAME/tag_on_merge.git"
  },
  "object_attributes" : {
    "assignee_id" : null,
    "author_id" : 181,
    "created_at" : "2018-05-28 05:31:57 UTC",
    "description" : "",
    "head_pipeline_id" : null,
    "id" : 14964,
    "iid" : 8,
    "last_edited_at" : null,
    "last_edited_by_id" : null,
    "merge_commit_sha" : "c4d3d98ac7208a476f1b9abad28db2730cd2068b",
    "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" : "marge8",
    "source_project_id" : 12717,
    "state" : "merged",
    "target_branch" : "master",
    "target_project_id" : 12717,
    "time_estimate" : 0,
    "title" : "merge8",
    "updated_at" : "2018-05-28 05:38:09 UTC",
    "updated_by_id" : null,
    "url" : "https://gitlab.CORP_HOSTNAME/MY_GROUP_NAME/tag_on_merge/merge_requests/8",
    "source" : {
      "id" : 12717,
      "name" : "tag_on_merge",
      "description" : "",
      "web_url" : "https://gitlab.CORP_HOSTNAME/MY_GROUP_NAME/tag_on_merge",
      "avatar_url" : null,
      "git_ssh_url" : "git@gitlab.CORP_HOSTNAME:MY_GROUP_NAME/tag_on_merge.git",
      "git_http_url" : "https://gitlab.CORP_HOSTNAME/MY_GROUP_NAME/tag_on_merge.git",
      "namespace" : "MY_GROUP_NAME",
      "visibility_level" : 10,
      "path_with_namespace" : "MY_GROUP_NAME/tag_on_merge",
      "default_branch" : "master",
      "ci_config_path" : null,
      "homepage" : "https://gitlab.CORP_HOSTNAME/MY_GROUP_NAME/tag_on_merge",
      "url" : "git@gitlab.CORP_HOSTNAME:MY_GROUP_NAME/tag_on_merge.git",
      "ssh_url" : "git@gitlab.CORP_HOSTNAME:MY_GROUP_NAME/tag_on_merge.git",
      "http_url" : "https://gitlab.CORP_HOSTNAME/MY_GROUP_NAME/tag_on_merge.git"
    },
    "target" : {
      "id" : 12717,
      "name" : "tag_on_merge",
      "description" : "",
      "web_url" : "https://gitlab.CORP_HOSTNAME/MY_GROUP_NAME/tag_on_merge",
      "avatar_url" : null,
      "git_ssh_url" : "git@gitlab.CORP_HOSTNAME:MY_GROUP_NAME/tag_on_merge.git",
      "git_http_url" : "https://gitlab.CORP_HOSTNAME/MY_GROUP_NAME/tag_on_merge.git",
      "namespace" : "MY_GROUP_NAME",
      "visibility_level" : 10,
      "path_with_namespace" : "MY_GROUP_NAME/tag_on_merge",
      "default_branch" : "master",
      "ci_config_path" : null,
      "homepage" : "https://gitlab.CORP_HOSTNAME/MY_GROUP_NAME/tag_on_merge",
      "url" : "git@gitlab.CORP_HOSTNAME:MY_GROUP_NAME/tag_on_merge.git",
      "ssh_url" : "git@gitlab.CORP_HOSTNAME:MY_GROUP_NAME/tag_on_merge.git",
      "http_url" : "https://gitlab.CORP_HOSTNAME/MY_GROUP_NAME/tag_on_merge.git"
    },
    "last_commit" : {
      "id" : "239a09e01881965d3bee6621be6ed01374798a4b",
      "message" : "merge8\n",
      "timestamp" : "2018-05-28T08:31:36+03:00",
      "url" : "https://gitlab.CORP_HOSTNAME/MY_GROUP_NAME/tag_on_merge/commit/239a09e01881965d3bee6621be6ed01374798a4b",
      "author" : {
        "name" : "FULL_NAME",
        "email" : "EMAIL"
      }
    },
    "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-05-28 05:38:09 UTC",
      "current" : "2018-05-28 05:38:09 UTC"
    },
    "total_time_spent" : {
      "previous" : null,
      "current" : 0
    }
  },
  "repository" : {
    "name" : "tag_on_merge",
    "url" : "git@gitlab.CORP_HOSTNAME:MY_GROUP_NAME/tag_on_merge.git",
    "description" : "",
    "homepage" : "https://gitlab.CORP_HOSTNAME/MY_GROUP_NAME/tag_on_merge"
  }
}

Problem description

  • what were you doing (simple push, merge request, MR with fork, ...)
    I've created a webhook trigger in a test project for accepted merge-requests only
    image
    ^^^ is the only checkbox checked (plus the verify SSL checkbox)

In Jenkins (2.73.3, Gitlab plugin 1.5.6) I've created a Pipeline project, checked the build when a change is pushed to GitLab. GitLab webhook URL: PROJECT_URL and marked only:
gitlab_webhook_config

Created a MR in the project - should not trigger the job
Accepted the MR in the project - webhook triggers and receives a 200 response (logs above) but the job doesn't get triggered.

Pipeline code:

node('SLAVE_LABEL') {
    properties([
        gitLabConnection('Gitlab-eng'),
        pipelineTriggers([
            [
                $class: 'GitLabPushTrigger',
                branchFilterType: 'All',
                triggerOnPush: false,
                triggerOnMergeRequest: false,
                triggerOnAcceptedMergeRequest: true,
                triggerOpenMergeRequestOnPush: "never",
                triggerOnNoteRequest: false,
                noteRegex: "Jenkins please retry a build",
                skipWorkInProgressMergeRequest: true,
                ciSkip: false,
                setBuildDescription: true,
                addNoteOnMergeRequest: true,
                addCiMessage: true,
                addVoteOnMergeRequest: true,
                acceptMergeRequestOnSuccess: false,
            ]
        ])
    ])
    dir(env.gitlabTargetRepoName) {
        checkout(
            changelog: true,
            poll: false,
            scm: [
                $class: 'GitSCM',
                branches: [[name: "origin/${env.gitlabTargetBranch}"]],
                doGenerateSubmoduleConfigurations: false,
                userRemoteConfigs: [[
                    credentialsId: 'CREDS_ID',
                    name: 'origin',
                    url: env.gitlabTargetRepoSshUrl
                ]]
            ]
        )
        echo sh(script: 'env|sort', returnStdout: true)
    }        
}
  • what was expected
    Accepted the MR in the project - webhook triggers and receives a 200 response (logs above) but the job doesn't get triggered.

  • what occurred finally
    Some log messages in Jenkins log, and 200 response in Gitlab side, no job gets triggered on Jenkins side.

UPDATE:
Configured the same webhook at the group level, the webhook triggers correctly (i've verified that the payload on Jenkins side is as expected) but them relevant job doesn't get triggered.

@ayashjorden
Copy link
Author

Another update:
Moved the webhook to the group level.

Configured the 'JOB_NAME' job to trigger on all events:
gitlab trigger config

Created MR in Gitlab - successfully triggered Jenkins Job with '"action" :
"open"'.
Merged the MR - the webhook calls the Jenkins API, but the 'tag_on_merge' job
doesn't get triggered.
-- see 'Jenkins Gitlab webhook logs' attachment:

May 28, 2018 7:54:20 AM INFO com.dabsquared.gitlabjenkins.webhook.GitLabWebHook getDynamic

WebHook called with url: /project/common/PROJECT_NAME

May 28, 2018 7:54:20 AM FINE com.dabsquared.gitlabjenkins.webhook.build.MergeRequestBuildAction 

MergeRequest: {
  "object_kind" : "merge_request",
  "user" : {
    "name" : "FULL_NAME",
    "username" : "USER_NAME",
    "avatar_url" : "AVATAR_URL"
  },
  "project" : {
    "id" : 12717,
    "name" : "PROJECT_NAME",
    "description" : "",
    "web_url" : "https://gitlab.CORP_HOST/GROUP_NAME/PROJECT_NAME",
    "avatar_url" : null,
    "git_ssh_url" : "git@gitlab.CORP_HOST:GROUP_NAME/PROJECT_NAME.git",
    "git_http_url" : "https://gitlab.CORP_HOST/GROUP_NAME/PROJECT_NAME.git",
    "namespace" : "GROUP_NAME",
    "visibility_level" : 10,
    "path_with_namespace" : "GROUP_NAME/PROJECT_NAME",
    "default_branch" : "master",
    "ci_config_path" : null,
    "homepage" : "https://gitlab.CORP_HOST/GROUP_NAME/PROJECT_NAME",
    "url" : "git@gitlab.CORP_HOST:GROUP_NAME/PROJECT_NAME.git",
    "ssh_url" : "git@gitlab.CORP_HOST:GROUP_NAME/PROJECT_NAME.git",
    "http_url" : "https://gitlab.CORP_HOST/GROUP_NAME/PROJECT_NAME.git"
  },
  "object_attributes" : {
    "assignee_id" : null,
    "author_id" : 181,
    "created_at" : "2018-05-28 07:54:20 UTC",
    "description" : "",
    "head_pipeline_id" : null,
    "id" : 14978,
    "iid" : 11,
    "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" : "unchecked",
    "merge_user_id" : null,
    "merge_when_pipeline_succeeds" : false,
    "milestone_id" : null,
    "source_branch" : "merge11",
    "source_project_id" : 12717,
    "state" : "opened",
    "target_branch" : "master",
    "target_project_id" : 12717,
    "time_estimate" : 0,
    "title" : "merge11",
    "updated_at" : "2018-05-28 07:54:20 UTC",
    "updated_by_id" : null,
    "url" : "https://gitlab.CORP_HOST/GROUP_NAME/PROJECT_NAME/merge_requests/11",
    "source" : {
      "id" : 12717,
      "name" : "PROJECT_NAME",
      "description" : "",
      "web_url" : "https://gitlab.CORP_HOST/GROUP_NAME/PROJECT_NAME",
      "avatar_url" : null,
      "git_ssh_url" : "git@gitlab.CORP_HOST:GROUP_NAME/PROJECT_NAME.git",
      "git_http_url" : "https://gitlab.CORP_HOST/GROUP_NAME/PROJECT_NAME.git",
      "namespace" : "GROUP_NAME",
      "visibility_level" : 10,
      "path_with_namespace" : "GROUP_NAME/PROJECT_NAME",
      "default_branch" : "master",
      "ci_config_path" : null,
      "homepage" : "https://gitlab.CORP_HOST/GROUP_NAME/PROJECT_NAME",
      "url" : "git@gitlab.CORP_HOST:GROUP_NAME/PROJECT_NAME.git",
      "ssh_url" : "git@gitlab.CORP_HOST:GROUP_NAME/PROJECT_NAME.git",
      "http_url" : "https://gitlab.CORP_HOST/GROUP_NAME/PROJECT_NAME.git"
    },
    "target" : {
      "id" : 12717,
      "name" : "PROJECT_NAME",
      "description" : "",
      "web_url" : "https://gitlab.CORP_HOST/GROUP_NAME/PROJECT_NAME",
      "avatar_url" : null,
      "git_ssh_url" : "git@gitlab.CORP_HOST:GROUP_NAME/PROJECT_NAME.git",
      "git_http_url" : "https://gitlab.CORP_HOST/GROUP_NAME/PROJECT_NAME.git",
      "namespace" : "GROUP_NAME",
      "visibility_level" : 10,
      "path_with_namespace" : "GROUP_NAME/PROJECT_NAME",
      "default_branch" : "master",
      "ci_config_path" : null,
      "homepage" : "https://gitlab.CORP_HOST/GROUP_NAME/PROJECT_NAME",
      "url" : "git@gitlab.CORP_HOST:GROUP_NAME/PROJECT_NAME.git",
      "ssh_url" : "git@gitlab.CORP_HOST:GROUP_NAME/PROJECT_NAME.git",
      "http_url" : "https://gitlab.CORP_HOST/GROUP_NAME/PROJECT_NAME.git"
    },
    "last_commit" : {
      "id" : "a291e71e66b7a9b159fa5d4cd270a5b1ff0b5422",
      "message" : "merge11\n",
      "timestamp" : "2018-05-28T10:53:46+03:00",
      "url" : "https://gitlab.CORP_HOST/GROUP_NAME/PROJECT_NAME/commit/a291e71e66b7a9b159fa5d4cd270a5b1ff0b5422",
      "author" : {
        "name" : "FULL_NAME",
        "email" : "USER_EMAIL"
      }
    },
    "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" : "PROJECT_NAME",
    "url" : "git@gitlab.CORP_HOST:GROUP_NAME/PROJECT_NAME.git",
    "description" : "",
    "homepage" : "https://gitlab.CORP_HOST/GROUP_NAME/PROJECT_NAME"
  }
}

May 28, 2018 7:54:20 AM INFO com.dabsquared.gitlabjenkins.trigger.handler.AbstractWebHookTriggerHandler handle

common/PROJECT_NAME triggered for merge request.

May 28, 2018 7:56:01 AM INFO com.dabsquared.gitlabjenkins.webhook.GitLabWebHook getDynamic

WebHook called with url: /project/common/PROJECT_NAME

May 28, 2018 7:56:01 AM FINE com.dabsquared.gitlabjenkins.webhook.build.MergeRequestBuildAction 

MergeRequest: {
  "object_kind" : "merge_request",
  "user" : {
    "name" : "FULL_NAME",
    "username" : "USER_NAME",
    "avatar_url" : "https://secure.gravatar.com/avatar/8035e0658c6bd51be58db92189cd480e?s=80&d=identicon"
  },
  "project" : {
    "id" : 12717,
    "name" : "PROJECT_NAME",
    "description" : "",
    "web_url" : "https://gitlab.CORP_HOST/GROUP_NAME/PROJECT_NAME",
    "avatar_url" : null,
    "git_ssh_url" : "git@gitlab.CORP_HOST:GROUP_NAME/PROJECT_NAME.git",
    "git_http_url" : "https://gitlab.CORP_HOST/GROUP_NAME/PROJECT_NAME.git",
    "namespace" : "GROUP_NAME",
    "visibility_level" : 10,
    "path_with_namespace" : "GROUP_NAME/PROJECT_NAME",
    "default_branch" : "master",
    "ci_config_path" : null,
    "homepage" : "https://gitlab.CORP_HOST/GROUP_NAME/PROJECT_NAME",
    "url" : "git@gitlab.CORP_HOST:GROUP_NAME/PROJECT_NAME.git",
    "ssh_url" : "git@gitlab.CORP_HOST:GROUP_NAME/PROJECT_NAME.git",
    "http_url" : "https://gitlab.CORP_HOST/GROUP_NAME/PROJECT_NAME.git"
  },
  "object_attributes" : {
    "assignee_id" : null,
    "author_id" : 181,
    "created_at" : "2018-05-28 07:54:20 UTC",
    "description" : "",
    "head_pipeline_id" : null,
    "id" : 14978,
    "iid" : 11,
    "last_edited_at" : null,
    "last_edited_by_id" : null,
    "merge_commit_sha" : "5b2b30a69aa76840ed8119b9ab5de6d31e357e75",
    "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" : "merge11",
    "source_project_id" : 12717,
    "state" : "merged",
    "target_branch" : "master",
    "target_project_id" : 12717,
    "time_estimate" : 0,
    "title" : "merge11",
    "updated_at" : "2018-05-28 07:56:01 UTC",
    "updated_by_id" : null,
    "url" : "https://gitlab.CORP_HOST/GROUP_NAME/PROJECT_NAME/merge_requests/11",
    "source" : {
      "id" : 12717,
      "name" : "PROJECT_NAME",
      "description" : "",
      "web_url" : "https://gitlab.CORP_HOST/GROUP_NAME/PROJECT_NAME",
      "avatar_url" : null,
      "git_ssh_url" : "git@gitlab.CORP_HOST:GROUP_NAME/PROJECT_NAME.git",
      "git_http_url" : "https://gitlab.CORP_HOST/GROUP_NAME/PROJECT_NAME.git",
      "namespace" : "GROUP_NAME",
      "visibility_level" : 10,
      "path_with_namespace" : "GROUP_NAME/PROJECT_NAME",
      "default_branch" : "master",
      "ci_config_path" : null,
      "homepage" : "https://gitlab.CORP_HOST/GROUP_NAME/PROJECT_NAME",
      "url" : "git@gitlab.CORP_HOST:GROUP_NAME/PROJECT_NAME.git",
      "ssh_url" : "git@gitlab.CORP_HOST:GROUP_NAME/PROJECT_NAME.git",
      "http_url" : "https://gitlab.CORP_HOST/GROUP_NAME/PROJECT_NAME.git"
    },
    "target" : {
      "id" : 12717,
      "name" : "PROJECT_NAME",
      "description" : "",
      "web_url" : "https://gitlab.CORP_HOST/GROUP_NAME/PROJECT_NAME",
      "avatar_url" : null,
      "git_ssh_url" : "git@gitlab.CORP_HOST:GROUP_NAME/PROJECT_NAME.git",
      "git_http_url" : "https://gitlab.CORP_HOST/GROUP_NAME/PROJECT_NAME.git",
      "namespace" : "GROUP_NAME",
      "visibility_level" : 10,
      "path_with_namespace" : "GROUP_NAME/PROJECT_NAME",
      "default_branch" : "master",
      "ci_config_path" : null,
      "homepage" : "https://gitlab.CORP_HOST/GROUP_NAME/PROJECT_NAME",
      "url" : "git@gitlab.CORP_HOST:GROUP_NAME/PROJECT_NAME.git",
      "ssh_url" : "git@gitlab.CORP_HOST:GROUP_NAME/PROJECT_NAME.git",
      "http_url" : "https://gitlab.CORP_HOST/GROUP_NAME/PROJECT_NAME.git"
    },
    "last_commit" : {
      "id" : "a291e71e66b7a9b159fa5d4cd270a5b1ff0b5422",
      "message" : "merge11\n",
      "timestamp" : "2018-05-28T10:53:46+03:00",
      "url" : "https://gitlab.CORP_HOST/GROUP_NAME/PROJECT_NAME/commit/a291e71e66b7a9b159fa5d4cd270a5b1ff0b5422",
      "author" : {
        "name" : "FULL_NAME",
        "email" : "USER_EMAIL"
      }
    },
    "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-05-28 07:56:01 UTC",
      "current" : "2018-05-28 07:56:01 UTC"
    },
    "total_time_spent" : {
      "previous" : null,
      "current" : 0
    }
  },
  "repository" : {
    "name" : "PROJECT_NAME",
    "url" : "git@gitlab.CORP_HOST:GROUP_NAME/PROJECT_NAME.git",
    "description" : "",
    "homepage" : "https://gitlab.CORP_HOST/GROUP_NAME/PROJECT_NAME"
  }
}

As you can see, There is no common/PROJECT_NAME triggered for merge request. line at the end of the second call.

@ayashjorden
Copy link
Author

This may be related to #762
Tried to enable the Jenkins trigger to also on approve events, it did trigger on approval of the MR but not on the "action" : "merge" event. 😠

@omehegan
Copy link
Member

@ayashjorden thanks for the additional logging details you provided, but I think you are right that this bug was documented in #734 and we have a fix in #762 which just needs to be merged (I am waiting on the author to resolve the merge conflicts). If you agree, please close this issue. Thanks!

@ayashjorden
Copy link
Author

Hi @omehegan,
My workaround is 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 (git tagging in my case)

Let's spread this idea, comments are welcome :thumbup;

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

2 participants