jenkinsci / jenkinsci/gitlab-plugin
Wrong target_url for pending status when parallell builds are queued
- Dominant language
- Java
- Stars
- 1.4k
- Forks
- 615
- Avg merge
- 4h 32m
- Merged PRs (30d)
- 10
Description
## Issue
### Context
- **Gitlab plugin version**: 1.4.5
- **Gitlab version**: 8.17.2-ee
- **Jenkins version**: 1.650
- **Job type**: Maven project
### Logs & Traces
Creation of pending commit status. The target_url does not point to the build that actually built branch-A later. That was in fact done by build 680.
```
Call GitLab:
HTTP method: POST
URL: https:///api/v3/projects/1/statuses/d516fe7776d11d4bda4e9002e3a8c78b19fb90e5
Request headers: [
Accept = [application/json],
Content-Type = [application/x-www-form-urlencoded],
PRIVATE-TOKEN = [****FILTERED****]
]
Mar 15, 2017 1:07:37 PM FINEST com.dabsquared.gitlabjenkins.gitlab.GitLabClientBuilder
Got response from GitLab:
URL: https:///api/v3/projects/1/statuses/d516fe7776d11d4bda4e9002e3a8c78b19fb90e5
Status: 201 Created
Response headers: [
Cache-Control = [max-age=0, private, must-revalidate],
Connection = [keep-alive],
Content-Length = [557],
Content-Type = [application/json],
Date = [Wed, 15 Mar 2017 12:07:22 GMT],
Etag = [W/"be7adc8781d5ad02b00fd4e2a1a46485"],
Server = [nginx],
Vary = [Origin],
X-Request-Id = [fa413498-6444-4090-ae44-52d00122b0b9],
X-Runtime = [0.154868]
]
Response body: {
"id" : 1203,
"sha" : "d516fe7776d11d4bda4e9002e3a8c78b19fb90e5",
"ref" : "branch-A",
"status" : "pending",
"name" : "jenkins",
"target_url" : "https:///jenkins/job/GitlabMergeRequests/679/",
"description" : null,
"created_at" : "2017-03-15T12:07:22.184Z",
"started_at" : null,
"finished_at" : null,
"allow_failure" : false,
"author" : {
"name" : "Administrator",
"username" : "root",
"id" : 1,
"state" : "active",
"avatar_url" : "https:///uploads/user/avatar/1/avatar.png",
"web_url" : "https:///root"
}
}
```
Creation of running commit status. Same target_url, but different commit and branch. However, this time it is correct. Build 679 did build that branch and commit.
```
Mar 15, 2017 1:14:56 PM FINEST com.dabsquared.gitlabjenkins.gitlab.GitLabClientBuilder
Call GitLab:
HTTP method: POST
URL: https:///api/v3/projects/1/statuses/9d0dec909237cb2c650c7a9f90797d6952da37a4
Request headers: [
Accept = [application/json],
Content-Type = [application/x-www-form-urlencoded],
PRIVATE-TOKEN = [****FILTERED****]
]
Mar 15, 2017 1:14:56 PM FINEST com.dabsquared.gitlabjenkins.gitlab.GitLabClientBuilder
Got response from GitLab:
URL: https:///api/v3/projects/1/statuses/9d0dec909237cb2c650c7a9f90797d6952da37a4
Status: 201 Created
Response headers: [
Cache-Control = [max-age=0, private, must-revalidate],
Connection = [keep-alive],
Content-Length = [533],
Content-Type = [application/json],
Date = [Wed, 15 Mar 2017 12:14:46 GMT],
Etag = [W/"5f7017b8d76bc00e6d31e5d620b8bd07"],
Server = [nginx],
Vary = [Origin],
X-Request-Id = [30574f32-9415-456e-ab77-1feaa3c7dbdb],
X-Runtime = [0.140720]
]
Response body: {
"id" : 1204,
"sha" : "9d0dec909237cb2c650c7a9f90797d6952da37a4",
"ref" : "branch-B",
"status" : "running",
"name" : "jenkins",
"target_url" : "https:///jenkins/job/GitlabMergeRequests/679/",
"description" : null,
"created_at" : "2017-03-15T12:14:45.945Z",
"started_at" : "2017-03-15T12:14:45.959Z",
"finished_at" : null,
"allow_failure" : false,
"author" : {
"name" : "Administrator",
"username" : "root",
"id" : 1,
"state" : "active",
"avatar_url" : "https:///uploads/user/avatar/1/avatar.png",
"web_url" : "https:///root"
}
}
```
### Problem description
For our project we have a single jenkins job setup to build all MR:s. The job has *Execute concurrent builds if necessary* enabled to allow multiple MR:s to be built in parallell.
I recently noticed that some commits had double status objects in gitlab:

Curiously the two jobs point to different jenkins builds, each for a different MR. The running status is for the MR which contains the current commit, but the pending status belongs to a job that is building a completely different MR. The current pipeline for that MR looks like this:

Job 1204 har the same URL as job 1203 in the previous image.
Until now we've been spared from extra pending commit statuses since #489 was fixed. What has changed on our end is that we are doing many more builds than before and sometimes a build queue with waiting MR builds has formed. My hunch is that the wrong build number is used when the pending status is created. The code seems to use `job.getNextBuildNumber()`, which I guess doesn't work out when multiple builds are queued up.
Contributor guide
Assessment
This issue has not been assessed yet.