Please help fill in this template with all the details to help others help you more efficiently. Use formatting blocks for code, config, logs and ensure to remove sensitive data.
Context
By default a CI configuration that doesnât use any rules
does not launch a merge request pipeline, but does launch for basically every other pipeline source (push, tag, trigger, pipeline, etc). This is fine.
I am developing a number of CI/CD components that developers in my org are encouraged to use to build/test/secure their applications.
I would like to ensure that jobs configured by the components can be disabled individually via job rules
but otherwise run in whatever pipeline the developer has configured.
Problem to solve
I have a very basic project with a very basic CI configuration here: https://gitlab.com/duncanmmacleod/test-pipeline-rules. This pipeline has a single job that always runs, which results in pipelines for pushes to all branches, tags, but not merge request pipelines (as per the default).
If I add a second job to the pipeline on a feature branch, a âpushâ pipeline is launched, but no duplicate âmerge requestâ pipeline is launched when an MR is opened for that branch. That can be seen here: https://gitlab.com/duncanmmacleod/test-pipeline-rules/-/merge_requests/2
However, I would like to configure a job that supports being disabled via rules
, e.g. by a variable that specifies disabling it, so that the job can be excluded under certain circumstances (web pipelines, schedules, etc).
My ânaiveâ attempt to achieve this is something like
conditional job:
script:
- echo "This is a test"
rules:
# allow users to disable it
- if: $DISABLE_TEST_JOB == 'true'
when: never
# but otherwise run it as normal for all types of pipelines where it
# would run by default
- when: on_success
However. This rules
stanza âaccidentallyâ triggers a merge request pipeline that wasnât asked for. This can be seen here: https://gitlab.com/duncanmmacleod/test-pipeline-rules/-/merge_requests/1
I understand that I could use the following for the âotherwise runâ rule:
- if: $CI_COMMIT_BRANCH
which is used throughout many of the job templates/components provided by gitlab-org (e.g. here), however that has the negative side effect of meaning that this job is excluded from merge request pipelines if the developer opts into those using workflow:rules
. See https://gitlab.com/duncanmmacleod/test-pipeline-rules/-/merge_requests/3
Is there a way to configure a job with rules
that effectively achieves the following:
job:
rules:
- if: disabled by whatever means
when: never
- if: otherwise
when: on_success
without also having to configure workflow:rules
and without spawning merge request pipelines that werenât asked for?
Any advice is great, including âno this isnât possibleâ.
Steps to reproduce
See https://gitlab.com/duncanmmacleod/test-pipeline-rules/ and proposed changes in open merge requests.
Configuration
See https://gitlab.com/duncanmmacleod/test-pipeline-rules/ and proposed changes in open merge requests.
Versions
Please select whether options apply, and add the version information.
- Self-managed
- GitLab.com SaaS
- Self-hosted Runners
Versions
- GitLab (Web:
/help
or self-managed system information): - GitLab Runner, if self-hosted (Web
/admin/runners
or CLIgitlab-runner --version
):
Helpful resources
- Before opening a new topic, make sure to search for keywords in the forum search
- Check the GitLab Runner and GitLab projects for existing issues. If you encounter a bug, please create a bug report issue.
- Troubleshooting docs: GitLab Runner, self-managed GitLab instances.
Thanks for taking the time to be thorough in your request, it really helps!