Scheduled pipeline does not work as expected

Hello Everybody :slightly_smiling_face:,

I have a pipeline that includes some rules, normal jobs and a triggered job. The problem is just about the triggered job. It basically runs with a cron and a variable and I expect that when the trigger runs, to run only the specific stage. But it does not stop and continue to run other jobs.

Problem to solve

As I have just mentioned the problem, the trigger does not run the specified job, but runs all the jobs.

Steps to reproduce

To reproduce the problem, you need to configure the .gitlab-ci.yml and add a schedule in UI.

The ci configuration:

stages:
  - merge

scheduled_job:
  stage: merge
  image: docker:24.0.6
  services:
    - docker:dind
  before_script:
    - apk add --no-cache git curl
    - git config user.name "username"
    - git config user.email "email"
  script:
    - git fetch
    - git checkout master
    - 'git merge --no-ff --no-commit origin/development || { 
        echo "CONFLICTS DETECTED !!! CREATING MERGE REQUEST..."; 
        git merge --abort; 
        CONFLICTS=$(git ls-files -u | wc -l); 
        if [ $CONFLICTS -gt 0 ]; then 
          echo "ABORTING MERGE !!!"; 
          exit 1; 
        fi; 
        curl --request POST --header "PRIVATE-TOKEN: $PERSONAL_ACCESS_TOKEN" --header "Content-Type: application/json" --data "{\"source_branch\": \"development\", \"target_branch\": \"master\", \"title\": \"MERGE development INTO master ( SCHEDULED JOB ))\", \"remove_source_branch\": false}" "https://<gitlab-host>/api/v4/projects/<project-id>/merge_requests"; 
        exit 1; 
      }'
    - git commit -m "MERGE development INTO master"
    - git push https://gitlab-ci-token:$PERSONAL_ACCESS_TOKEN@<gitlab-host/<group-name>/<project-name>.git master
    - echo "MERGE SUCCESSFUL"
  rules:
    - if: '$CI_PIPELINE_SOURCE == "schedule" && $SCHEDULED == "TRUE"'
  tags:
    - docker

The schedule settings:

Configuration

  • git should be configured correctly with a valid username and an email address.
  • $PERSONAL_ACCESS_TOKEN should be created in project, and should has specific permissions : api, read_api, read_repository, write_repository

Versions

  • [ x ] Self-managed
  • [ x ] Self-hosted Runners
- GitLab v16.11.1
- GitLab Shell 14.35.0
- GitLab Workhorse v16.11.1
- GitLab API v4
- GitLab KAS 16.11.1
- Ruby 3.1.4p223
- Rails 7.0.8.1
- PostgreSQL (main) 14.11
- PostgreSQL (ci) 14.11
- Redis  7.0.15 

Thanks for everything! :blush:

I’ve fixed the problem by adding a rule to all other jobs in my pipeline, so schedule triggers only one job now.

rules:
 - if: '$SCHEDULED != "TRUE"'

Reference: https://docs.gitlab.com/ee/ci/jobs/job_rules.html#run-jobs-only-in-specific-pipeline-types