Why Post Commit status API not returns pipeline_id in same call

When using API https://docs.gitlab.com/ce/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/ce/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

API should return pipeline_id created in same response
https://docs.gitlab.com/ce/api/commits.html#post-the-build-status-to-a-commit

1 Like