Add support for CI_ENVIRONMENT_NAME to be used in job:rules
What does this MR do and why?
We noted in #35315 (closed) that customers would like the ability to use the variable CI_ENVIRONMENT_NAME
in job:rules. The purpose is to run a subset of jobs in a pipeline based on an environment name of their choosing.
Prior to this MR, we can only access most of the CI_ENVIRONMENT_*
variables after the build and environment creation. But we can make an exception for CI_ENVIRONMENT_NAME
as its value is easily accessible from the job's environment config. In this MR, we set its value earlier in the job cycle such that it is populated prior to the job's rules evaluation.
Documentation updated: Where variables can be used
Screenshots or screen recordings
Example config:
variables:
TARGET_ENV: "dev"
.base_job:
script: echo "Only run dev jobs - $CI_ENVIRONMENT_NAME, $CI_JOB_NAME"
rules:
- if: $CI_ENVIRONMENT_NAME == $TARGET_ENV
job1:
extends: .base_job
environment:
name: dev
url: "http://test.com"
job2:
extends: .base_job
environment: dev
job3:
extends: .base_job
environment:
name: test
-
We want
job1
andjob2
to run. -
Prior behaviour: The
CI_ENVIRONMENT_NAME
value is not set so no jobs run. -
New behaviour: The
CI_ENVIRONMENT_NAME
value is set sojob1
andjob2
run as expected.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #35315 (closed)