Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of "workflow:rules" in Gitlab-ci pipelines?

I am a bit confused between Gitlab CI pipeline workflow:rules and job:rules

workflow:
  rules:
    - if: '$CI_PIPELINE_SOURCE == "push"'
    - if: '$CI_PIPELINE_SOURCE != "schedule"'

and

test:
  stage: test
  image: image
  script:
    - echo "Hello world!"
  rules:
    - if: $CI_PIPELINE_SOURCE == "schedule"

What happens if both of them were used in the same GitLab-ci YAML file.

like image 342
zegoat7 Avatar asked Sep 02 '25 16:09

zegoat7


1 Answers

With workflow you configure when a pipeline is created while with rules you configure when a job is created.

So in your example pipelines are created for pushes but cannot be scheduled while your test job will only run when scheduled.

But as workflow rules take precedence over job rules, no pipeline will be created in your example as your rules for workflow and job are mutually exclusive.

like image 86
danielnelz Avatar answered Sep 06 '25 20:09

danielnelz