我想将GitLab CI与.gitlab-ci.yml文件一起使用,以使用单独的脚本运行不同的阶段.第一阶段生成一个工具,必须在稍后阶段用于执行测试.我已将生成的工具声明为工件.
现在我如何在后期工作中执行该工具?什么是正确的路径,它周围会有什么文件?
例如,第一阶段构建工件/ bin/TestTool/TestTool.exe,该目录包含其他所需文件(DLL和其他).我的.gitlab-ci.yml文件如下所示:
releasebuild:
script:
- chcp 65001
- build.cmd
stage: build
artifacts:
paths:
- artifacts/bin/TestTool/
systemtests:
script:
- chcp 65001
- WHAT TO WRITE HERE?
stage: test
Run Code Online (Sandbox Code Playgroud)
如果相关,则在Windows上运行构建和测试.
use*_*793 80
你必须使用 dependencies
使用此配置测试阶段将下载在构建阶段创建的未跟踪文件:
build:
stage: build
artifacts:
untracked: true
script:
- ./Build.ps1
test:
stage: test
dependencies:
- build
script:
- ./Test.ps1
Run Code Online (Sandbox Code Playgroud)
Chu*_*uan 15
Since artifacts from all previous stages are passed by default, we just need to define stages in correct order. Please try the example below, which could help understanding.
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
Run Code Online (Sandbox Code Playgroud)
And in case to pass artifacts between jobs in different stages, we can use dependencies together with artifacts to pass the artifacts, as described from the document.
And one more simpler example:
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
Run Code Online (Sandbox Code Playgroud)
k1e*_*ran 12
如果您希望foo/
在下一阶段可用并且它在您的中,.gitignore
您需要将其列在artifacts
创建它的阶段中,或者按照此处的说明使用untracked: true
。因为我只想要一个子集,所以我没有\xe2\x80\x99t 使用untracked: true
.
以下方法对我有用(dependencies
在下一阶段没有指定)
artifacts:\n paths:\n - foo/\n expire_in: 1 hour\n
Run Code Online (Sandbox Code Playgroud)\n顺便说一句,关于:expire_in: 1 hour
部分: \n我在https://gitlab.com/gitlab-org/gitlab-runner/-/issues/2133
上读到,没有办法让工件在管道结束时自动过期,并且默认保留期长得惊人(默认为 30 天) - 因此需要基于时间的拼凑来摆脱它们 - 请参阅https://docs.gitlab.com/ee/ci/yaml/
如果您使用该needs:
关键字,默认工件管理行为会发生变化。唯一可用的工件来自需求图上的“上游”作业。另外,dependencies:
关键字不能与关键字一起使用needs:
。
要解决问题中的管道片段,needs
只需向创建所需工件的作业添加关系即可:
releasebuild:
script:
- chcp 65001
- build.cmd
stage: build
artifacts:
paths:
- artifacts/bin/TestTool/
systemtests:
script:
- chcp 65001
stage: test
needs:
- job: releasebuild
artifacts: true
Run Code Online (Sandbox Code Playgroud)
注意:该needs:artifacts:
关键字默认为true
并且可以省略。当设置为 时false
,作业将不会加载上游工件。
归档时间: |
|
查看次数: |
47137 次 |
最近记录: |