Skip to content

Post build status to non-branch pipelines creates a new pipeline

Summary

Adding build status through commit statuses API usually adds a new stage in the pipeline. If the pipeline is tied to a Merge Request (by adding stages with only: merge_requests), the API creates a new pipeline instead of adding a new stage in the pipeline. This is also the case if we use only: tags and tries to add build status to the pipeline.

If we trigger the API inside our pipeline, it means that the new pipeline will be prioritised instead. What happens is our original pipeline will not be shown in Merge Request page. It also means that manual stages can't be clicked through the Merge Request page and we need to trigger it via CI/CD > Pipelines page or API. I'm not sure if there are other means to trigger this, but I'm pretty sure it will be worse experience than just clicking the manual stage on the Merge Request page.

Steps to reproduce

  1. Create a new project, initialise it with README.md
  2. Create a new branch, add .gitlab-ci.yml with the following code, commit, and push:
stages:
  - test

test:
  stage: test
  script:
    - ":"
  only:
    - merge_requests
  1. Create a new Merge Request from that branch against master.
  2. Hit the API with the required parameters only:
curl -X POST -vL -H 'Private-Token: <token>' "gitlab.com/api/v4/projects/<project id>/statuses/<commit sha>?state=success"
  1. Look for the pipeline(s) in CI/CD > Pipelines, there should be two pipeline:
  • Pipeline with stages test
  • Pipeline with stages external

Example Project

See the two pipelines in https://gitlab.com/aufarg/pipeline-test/pipelines for commit db81cd7db72ebfb5ba7d8aa0471cabd931aac274.

The second pipeline is the original pipeline, tied to the Merge Request.

The first pipeline is the external pipeline, created after I do step 4 in Steps to reproduce section.

See pipelines for commit 38edd881a68cb90a403796db1487544d342b3dd8 for tags pipeline.

What is the current bug behavior?

Adding build status to a commit creates a new pipeline that is tied to the branch.

What is the expected correct behavior?

Adding build status to a commit should also reflect to other type of pipeline.

Relevant logs and/or screenshots

Screenshot_20190830_223058

Output of checks

This bug happens on GitLab.com

Results of GitLab environment info

N/A

Results of GitLab application Check

N/A

Possible fixes

In lib/api/commit_statuses.rb:72, it seems that we only search for pipelines tied to a branch and if it cannot find one, it will create a new pipeline. Maybe we can consider other refs too if we cannot find the pipeline from branch only.

Currently, workaround exists by explicitly specifying the Merge Request/Tags ref as ref parameter. It will solves this issue, but current behavior is not intuitive.

Edited by Aufar Gilbran