Search code examples
continuous-integrationgitlabgitlab-cigitlab-ci-runner

Disable a given manual job for previous pipelines


I have this proof-of-concept (just displaying the relevant parts) in a GitLab CI pipeline:

deploy:development:
  stage: deploy
  rules:
    - if: $CI_COMMIT_BRANCH == "master"
  script: do_deploy
  variables:
    ANSIBLE_INVENTORY: development

deploy:test:
  stage: deploy
  environment:
    name: test
    url: https://env.url.tld
  rules:
    - if: $CI_COMMIT_BRANCH == "master"
      when: manual
  script: do_deploy
  variables:
    ANSIBLE_INVENTORY: test

I would like to disable/deprecate the previous deploy:test jobs when a new one is created. Basically, the deploy:test job should only be enabled for the current/latest pipeline, hence preventing an old build to take over a recent one.

I'm not saying that it should happens instantaneously; if it's running, is fine to let if finish, but if it failed and a new one is created, the old one (failed) should be disabled also. Same for the current one, if it ran successfully, it should be disabled — this is an optimal state.

Is there a configuration setting that will let me do that? I have checked Auto-cancel redundant, pending pipelines and Skip outdated deployment jobs in Settings > CI/CD > General pipelines, but still the job doesn't get disabled on previous pipelines.


Solution

  • I have checked Auto-cancel redundant, pending pipelines and Skip outdated deployment jobs in Settings > CI/CD > General pipelines, but still the job doesn't get disabled on previous pipelines.

    It should work better with GitLab 15.5 (October 2022):

    Prevent outdated deployment jobs

    Previously, some outdated jobs could be manually started or retried even when Skip outdated deployment jobs is enabled.

    We have updated the logic for this setting to check the deployment status when a job starts.

    The job does not execute if the deployment job is outdated due to a more recent deployment.
    This check ensures that outdated deployment jobs are not accidentally started, overwriting more recent code changes in production.

    See Documentation and Issue.