Gitlab Ci Schedule Task for Specific Jobs

Gitlab Ci Schedule Task for Specific Jobs

I have several jobs that are set to be triggered only for scheduled tasks. Some job requires to run every hour and other is set to run every day.

How do I set the job to run on schedule and also on specific schedule tasks/definitions? I know GitLab CI has an option to set rules for jobs to run on schedule but I could find an option to set a specific schedule given that I have many scheduled tasks.

For example:

job:
  script: echo "Hello, Rules!"
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
      when: manual
      allow_failure: true
    - if: $CI_PIPELINE_SOURCE == "schedule"

The rule - if: $CI_PIPELINE_SOURCE == "schedule" is very generic. I don't want some job to run every hour. I want it to pick the schedule that is set to run every day only for example

1 Answer

You can add a new schedule with a variable and change gitlab-ci.yml . For example:

job:
  script: echo "Hello, Rules!"
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
      when: manual
      allow_failure: true
    - if: $CI_PIPELINE_SOURCE == "schedule" && $SCHEDULE_TIMING == "hourly"

and add new schedule with variable

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Sophia Al-Mansoor
Author

Sophia Al-Mansoor

Sophia analyzes international trade, startup ecosystems, retail transformation, and supply chain logistics for modern digital publications.