我正在尝试在我的 .gitlab.yml
文件中设置条件,遵循此 documentation ,使用第 7 点(合取/析取),但我使用的语法一直被 gitlab yml 验证器拒绝。
应该发生的是,如果 VAR1
以“thing”结尾或存在 VAR2
(即不为空),则应从运行中排除该作业。
这是我的 YAML 文件的一个片段:
build:
except:
variables:
- $VAR1 =~ /thing$/ || $VAR2
script:
- echo "Hello"
每当我尝试验证此语法时,我都会收到以下消息:
我还尝试了以下(不成功)变体:
- $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:
block 引用>(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/