我在 GitLab CI 管道中进行了这个概念验证(仅显示相关部分):
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
我想在创建新作业时禁用/弃用之前的 deploy:test
作业。基本上,deploy:test
作业应该只针对当前/最新的管道启用,从而防止旧的构建接管最近的构建。
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.
是否有配置设置可以让我这样做?我已在设置 > CI/CD > 常规管道
中检查了自动取消冗余、挂起的管道和跳过过时的部署作业,但仍然是作业不会在以前的管道上被禁用。
最佳答案
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.
它应该与 GitLab 15.5 配合使用效果更好(2022 年 10 月):
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.
关于continuous-integration - 禁用先前管道的给定手 Action 业,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62939079/