Post Commit status API needs to create and list newly created pipeline in same call.
Summary
When using API https://docs.gitlab.com/ee/api/commits.html#post-the-build-status-to-a-commit to post a job status from external CI tool, if no existing pipeline exists or non matching pipeline_id =-1 is given, then API creates new pipeline.
This newly created pipeline is not given in response of same API call but a separate API call is needed to fetch last pipeline. https://docs.gitlab.com/ee/api/commits.html#get-a-single-commit
As some other service can also create a pipeline in between two calls, Its not guaranteed to get intended pipeline_id. So subsequent commit status might post to different pipeline. Original pipeline hangs in pending state.
Steps to reproduce
Step 1: curl --request POST --header "PRIVATE-TOKEN: " "https://gitlab.com/api/v4/projects/:id/statuses/:sha?name=Job1&state=pending&description=Pending&pipeline_id=-1"
Step 2: curl --request GET --header "PRIVATE-TOKEN: " "https://gitlab.com/api/v4/projects/:id/repository/commits/:sha"
What is the expected correct behavior?
Below API should also return pipeline_id created https://docs.gitlab.com/ee/api/commits.html#post-the-build-status-to-a-commit
Relevant logs and/or screenshots
Output of checks
Results of GitLab environment info
Expand for output related to GitLab environment info
(For installations with omnibus-gitlab package run and paste the output of:
sudo gitlab-rake gitlab:env:info
)(For installations from source run and paste the output of:
sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
)
Results of GitLab application Check
Expand for output related to the GitLab application check
(For installations with omnibus-gitlab package run and paste the output of:
sudo gitlab-rake gitlab:check SANITIZE=true
)(For installations from source run and paste the output of:
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true
)(we will only investigate if the tests are passing)
Proposal
Return pipeline_id
in the POST /projects/:id/statuses/:sha
request.
This can be done via modifying the API::Entities::CommitStatus
.
diff --git a/lib/api/entities/commit_status.rb b/lib/api/entities/commit_status.rb
index df6a41895ffb..7bca63f2632b 100644
--- a/lib/api/entities/commit_status.rb
+++ b/lib/api/entities/commit_status.rb
@@ -18,6 +18,7 @@ class CommitStatus < Grape::Entity
expose :finished_at, documentation: { type: 'dateTime', example: '2016-01-21T08:40:25.832Z' }
expose :allow_failure, documentation: { type: 'boolean', example: false }
expose :coverage, documentation: { type: 'number', format: 'float', example: 98.29 }
+ expose :pipeline_id, documentation: { type: 'integer', example: 101 }
expose :author, using: Entities::UserBasic
end
As the GET /projects/:id/repository/commits/:sha/statuses
also uses the same API::Entities::CommitStatus
, responses of this endpoint will automatically have pipeline_id
added with the code snippet above.