Hello. I was wondering if someone can please confirm if my understanding of the conditional behaviour for scheduled jobs in GitLab is correct? My goal is to ensure that a newly created schedule for a particular job only triggers that specific job and does not affect any other jobs that are also tied to a schedule.
I basically have a new job I want to add to the .gitlab-ci.yml file that looks like this:
AMI Clean-up:
stage: ami_clean_up
script:
- python ami_clean_up.py
rules:
- if: '$CI_PIPELINE_SOURCE == "schedule" && $AMI_CLEANUP_SCHEDULE == "true"'
when: always
The thing is we have 2 other schedules defined within CI/CD > Schedules, and other jobs in the .gitlab-ci.yml file as well that use a schedule. For example, we have a nightly packer build schedule and a job that looks like this:
build-linux-image:
timeout: 1 hours
stage: build-images
script: ./build.sh linux centos7
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
- if: $image == "build-product-image"
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
- if: $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH
when: manual
needs:
- job: build-centos7
optional: true
retry: 1
What I am trying to understand is how to segregate my schedules and jobs from one another. For example, I don’t want the other two schedules that run every night to trigger my new AMI clean up job.
So, when I created my schedule I did this:
I created a variable in the schedule that has the key of AMI_CLEANUP_SCHEDULE and the value of true
I believe this will ensure that only this schedule is related to this job (as I have also defined $AMI_CLEANUP_SCHEDULE == “true”’ within my new job).
Because other jobs in the CI file that also use $CI_PIPELINE_SOURCE == “schedule” don’t have the AND condition of $AMI_CLEANUP_SCHEDULE == “true”', my new monthly schedule shouldn’t trigger those jobs, and the existing schedules which trigger the other jobs shouldn’t trigger my new job, because only my new schedule has the environment variable defined.
Sorry if I haven’t explained this very well. I’ve ran into this issue a couple of times now where I’ve needed to create a new schedule for a job, but I want to ensure I am understanding how I can ensure that a new schedule created for a particular job only triggers the job it was created for and nothing else.