user4695271
user4695271

Reputation:

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.

Upvotes: 2

Views: 1386

Answers (2)

VonC
VonC

Reputation: 1323373

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.

Upvotes: 1

sur.la.route
sur.la.route

Reputation: 530

Did you try adding the "interruptible" tag?

enter image description here

It seems like you have to add interruptible: true to your yaml.

For example:

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

Ref: https://gitlab.com/gitlab-org/gitlab/-/issues/32022

Upvotes: 1

Related Questions