I have a daily and a weekly schedule pipeline and depending on which one runs I want to select the jobs included.
So I’m doing the following:
workflow:
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_PIPELINE_SOURCE == "schedule"
.template_daily:
stage: test
rules:
- if: '$CI_PIPELINE_SOURCE == "schedule" && $CI_SCHED_FREQ == "daily"'
before_script:
- echo "This is the before_script of the .template_daily job"
.template_weekly:
stage: test
rules:
- if: '$CI_PIPELINE_SOURCE == "schedule" && $CI_SCHED_FREQ == "weekly"'
before_script:
- echo "This is the before_script of the .template_weekly job"
test:daily:
extends: .template_daily
script:
- echo "Run on $CI_SCHED_FREQ schedule"
test:weekly:
extends: .template_weekly
script:
- echo "Run on $CI_SCHED_FREQ schedule"
test:any:
script:
- echo "Run on merge_request_event and schedule"
The CI_SCHED_FREQ is a variable set by the schedule pipeline
I expect that test:daily will run together with test:any on the daily schedule, while the test:weekly will run with test:any on a weekly schedule. On merge requests only test:any should be able to run, since the $CI_SCHED_FREQ
is not set.
None of the test:daily or test:weekly is run, only the test:any is run.
I’ve tried changing the rules, removing the templates and sticking the rules in the jobs directly, played with and without quotes around the entire rule expression, none of that worked.
I was trying to use the documentation here:
and specifically this instructions:
job:
script: echo "This job does NOT create double pipelines!"
rules:
- if: '$CUSTOM_VARIABLE == "true" && $CI_PIPELINE_SOURCE == "merge_request_event"'
the logic should be exactly the same, but for some reason the job does not start.
Maybe an important detail, I’m running on 14.10 self-managed.
What am I doing wrong?
EDIT: the original sin was in the schedule pipeline configuration where the variable was set to “daily” with the quotes, while it should have been without the quotes. Unclear why the quotes caused so much troubles, apparently their usage is not entirely clear in the documentation, or maybe I missed that part.