gitlab - 当提供看似有效的 YAML 时,Gitlab 中的连接逻辑失败

标签 gitlab yaml gitlab-ci

我正在尝试在我的 .gitlab.yml 文件中设置条件,遵循此 documentation ,使用第 7 点(合取/析取),但我使用的语法一直被 gitlab yml 验证器拒绝。

应该发生的是,如果 VAR1 以“thing”结尾或存在 VAR2(即不为空),则应从运行中排除该作业。

这是我的 YAML 文件的一个片段:

build:
  except:
    variables: 
      - $VAR1 =~ /thing$/ || $VAR2
  script:
      - echo "Hello"

每当我尝试验证此语法时,我都会收到以下消息:

Failing Validation

我还尝试了以下(不成功)变体:

  - $VAR1 =~ /thing$/ || $VAR2 != null
  - $VAR1 =~ /thing$/ && $VAR2 != null (this was just testing an AND condition)

每当我单独列出条件时,它们都会通过验证。

我的语法有什么问题吗?有没有不同的方法来实现我想要的验证?对我来说这感觉就像一个错误。

最佳答案

文档提到:

If you use multiple keys under only or except, they act as an AND. The logic is:

(any of refs) AND (any of variables) AND (any of changes) AND (if kubernetes is active)

这使得它看起来像 any of variables表示列出的每个变量的或,因此这应该满足您的要求:

build:
  except:
    variables: 
      - $VAR1 =~ /thing$/ 
      - $VAR2 != null

关于gitlab - 当提供看似有效的 YAML 时,Gitlab 中的连接逻辑失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56589201/

相关文章:

node.js - 术语 'CI=false' 未被识别为 cmdlet、函数、脚本文件或可运行程序的名称

gitlab - 更改gitlab markdown美人鱼图大小

gitlab - 无法 GIT : Error setting certificate verify locations

docker - 如何在Gitlab中删除功能分支?在Docker中运行的标准gitlab-ce镜像

c++ - 我需要帮助为 C++ 设置 .gitlab-ci.yml 文件

java - SpringBoot 和 GitLab CI 运行测试

linux - 直接从 GitLab 私有(private)仓库打开文件

git - 来自 bash 的 YAML 解析器

ruby-on-rails - ActiveRecord 使用 JSON 而不是 YAML 进行序列化

character-encoding - 如何在Yaml文件中设置字符编码