It appears that when I make a call to addGitLabMRComment, there is no request to GitLab made behind the scenes. The gitlabCommitStatus call does work perfectly though, so it isn't an issue with the connection to GitLab.
Here is the relevant console output from the job:
[Pipeline] properties
[Pipeline] node
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Checkout)
[Pipeline] checkout
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Build)
[Pipeline] gitlabCommitStatus
[Pipeline] {
[Pipeline] sh
+ ./gradlew build
BUILD SUCCESSFUL
Total time: 6.042 secs
[Pipeline] }
[Pipeline] // gitlabCommitStatus
[Pipeline] addGitLabMRComment
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
And here is the output from the logger during the build:
Jul 20, 2017 1:08:43 PM FINE com.dabsquared.gitlabjenkins.webhook.build.PushBuildAction
Push: {
"object_kind" : "push",
"event_name" : "push",
"ref" : "refs/heads/test-branch",
"message" : null,
"user_id" : 1,
"project_id" : 1,
"project" : {
"name" : "test-project",
},
"commits" : [ {
"id" : "99df37fc9ddf25bd0ff0ed4d72fa4293ca9f91f1",
"message" : "Trigger build\n",
"timestamp" : "2017-07-20T13:08:42-04:00",
} ],
"total_commits_count" : 1,
"repository" : {
"name" : "test-project",
}
}
Jul 20, 2017 1:08:43 PM FINE com.dabsquared.gitlabjenkins.webhook.build.PushBuildAction
Notify scmSourceOwner test-project about changes for http://gitlab.example.com/test-user/test-project.git
Jul 20, 2017 1:08:45 PM INFO com.dabsquared.gitlabjenkins.util.CommitStatusUpdater retrieveGitlabProjectIds
Retrieving gitlab project ids
Jul 20, 2017 1:08:45 PM INFO com.dabsquared.gitlabjenkins.util.CommitStatusUpdater addGitLabBranchBuild
Retrieving the gitlab project id from remote url http://gitlab.example.com/test-user/test-project.git
Jul 20, 2017 1:08:45 PM FINEST com.dabsquared.gitlabjenkins.gitlab.GitLabClientBuilder
Call GitLab:
HTTP method: GET
URL: http://gitlab.example.com/api/v3/projects/test-user%2Ftest-project/repository/commits/99df37fc9ddf25bd0ff0ed4d72fa4293ca9f91f1
...
Jul 20, 2017 1:08:45 PM FINEST com.dabsquared.gitlabjenkins.gitlab.GitLabClientBuilder
Got response from GitLab:
URL: http://gitlab.example.com/api/v3/projects/test-user%2Ftest-project/repository/commits/99df37fc9ddf25bd0ff0ed4d72fa4293ca9f91f1
Status: 200 OK
...
Jul 20, 2017 1:08:45 PM FINEST com.dabsquared.gitlabjenkins.gitlab.GitLabClientBuilder
Call GitLab:
HTTP method: POST
URL: http://gitlab.example.com/api/v3/projects/test-user%2Ftest-project/statuses/99df37fc9ddf25bd0ff0ed4d72fa4293ca9f91f1
...
Jul 20, 2017 1:08:45 PM FINEST com.dabsquared.gitlabjenkins.gitlab.GitLabClientBuilder
Got response from GitLab:
URL: http://gitlab.example.com/api/v3/projects/test-user%2Ftest-project/statuses/99df37fc9ddf25bd0ff0ed4d72fa4293ca9f91f1
Status: 201 Created
...
Jul 20, 2017 1:08:52 PM INFO com.dabsquared.gitlabjenkins.util.CommitStatusUpdater retrieveGitlabProjectIds
Retrieving gitlab project ids
Jul 20, 2017 1:08:52 PM INFO com.dabsquared.gitlabjenkins.util.CommitStatusUpdater addGitLabBranchBuild
Retrieving the gitlab project id from remote url http://gitlab.example.com/test-user/test-project.git
Jul 20, 2017 1:08:52 PM FINEST com.dabsquared.gitlabjenkins.gitlab.GitLabClientBuilder
Call GitLab:
HTTP method: GET
URL: http://gitlab.example.com/api/v3/projects/test-user%2Ftest-project/repository/commits/99df37fc9ddf25bd0ff0ed4d72fa4293ca9f91f1
...
Jul 20, 2017 1:08:52 PM FINEST com.dabsquared.gitlabjenkins.gitlab.GitLabClientBuilder
Got response from GitLab:
URL: http://gitlab.example.com/api/v3/projects/test-user%2Ftest-project/repository/commits/99df37fc9ddf25bd0ff0ed4d72fa4293ca9f91f1
Status: 200 OK
...
Jul 20, 2017 1:08:52 PM FINEST com.dabsquared.gitlabjenkins.gitlab.GitLabClientBuilder
Call GitLab:
HTTP method: POST
URL: http://gitlab.example.com/api/v3/projects/test-user%2Ftest-project/statuses/99df37fc9ddf25bd0ff0ed4d72fa4293ca9f91f1
...
Jul 20, 2017 1:08:52 PM FINEST com.dabsquared.gitlabjenkins.gitlab.GitLabClientBuilder
Got response from GitLab:
URL: http://gitlab.example.com/api/v3/projects/test-user%2Ftest-project/statuses/99df37fc9ddf25bd0ff0ed4d72fa4293ca9f91f1
Status: 201 Created
...
My Jenkinsfile looks something like this:
#!/usr/bin/env groovy
def projectProperties = [
gitLabConnection('gitlab'),
]
properties(projectProperties)
try {
node() {
stage("Checkout") {
checkout scm
}
stage("Build") {
gitlabCommitStatus("build") {
sh "./gradlew build"
}
addGitLabMRComment comment: "Success!"
}
}
} catch (e) {
addGitLabMRComment comment: "Uh-oh!"
throw e
}
I think the MR comment is not happening because this job was triggered by a push, rather than by an MR being opened or changed, etc. See "event_name" : "push",
Looking at the code, it seems we would need to know the MR ID in order to be able to comment to it. That is only sent by the GitLab MR webhook, not the push webhook. Without an MR ID, calling this method just does nothing. Perhaps we should log a warning that we can't comment on an MR if the job was triggered manually or by a push trigger.
@darwish can you confirm if your GitLab project has MR triggers set up, or just push triggers?
@omehegan Adding the MR triggers doesn't seem to have an effect. If I enable both the Push and the MR triggers, I can see both triggers in the log, but only the Push trigger seems to actually cause a build (and the MR comments don't work). If I only enable MR triggers, I see it in the log but no build is triggered.
@darwish oh right, I think that's because this is a Multibranch Pipeline job. For those, MR hooks won't trigger. I guess this is a bug.
Folks, any update on this from gitlab side. I am also experiencing same for Multibranch Pipeline job, my addGitLabMRComment is not working on creating new MR and it is not reflected under "Discussion" tab.
Can we request gitlab people to address this issue ?
This would indeed be greatly appreciated.
As of now, this plugin is basically useless for multibranch pipelines (sadly this means 100% of all CIs I'm building).
It only allows us to have some information in the "Pipeline" tab of Gitlab but that's about it. No MR blocked until build is OK, no badge available to know at a glance if the build succeeded, no message posted in the MR discussion in case of success / failure…
Is this planned someday or is https://github.com/jenkinsci/gitlab-branch-source-plugin supposed to replace this plugin?
Can someone explain why addGitLabMRComment is not documented? I've been looking for this for hours and now finding it deep within an issue makes me look dumb.
How do you even find these missing useful methods?
@codeasashu Because it was not yet documented. But yeah, I lost a solid hour over this one.
Most helpful comment
This would indeed be greatly appreciated.
As of now, this plugin is basically useless for multibranch pipelines (sadly this means 100% of all CIs I'm building).
It only allows us to have some information in the "Pipeline" tab of Gitlab but that's about it. No MR blocked until build is OK, no badge available to know at a glance if the build succeeded, no message posted in the MR discussion in case of success / failure…
Is this planned someday or is https://github.com/jenkinsci/gitlab-branch-source-plugin supposed to replace this plugin?