Allow creating variables in workflow:rules:if so they can be used in job rules:if
Description
We have a number of "different" pipelines that run different levels of testing deployment etc. Examples of our different pipelines include:
- Merge request pipelines - regular developer pipelines with minimal testing, and manual jobs for additional tests/builds available.
- Release/master pipelines - same as merge request pipelines with some extra .
- Tagged builds - same as release/master pipelines but runs all tests and deploys builds to a shared Artifactory instance. There are others that are excluded for brevity.
We have templates for rules:if rules that determine whether a job is required or not. These are quite long, complicated, and have lots of room for errors. Testing changes to them is tricky as we need to trigger pipelines for each scenario (e.g. creating tags, branches with particular names etc).
This is means that maintenance of the pipelines is difficult, and adding a new "type" of pipeline can be very arduous.
Proposal
Allow the definition of variables in workflow:rules entries. These variables can then be used in job rules:if templates to shorten them drastically. These variables could also then be overwritten when creating pipelines via the UI or API making creating a specific "type" of pipeline very easy.
For example:
workflow:
rules:
- if: $CI_COMMIT_TAG
variables:
PIPELINE_TYPE: merge_request
- if: $CI_COMMIT_BRANCH == "master" || $CI_COMMIT_BRANCH =~ /^release\/.*$/
variables:
PIPELINE_TYPE: special_branch
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
variables:
PIPELINE_TYPE: tagged_build
.merge_request_job:
rules:
- if: '$PIPELINE_TYPE == "merge_request" || $PIPELINE_TYPE == "special_branch" || $PIPELINE_TYPE == "tagged_build"'
when: always
.special_branch_job:
rules:
- if: '$PIPELINE_TYPE == "merge_request"'
when: manual
- if: '$PIPELINE_TYPE == "special_branch" || $PIPELINE_TYPE == "tagged_build"'
when: always
.tagged_build_job:
rules:
- if: '$PIPELINE_TYPE == "merge_request" || $PIPELINE_TYPE == "special_branch"'
when: manual
- if: '$PIPELINE_TYPE == "tagged_build"'
when: always
Merge Request Job:
extends: .merge_request_job
script: /bin/true