Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gitlab schedule jobs with `rules` are not running and can't be triggered

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.

like image 572
dom Avatar asked Sep 05 '25 03:09

dom


1 Answers

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.

like image 88
Cyrus Matsumori Avatar answered Sep 08 '25 22:09

Cyrus Matsumori