I have a base job like this:
.parent_job
rules:
- if '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"'
But I want all the child jobs to also run on specific sets of file changes
child_job1
extends: .parent_job
rules:
- changes:
- file1
child_job2
extends: .parent_job
rules:
- changes:
- file2
Will the child jobs lose their rule about running on Merge Requests ?
I want to do this because I have a lot of jobs and limited slots, so I dont want them all running on every push to a branch. Will I need to define the merge request rule in every child?
The answer to this, from my own research, is that any rules in a child task override all rules in the parent (which makes sense, as rules have precedence order). The best I could come up with for this was to create a set of anchors to make the rules as readible as possible:
.rules job:
rules:
- if: &run_all_jobs '$RUN_ALL_JOBS != null'
- if: &merge_request '$CI_MERGE_REQUEST_ID != null'
job1:
rules:
- if: *run_all_jobs
changes: &job_file_list
- file1
- file2
- if: *merge_request
changes: *job_file_list
when: always
job2:
rules:
- if: *run_all_jobs
changes: &job_file_list
- file3
- file4
- if: *merge_request
changes: *job_file_list
when: always
1 Like