I need configure my GitLab CI job like this:
- Only job with
$CI_PIPELINE_SOURCE == "merge_request_event"
is added to Pipeline, - Job is runned multipletimes by
matrix
for each version defined by matrixPHP_VERSION: [ '7.4', '8.0', '8.1' ]
. - The
'8.1'
must but runned withallow_failure: true
.
I tried to write rules intuitive as I except rules works, but I’m getting a different result.
I first tried this:
parallel:
matrix:
- PHP_VERSION: [ '7.4', '8.0', '8.1' ]
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
when: on_success
- if: '$PHP_VERSION == "8.1"'
allow_failure: true
It result only to MR event for PHP 8.1 us added to Pipeline.
My next iteration is still wrong:
parallel:
matrix:
- PHP_VERSION: [ '7.4', '8.0', '8.1' ]
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
when: on_success
- if: '$PHP_VERSION == "8.1"'
when: on_success
allow_failure: true
- when: on_success
This looks better, but it runs job for every other event (not only merge_request_event
).
How I can to right combine rules to get result as I declared above? 🙏
2
Answers
You could try
Based on https://docs.gitlab.com/ee/ci/jobs/job_control.html#run-a-matrix-of-parallel-trigger-jobs
Example of execution
If you want to run only on merge request, you have to invert the logic: