How can I add only run a pipeline job after a specific date?

Problem to solve

As part of our CI pipelines, code is scanned via SonarQube which is hosted in a different team. It is running on LTS releases and only sees upgrades every 18 months or so.

We encountered a missing feature which causes the SonarQube job to fail. This is fixed in an upcoming release which has already been scheduled. It only happens in some projects (detectable by an “exists” rule in the project)

I want to disable the job for now, but I also want it to re-activate automatically when the time is right. As “pseudocode” I was thinking of a rule like this:

  - if: "current_timestamp() < 1735686000"
    #        ^--- This doesn't exist
    when: never
  - exists:
      - pyproject.toml
    when: on_success

However, I don’t see an easy way to implement the first rule. The CI_JOB_STARTED_AT CI variable has the necessary information, but only as ISO-formatted time-string. And, as far as I can tell, this make comparison in the if clause impossible.

I’m contemplating in adding this to an env-variable using the “dotenv-report” from a previous stage. But before going down that route, I would prefer to know if there’s a cleaner solution.


Please select whether options apply, and add the version information.

  • Self-managed
  • SaaS
  • Self-hosted Runners


  • GitLab (Web: /help or self-managed system information): I have no access to this information
  • GitLab Runner, if self-hosted (Web /admin/runners or CLI gitlab-runner --version): I have no access to this information

YAML can only do string comparison with == and =~, which won’t allow you to test if a string is “less than” another.

Instead you can use unix date in a job which tests if the CI_JOB_STARTED_AT is after the due-date for the LTS release:

        - CI_JOB_STARTED_AT_TS=$(date -d "$CI_JOB_STARTED_AT" +%s)
        - test $CI_JOB_STARTED_AT_TS -gt 1735686000

      - exists:
          - pyproject.toml
        - lts_ready
        - echo "do the sonar scan"

There are two jobs:

  • lts_ready converts the $CI_JOB_STARTED_AT into a Unix timestamp using date -d. It then compares this with your due-date. If the date is before the due date, the test fails
  • sonar-job is the job which must only run after the due date. It needs: lts_ready.

Doing it this way with needs avoids having to make any changes to the pipeline’s existing CI stages.

Alternatively, you could combine these two jobs’ scripts into a single job which tests before doing the scan:

        - exists:
            - pyproject.toml
        - |
            CI_JOB_STARTED_AT_TS=$(date -d "$CI_JOB_STARTED_AT" +%s)
            test $CI_JOB_STARTED_AT_TS -lt 1735686000 && exit
            echo "do the sonar scan"

Your choice on which approach to use would depend upon what makes more sense to your pipeline. Consider that in the first example, lts_ready will fail until the due date, and in the second example, the sonar-job always runs but exits successfully without scanning, until after the due date.

For both examples, it may be better to use a custom CI variable so that you can update the next relrease date in 2025 (or test it with a manual run - step 5) without editing the CI configuration:

        - test $CI_JOB_STARTED_AT_TS -gt $LTS_RELEASE_TS


        test $CI_JOB_STARTED_AT_TS -lt $LTS_RELEASE_TS && exit