gpt4 book ai didi

gitlab - 只有在 ref 或可变条件下才能执行 GitLab runner 作业

转载 作者:行者123 更新时间:2023-12-01 23:07:27 25 4
gpt4 key购买 nike

如果变量 COVERAGE_TEST 等于 ON ,我希望 CI 仅在主、合并请求、计划管道 上执行此作业:

c++TestCoverage:
stage: analysis
script: "./ciScripts/testCoverageScript.sh"
tags:
- framework
dependencies:
- c++Build
variables:
GIT_STRATEGY: fetch
artifacts:
paths:
- ./build/test_coverage/
expire_in: 1 week
when: on_success

我尝试添加下一行:

only:
refs:
- master
- merge_requests
- schedule
variables:
- $COVERAGE_TEST == "ON"

但结果实际上是 -> If ((Master || MergeRequest || ScheduledPipeline) && COVERAGE_TEST == ON)

我也试过:

only:
variables:
- $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"
- $CI_PIPELINE_SOURCE == 'merge_request_event'
- $CI_PIPELINE_SOURCE == 'schedule'
- $COVERAGE_TEST == "TRUE"

但是 CI_PIPELINE_SOURCE == 'merge_request_event' 不能像我想要的那样工作,因为如果我在合并请求中有分支并且我推送了一些更改,那么 CI_PIPELINE_SOURCE 的值是 push
有没有办法做到这一点?

最佳答案

您需要使用 rulesif keywords 来测试所有变量值并在测试之间放置 OR。

在您的情况下正确的配置应该是:

  rules:
- if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master" || $CI_PIPELINE_SOURCE == "merge_request_event" || $CI_PIPELINE_SOURCE == "schedule" || $COVERAGE_TEST == "TRUE"'
when: always

关于gitlab - 只有在 ref 或可变条件下才能执行 GitLab runner 作业,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60726655/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com