Gitlab“存在”规则不考虑工件

ibe*_*dev 5 gitlab gitlab-ci

我在处理某些 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会失败,因为在我的特定项目中没有集成测试。

我试过用 替换existschanges同样的问题。

我怎样才能实现这个有条件的作业执行?


更新 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)

Joe*_*Joe 5

在撰写本文时,GitLab 似乎不支持在规则中使用工件文件。这个问题证实它不起作用。

我自己的解决方法是删除条件规则,而是编写一个包装器脚本,首先检查文件是否存在。