我在处理某些 Gitlab CI 作业时遇到问题,在这些作业中我指定了仅在文件存在时才运行的规则。
这是我的.gitlab-ci.yml:
stages:
- build
- test
#Jobs
build:
stage: build
script:
- dotnet restore --no-cache --force
- dotnet build --configuration Release --no-restore
artifacts:
paths:
- test/
expire_in: 1 week
unit_tests:
stage: test
script: dotnet vstest test/*UnitTests/bin/Release/**/*UnitTests.dll --Blame
rules:
- exists:
- test/*UnitTests/bin/Release/**/*UnitTests.dll
integration_tests:
stage: test
script: dotnet vstest test/*IntegrationTests/bin/Release/**/*IntegrationTests.dll --Blame
rules:
- exists:
- test/*IntegrationTests/bin/Release/**/*IntegrationTests.dll
Run Code Online (Sandbox Code Playgroud)
unit_tests我只想当文件夹*UnitTests.dll中的 bin 下有test/且integration_tests仅当文件夹*IntegrationTests.dll中的 bin 下也有时运行test/。
问题是这两项工作都被完全忽略了。换句话说,Gitlab 似乎将 评估exists为 false ,就好像它仅在管道开始时而不是在作业开始时评估一样,但这些路径存在,因为它们是在前一阶段生成的,并且工件是自动可用。
如果我删除它将rules成功unit_tests运行但integration_tests会失败,因为在我的特定项目中没有集成测试。
我试过用 替换exists,changes同样的问题。
我怎样才能实现这个有条件的作业执行?
更新 1:我有一个丑陋的解决方法,但问题仍然存在,因为exists似乎是在管道开始时而不是在工作开始时进行评估,因此,有关工件的任何内容都会被忽略。
这个技巧之所以有效,是因为我总是假设,如果有的话,构建阶段的结果csproj就会有一个。dll
stages:
- build
- test
build:
stage: build
script:
- dotnet restore --no-cache --force
- dotnet build --configuration Release --no-restore
artifacts:
paths:
- test/
expire_in: 1 week
unit_tests:
stage: test
script: dotnet vstest test/*UnitTests/bin/Release/**/*UnitTests.dll --Blame
rules:
- exists:
- test/*UnitTests/*UnitTests.csproj
integration_tests:
stage: test
script: dotnet vstest test/*IntegrationTests/bin/Release/**/*IntegrationTests.dll --Blame
rules:
- exists:
- test/*IntegrationTests/*IntegrationTests.csproj
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4228 次 |
| 最近记录: |