4

I would like to run one or multiple jobs within a scheduled context and therefore used the specific rule to declare it like this. Problem is that the pipeline will neither be triggered by my schedule configuration nor when i manually trigger it via the scheduling pipeline UI. I just don't see any triggered scheduled pipeline at all.

Gitlab Version: 12.9.2

gitlab-ci.yml (partially):

workflow:
rules:
    -   if: $CI_COMMIT_TAG
    -   if: $CI_COMMIT_BRANCH

non-scheduled-job:
...
rules:
    -   if: '$CI_PIPELINE_SOURCE != "schedule"'


scheduled-job:
...
rules:
    -   if: '$CI_PIPELINE_SOURCE == "schedule"'
        when: always
    -   if: '$CI_PIPELINE_SOURCE != "schedule"'
        when: never

I know that the second rule for the scheduling-job is not needed but even without this the pipeline is not properly running.

1

2 Answers 2

6

Unfortunately, as for Workflows logic, Gitlab is very twiggy. If you use Workflow section and Rules conditions for your jobs, you have to obviously declare 'Scheduled' type of pipeline in the Workflow section to enable it in your configuration:

workflow:                                                 
    rules:
      - if: '$CI_PIPELINE_SOURCE == "schedule"'
      ...

Or you may enable all types of pipelines in your configuration just adding at the end of workflow:rules

workflow:                                                 
  rules:
    ...
    - when: always

In other way, use may use except/only notation for scheduled jobs and it will work, but only if your workflow conditions met:

only:
  - schedules

This approach may appear merging conflicts if you use include option. Because merging lets you extend and override dictionary mappings, but you cannot add or modify items to an included array. Thus you have to obviously declare all previously added workflow:rules array items in the last included YAML or use anchors.

See issue for details.

Sign up to request clarification or add additional context in comments.

Comments

-3

You can use only.

E.g.

scheduled-job:
  only:
    - schedules

https://docs.gitlab.com/ee/ci/pipelines/schedules.html

But, when reusing the snippet in other jobs, do not use rules togetther with only / except.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.