jenkinsci / gitlab-plugin

A Jenkins plugin for interfacing with GitLab
https://plugins.jenkins.io/gitlab-plugin/
GNU General Public License v2.0
1.43k stars 612 forks source link

Feature: Stop Jenkins build if the related Gitlab pipeline has been canceled #607

Open trunov-ms opened 7 years ago

trunov-ms commented 7 years ago

If I cancel pipeline in GitLab Jenkins get response from Gitlab like this

Aug 19, 2017 5:01:27 PM FINEST com.dabsquared.gitlabjenkins.gitlab.GitLabClientBuilder
Got response from GitLab:
URL: https://gitlab.local/api/v3/projects/724/repository/commits/cd3a7656bff11f26dd525f6e9a72e3b8ef4acf2b
Status: 200 OK
Response headers: [
Cache-Control = [max-age=0, private, must-revalidate],
Connection = [keep-alive],
Content-Length = [565],
Content-Type = [application/json],
Date = [Sat, 19 Aug 2017 12:01:27 GMT],
Etag = [W/"048f9623f241e8b4e01feaf9df2f9af4"],
Server = [nginx],
Strict-Transport-Security = [max-age=31536000],
Vary = [Origin],
X-Frame-Options = [SAMEORIGIN],
X-Request-Id = [730a5830-50ed-4d7e-bf0f-05931d46a4e2],
X-Runtime = [0.027535]
]
Response body: {
  "id" : "cd3a7656bff11f26dd525f6e9a72e3b8ef4acf2b",
  "short_id" : "cd3a7656",
  "title" : "Update README.md",
  "created_at" : "2017-08-19T17:00:12.000+05:00",
  "parent_ids" : [ "46586ec4ea96e1096a24b8929213248080603c6a" ],
  "message" : "Update README.md",
  "author_name" : "commiter name",
  "author_email" : "commiter email",
  "authored_date" : "2017-08-19T17:00:12.000+05:00",
  "committer_name" : "commiter name",
  "committer_email" : "commiter email",
  "committed_date" : "2017-08-19T17:00:12.000+05:00",
  "stats" : {
    "additions" : 3,
    "deletions" : 0,
    "total" : 3
  },
  "status" : "canceled"
}

I can see "status" : "canceled" in this response. Is it possible to stop Jenkins build if the related Gitlab pipeline has been canceled? Or remove the build from the Jenkins queue if it is not already running.

omehegan commented 7 years ago

Interesting feature request. I didn't know you could do this in GitLab. It seems a little strange to use the GitLab UI to cancel Jenkins builds, but in theory we could support this. I won't have time to build it, but if someone wants to submit a PR we would definitely consider it.

sebastienbonami commented 6 years ago

I also want this.

daks commented 6 years ago

@omehegan for me, it's not that strange. Because this plugin is so powerful that all absolutely needed information about builds are available in our Gitlab instance, which is the place where we work. Jenkins consultation becomes optional, except for failed builds.

Thanks all for your job :)

chinhodado commented 6 years ago

I want this feature as well. From a GitLab user's perspective, it's even a bit unexpected that cancelling a pipeline inside GitLab does not actually stop it from running.

sebastienbonami commented 6 years ago

Any news on this?

linzhenan commented 6 years ago

I need this feature as well. If I cancel a build job in GitLab, the icon will be "cancelled". But the job in Jenkins is still running (or pending if there is a previous job running). After all queued jobs done, the icons in GitLab may be in wrong status.

bwaldvogel commented 5 years ago

+1

Is a workaround available?

omehegan commented 5 years ago

No workaround available. This would require a change to the plugin to respond to the 'cancelled' message from GitLab. As I said previously, I'm not in a position to work on that, but if anyone else wants to I would be happy to review a PR.

BarrMan commented 3 weeks ago

No workaround available. This would require a change to the plugin to respond to the 'cancelled' message from GitLab. As I said previously, I'm not in a position to work on that, but if anyone else wants to I would be happy to review a PR.

I'll take this issue, let's talk before I start implementing anything.