Gitlab 管道应该在管道故障时停止
Gitlab pipeline should stop on pipeline failure
我在 gitlab 中有一个示例管道。如果任何作业失败,我希望管道停止。下面是我用来复制场景的代码。管道确实将失败显示为状态,但即使在失败的阶段之后,作业仍会继续 运行。附图中的示例。
stages:
- unittest
- coverage_test
- static_code_analysis
variables:
skip_integration:
value: 'false'
description: "This variable for skipping integration tests"
skip_migration:
value: 'false'
unittest:
stage: unittest
script:
- echo "testing the code"
rules:
- if: '$CI_COMMIT_BRANCH == "master"'
when: always
- if: '$skip_integration == "true"'
when: never
- if: '$skip_integration == "false"'
when: always
lint_test:
stage: static_code_analysis
allow_failure: false
script:
- echo "this is a test"
rules:
- if: '$CI_COMMIT_BRANCH == "master"'
when: always
- if: '$skip_integration == "true"'
when: never
- if: '$skip_integration == "false"'
when: always
- when: on_success
coverage_test:
stage: coverage_test
script:
- echo00 "this is test again"
rules:
- if: '$CI_COMMIT_BRANCH == "master"'
when: always
- if: '$skip_integration == "true"'
when: never
- if: '$skip_integration == "false"'
when: always
- when: on_success
但是管道不会在失败时停止。
when: always
顾名思义,运行工作总是。如果你想在前一阶段成功时 运行 作业,运行 它 on_success
。将所有 always
更改为 on_success
.
when: on_success
我已经成功地使用 needs
完成了那些应该只 运行 如果以前的工作成功的工作。
lint_test:
stage: static_code_analysis
allow_failure: false
script:
- echo "this is a test"
needs:
- coverage_test
rules:
- if: '$CI_COMMIT_BRANCH == "master"'
when: always
- if: '$skip_integration == "true"'
when: never
- if: '$skip_integration == "false"'
when: always
- when: on_success
stages:
- unittest
- coverage_test
- static_code_analysis
variables:
skip_integration:
value: 'false'
description: "This variable for skipping integration tests"
skip_migration:
value: 'false'
unittest:
stage: unittest
script:
- echo "testing the code"
rules:
- if: '$CI_COMMIT_BRANCH == "master"'
when: always
- if: '$skip_integration == "true"'
when: never
- if: '$skip_integration == "false"'
when: always
lint_test:
stage: static_code_analysis
allow_failure: false
script:
- echo "this is a test"
rules:
- if: '$CI_COMMIT_BRANCH == "master"'
when: always
- if: '$skip_integration == "true"'
when: never
- if: '$skip_integration == "false"'
when: always
- when: on_success
coverage_test:
stage: coverage_test
script:
- echo00 "this is test again"
rules:
- if: '$CI_COMMIT_BRANCH == "master"'
when: always
- if: '$skip_integration == "true"'
when: never
- if: '$skip_integration == "false"'
when: always
- when: on_success
但是管道不会在失败时停止。
when: always
顾名思义,运行工作总是。如果你想在前一阶段成功时 运行 作业,运行 它 on_success
。将所有 always
更改为 on_success
.
when: on_success
我已经成功地使用 needs
完成了那些应该只 运行 如果以前的工作成功的工作。
lint_test:
stage: static_code_analysis
allow_failure: false
script:
- echo "this is a test"
needs:
- coverage_test
rules:
- if: '$CI_COMMIT_BRANCH == "master"'
when: always
- if: '$skip_integration == "true"'
when: never
- if: '$skip_integration == "false"'
when: always
- when: on_success