Allow CI `only`/`except` to be combined with `rules` when null
What does this MR do and why?
Per #215662 (closed), users would like to be able to override an extended job's only
/except
or rules
keyword with null. Currently, the problem is that the CI validator is giving a validation error that prevents only
/except
and rules
to be used together even if their values are nulled.
This MR implements the following:
- Updated the FE CI json schema so that you can set
rules
to null - Updated the relevant validation statement so that it only applies when
rules
is not null - Modified the
disallowed_keys
validator to ignore keys with null values
Note that a blank value or ~
is equivalent to the Yaml null
. In our examples below, we are explicitly setting the value as null
.
Screenshots or screen recordings
- Example config:
job-a:
rules:
- if: '$CI_MERGE_REQUEST_ID'
script: echo "foo"
job-b:
extends: job-a
rules: null
only:
refs:
- master
except:
refs:
- merge_requests
script: echo "bar"
-
Old Behaviour
- Shows error message
jobs:job-b config key may not be used with `rules`: only, except
-
rules: null
has an FE validation error
- Shows error message
-
New Behaviour
- No validation errors
How to set up and validate locally
- Test the following config examples in your Project's CI/CD editor.
- Config Example 1:
rules
combined with nullonly
/except
.base-job:
only:
refs:
- master
except:
variables:
- $CI_JOB_NAME != "" # Always true, so .base-job should never run
script: echo "base-job"
job1:
extends: .base-job
only: null
except: null
rules:
- if: $CI_JOB_NAME == ""
script: echo "job1"
job2:
extends: .base-job
only: null
except: null
rules:
- if: $CI_JOB_NAME == "job2"
script: echo "job2"
- Config Example 2:
only
/except
combined with nullrules
.base-job:
rules:
- if: $CI_JOB_NAME == "" # Always false, so .base-job should never run
script: echo "base-job"
job1:
extends: .base-job
rules: null
only:
refs:
- master
except:
variables:
- $CI_JOB_NAME != ""
script: echo "job1"
job2:
extends: .base-job
rules: null
only:
refs:
- master
except:
variables:
- $CI_JOB_NAME == ""
script: echo "job2"
- Observe that they do not produce validation errors.
- Commit the change (to run the pipeline) and see that only
job2
runs, which indicates the.base-job
'sonly
/except
/rules
values are nulled and the overidden values take effect. - Also observe that if you replace the
null
with a non-null value, then the validation error message displays 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 #215662 (closed)
Edited by Leaminn Ma