我正在尝试使用 Gitlab CI 在管道阶段构建 C 代码,并在下一个阶段执行它。
问题是执行测试阶段没有找到二进制文件 我不想在每个阶段都进行重建,以便在管道期间使用更少的 CPU,所以我认为缓存应该是可行的方法。
这是我的 .gitlab-ci.yml 文件:
stages:
- build
- test
- deploy
job:build:
stage: build
before_script:
- pwd
script:
- mkdir bin/
- gcc -o bin/main.exe *.c
cache:
key: build-cache
paths:
- bin/
after_script:
- ls -R
job:test:unit:
stage: test
script: echo 'unit tests'
job:test:functional:
stage: test
before_script:
- pwd
- ls -R
script:
- echo 'functional test'
- cd bin ; ./main.exe
job:deploy:
stage: deploy
script: echo 'Deploy stage'
所以我发现我必须使用工件。
这是我的代码:
stages:
- build
- test
- deploy
job:build:
stage: build
before_script:
- pwd
script:
- mkdir bin/
- gcc -o bin/main.exe *.c
artifacts:
expire_in: 1 day
paths:
- bin/main.exe
after_script:
- ls -R
job:test:unit:
stage: test
script: echo 'unit tests'
job:test:functional:
stage: test
before_script:
- pwd
- ls -R
script:
- echo 'functional test'
- cd bin ; ./main.exe
dependencies:
- job:build
job:deploy:
stage: deploy
script: echo 'Deploy stage'