我在某些Gitlab CI作业中遇到问题,我在其中指定了仅在file exists时才运行的规则。
这是我的.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
我只想在unit_tests
文件夹中的文件夹下有*UnitTests.dll
时运行test/
,而当integration_tests
中的文件夹中有*IntegrationTests.dll
时,我才想运行test/
exists
文件夹。
问题是两个作业都被完全忽略。换句话说,Gitlab似乎正在将rules
评估为假,就好像它只是在管道的开始而不是在作业的开始进行评估一样,但是存在这些路径是因为它们是在上一阶段生成的,并且工件是自动可用的。
如果我删除unit_tests
,则integration_tests
将成功运行,但exists
将失败,因为在我的特定项目中没有集成测试。
我尝试将changes
替换为exists
,这是同样的问题。
如何实现有条件的作业执行?
更新1 :我有一个丑陋的解决方法,但问题仍然存在,因为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
。
q = Question.objects.prefetch_related( 'questionquiz_set')
答案 0 :(得分:1)
在撰写本文时,GitLab 似乎不支持在规则中使用工件文件。 This issue confirms 它不起作用。
我自己的解决方法是删除条件规则,而是编写一个包装脚本,首先检查文件是否存在。