4

At the moment, I have a couple of CI/CD jobs configured in gitlab-ci.yaml within a pipeline. For instance, I have the build and deploy configured within one branch. One of the jobs is creating a backup.

I would like to schedule only the backup job every night. However, in the schedule section of GitLab CI/CD, I can only select a branch or a tag. This will result in all the stages/jobs to be triggered, whereas I only want the backup to be triggered.

I've seen the option to configure rules and excepts to only trigger the jobs in a certain context. That, however, feels a bit like a patch solution. Is there another way to trigger only a single job in the Gitlab CI/CD scheduler?

sjaakoil
  • 71
  • 3

1 Answers1

7

I've seen the option to configure rules and excepts to only trigger the jobs in a certain context. That, however, feels a bit like a patch solution. Is there another way to trigger only a single job in the Gitlab CI/CD scheduler?

No, there's no other way than using rules: or only:/except: to control which jobs run when the pipeline is triggered by a schedule.

You can make this more manageable by splitting your pipeline configuration to multiple files then using the appropriate rules: on the include:

include:
  - local: /do-backup.yml
    rules:
      - if: '$CI_PIPELINE_SOURCE == "schedule"'
  - local: /do-pipeline.yml
    rules:
      - if: '$CI_PIPELINE_SOURCE != "schedule"'

That way you don't have to necessarily apply the same rules: to every single job and you can define additional rules: per job with less conflict.

sytech
  • 29,298
  • 3
  • 45
  • 86