由于默认情况下会传递来自所有先前阶段的工件,因此我们只需要以正确的顺序定义阶段。请尝试下面的示例,这可能有助于理解。
image: ubuntu:18.04
stages:
- build_stage
- test_stage
- deploy_stage
build:
stage: build_stage
script:
- echo "building..." >> ./build_result.txt
artifacts:
paths:
- build_result.txt
expire_in: 1 week
unit_test:
stage: test_stage
script:
- ls
- cat build_result.txt
- cp build_result.txt unittest_result.txt
- echo "unit testing..." >> ./unittest_result.txt
artifacts:
paths:
- unittest_result.txt
expire_in: 1 week
integration_test:
stage: test_stage
script:
- ls
- cat build_result.txt
- cp build_result.txt integration_test_result.txt
- echo "integration testing..." >> ./integration_test_result.txt
artifacts:
paths:
- integration_test_result.txt
expire_in: 1 week
deploy:
stage: deploy_stage
script:
- ls
- cat build_result.txt
- cat unittest_result.txt
- cat integration_test_result.txt
并且为了在不同阶段的作业之间传递工件,我们可以将依赖项与工件一起使用以传递工件,如文档中所述。
还有一个更简单的示例:
image: ubuntu:18.04
build:
stage: build
script:
- echo "building..." >> ./result.txt
artifacts:
paths:
- result.txt
expire_in: 1 week
unit_test:
stage: test
script:
- ls
- cat result.txt
- echo "unit testing..." >> ./result.txt
artifacts:
paths:
- result.txt
expire_in: 1 week
deploy:
stage: deploy
script:
- ls
- cat result.txt