Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gitlab CI/CD: Schedule only for a particular job and exclude it from the pipeline

Consider I have the following .gitlab-ci.yml, and they are running fine in Pipeline:

image: 

stages:
  - job1
  - job2
  - job3
       
job1:
  dependencies: []
  stage: job1      
  script:

job2:
  dependencies: []
  stage: job2     
  script:

job3:
  dependencies: []
  stage: job3    
  script:
 

Now, what I would like to achieve is:

  • to exclude job3 from the Pipeline
  • and to create a schedule only for this job3

I have read option to configure schedule, using rules, so I edit the job3 as follow:

job3:
  dependencies: []
  stage: job3
  rules:
    - if: $CI_PIPELINE_SOURCE == "schedule"
  script:

And I setup a schedule. But unfortunately, it doesn't work out: job3 is still part of the Pipeline, and my schedule runs all the jobs.

What is missing in this configuration? Or is it possible to achieve it.

like image 663
Ragnarsson Avatar asked Oct 14 '25 15:10

Ragnarsson


1 Answers

define rules for every job:

job1:
  dependencies: []
  stage: job1  
  rules:  
    - if: '$CI_PIPELINE_SOURCE != "schedule"'
      when: always
  script:

job2:
  dependencies: []
  stage: job2  
  rules:  
    - if: '$CI_PIPELINE_SOURCE != "schedule"'
      when: always  
  script:

job3:
  dependencies: []
  stage: job3
  rules:
    - if: '$CI_PIPELINE_SOURCE == "schedule"'
      when: always
  script:
like image 192
ericfossas Avatar answered Oct 17 '25 06:10

ericfossas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!