Combine only:schedules AND rules

Hi,

we start our nightly build by creating a ‘schedule’ in CI/CD => Schedules, configure them with cron pattern, some variables etc. Within our .gitlab-ci.yml we configure some jobs with only: schedules in order to start such a job ONLY if it was started by the scheduler OR if we manually click the play button.
Now, only becomes deprecated and we should use the new rules keyword. We define some rules in order to decide, which deployment we start for the given scheduled task. we use

deploy-1-nightly:
    stage: deploy
    rules:
        - if: '$PROFILE == "1-nightly"'
          when: always

deploy-2-nightly:
    stage: deploy
    rules:
        - if: '$PROFILE == "2-nightly"'
          when: always

But both jobs are now executed on each build, not only for those scheduled builds !
How can we combine the new rules with the previously uses only:schedules in order to start such a job on scheduled (or clicked play button) only ?

kind regards
Dominik

Problem solved: The deploy jobs are started because the scheduler declares variables named PROFILE which is used for the if statement, but the jobs also contains variable declaration of the same name PROFILE. Just renamed the variables declared by the job solved the problem.

1 Like
    - if: $CI_PIPELINE_SOURCE == "schedule"
      when: never
4 Likes

Kudos +1