Pipeline symbol missing in MR commits when `gitlab-ci.yml` job uses `rules` instead of `except`
Summary
This issue is about the pipeline symbol on the right side of a commit within a Merge Request (see image below). In the following they are often referenced as "pipeline indicators".
After replacing the except
section with a rules
section for a job in the .gitlab-ci.yml
, the indicator telling, whether the commit has passed the pipeline or not, was not shown anymore.
I investigated it today and I believe I found what causes this problem.
First of all, here the commits I made during my tests (all of those commits were pushed on their own):
Here the exact diff of what resulted in the indicator not being shown anymore:
compile:
stage: Build
- except:
- - master
- - tags
+ rules:
+ - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
+ - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
script:
- 'mvn test-compile'
This change led to two changes regarding pipelines.
- After this change, the created pipeline got the
merge request
"label".
This pipeline ran on the contents of this merge request's source branch, not the target branch.
Before, this was not the case (see difference below between the pipelines for commit 1 and 2).
- When using multiple jobs, all jobs were executed in a single pipeline.
Before, there was one pipeline for the compile
job and one for the further jobs (see difference below between the pipelines for commit 3 and 4). This sadly had the side effect that the two pipelines were running in parallel and not sequentially.
Here an overview over all pipelines. I edited it to make it (hopefully) easier to understand what I think the issue is.
I assume the bug is that the pipeline indicator is not shown for a commit if there is no pipeline for the branch itself / if all pipelines for the commit have the merge request
"label".
Steps to reproduce
- Add / Use the following
.gitlab-ci.yml
:
image: maven:3.8.5-openjdk-17
stages:
- Build
compile:
stage: Build
except:
- master
- tags
script:
- 'mvn test-compile'
- Create a new branch, make a commit, push it and open a Merge Request. The
compile
job should run for the commit and you should have two pipelines (for thecompile
andtest
job). - Apply the diff from above (replace
except
withrules
, the first rule will make the job getting triggered). - Commit and push the change. Now there should be no indicator beside the commit.
Example Project
I created a test project to show this. Sadly due to missing verification, pipelines are not running. It has the same commits as shown here via. screenshots. With that, you can see exactly what I changed.
DManstrator/gitlab-ci-test-project!1
Notice: In this project, there were two pipelines for each pushed commit even the gitlab-ci.yml
was configured exactly as in the private GitLab instance. I'm not sure if this is caused by erroring out due to missing verification.
What is the current bug behavior?
As explained above, there is no indicator for the pipeline shown for a commit of a MR when the commit has no pipeline targeting the branch itself / the commit only having pipelines with the merge request
"label". This is somehow caused by using rules
instead of except
for the job in the gitlab-ci.yml
.
What is the expected correct behavior?
There should be an indicator for the pipeline for each pushed commit of a MR even if there is no pipeline directly targeting the branch.
Relevant logs and/or screenshots
See above.
Output of checks
I can't tell if this is a general GitLab issue, I assume it is.
Results of GitLab environment info
Self-hosted GitLab. Sadly I'm not able to find out more about our environment.
Results of GitLab application Check
GitLab Community Edition 14.9.3.
Possible fixes
Also displaying the pipeline indicator if there is no pipeline directly targeting the branch.