Can I schedule only one specific GitLab CI/CD job?
Asked Answered
K

1

9

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?

Kist answered 11/4, 2022 at 18:26 Comment(0)
D
11

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.

Declarative answered 11/4, 2022 at 18:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.