Karthikeyan M
Karthikeyan M

Reputation: 33

Migrate from only to rules

With only being deprecated, I need help in migrating the only to rules in the below .gitlab-ci.yml.

    pull_share:
        stage: config
        script:
            - git --work-tree=/Users/Shared/repo --git-dir=/Users/Shared/repo/.git pull origin main
        only:
            - triggers
            - schedules

Upvotes: 1

Views: 29

Answers (1)

Chris Doyle
Chris Doyle

Reputation: 12190

Gitlab Docs are pretty good at giving examples and common use cases. For rules:if they have https://archives.docs.gitlab.com/15.11/ee/ci/jobs/job_control.html#common-if-clauses-for-rules

For behavior similar to the only/except keywords, you can check the value of the $CI_PIPELINE_SOURCE

So in your case it would be

    pull_share:
        stage: config
        script:
            - git --work-tree=/Users/Shared/repo --git-dir=/Users/Shared/repo/.git pull origin main
        rules:
          - if: $CI_PIPELINE_SOURCE == "schedule"
          - if: $CI_PIPELINE_SOURCE == "trigger"

Upvotes: 2

Related Questions