'Gitlab: Removing specific scheduled jobs from scheduled pipelines

I have following jobs and stages and with this yml configuration the test stage runs on schedule and regular pipelines when I set $RUN_JOB variable to true in my schedule and in my project's CI/CD variables. But this also schedules scheduled-test-1 and scheduled-test-2 in my scheduled pipelines.

What I want to do is that the test stage should continue to run on schedule and regular pipelines but scheduled-test-1 and scheduled-test-2 should not be scheduled with test stage.

stages:
  build
  test
  deploy
  scheduled-test-1
  scheduled-test-2

build:
  script:
  - echo $Service_Version
  only:
  - develop
  except:
  - schedules

test:
  script:
  - echo $Service_Version
  only:
    variables:
    - $RUN_JOB

deploy:
  script:
  - echo $Service_Version
  only:
  - develop
  except:
  - schedules

scheduled-test-1:
  script:
  - echo $Service_Version
  only:
  - schedules

scheduled-test-2:
  script:
  - echo $Service_Version
  only:
  - schedules


Solution 1:[1]

There might be a simpler option but, using artifacts:reports as in Exporting environment variables from one stage to the next in GitLab CI might help.

The idea would be to export a RUN_TEST environment variable (a flag to signal the test job has been executed), and use it in the scheduled-test-x jobs in a rules section:

rules:
    - if: $RUN_TEST != ""

While those scheduled-test-x jobs might still be scheduled, at least they would not run, but their rule would be false.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 VonC