Allow conditional statements (only, except, when) to run a job or not
Description
Currently jobs can be run/not with only
/except
based on branch specifiers. For many use cases this works like a charm. However sometimes it would be nice to run a job based on a condition. I.e. we only want to publish/promote artifacts for the nightly build
Proposal
Allow when
, only
/except
to evaluate a condition based on variables
Links / references
Ansible supports something similar with their when statement
Documentation blurb
Overview
What is it?
Expanding conditional execution of jobs
Why should someone use this feature?
Some jobs need to run conditional, but there aren't always specific branches for this condition
What is the underlying (business) problem?
We publish artifacts during the nightly build. This runs from master, but not all master builds should publish artifacts.
How do you use this feature?
...
publish:
stage: publish
script:
- ./publish.sh
when: $PUBLISH_ARTIFACTS==true
...
In this case it can be triggered like so:
curl -X POST -F token=${ACCESS_TOKEN} \
-F ref=master \
-F variables[PUBLISH_ARTIFACTS]=true \
https://gitlab.example.com/api/v4/projects/${project_id}/trigger/pipeline
Use cases
Who is this for? Provide one or more use cases.
Feature checklist
Make sure these are completed before closing the issue, with a link to the relevant commit.
-
Feature assurance -
Documentation -
Added to features.yml