有条件地插入变量模板时意外的符号'contains'



我看不懂这个。任何帮助都是感激的。这快把我逼疯了,不知道我做错了什么。

我已经尝试用'eq'和'startsWith'替换'contains',但由于某种原因,它一直告诉我这是一个意想不到的符号。

完全错误:

(Line: 33, Col: 3):意外符号:'contains'。位于表达式中的位置8:elseif包含变量['Build. if ']。SourceBranch '],"用户")

resources:
repositories:
- repository: WebAppComponents
ref: main
endpoint: RepoAccess
type: git
name: Project/WebAppComponents.git
- repository: test-data
ref: main
endpoint: RepoAccess
type: git
name: Project/test-data.git

variables:
- template: Variables/default.yml
- ${{ if contains(variables['resources.repositories.WebAppComponents.ref'], 'user') }}:
- template: Variables/dev.yml
- ${{ elseif contains(variables['Build.SourceBranch'], 'user') }}:
- template: Variables/dev.yml
- ${{ else }}:
- template: Variables/main.yml

我也遇到过同样的问题。

我不知道为什么会出现这种情况,但是进一步缩进elseifelse条件似乎可以解决这个问题。

试试这个

variables:
- template: Variables/default.yml
- ${{ if contains(variables['resources.repositories.WebAppComponents.ref'], 'user') }}:
- template: Variables/dev.yml
- ${{ elseif contains(variables['Build.SourceBranch'], 'user') }}:
- template: Variables/dev.yml
- ${{ else }}:
- template: Variables/main.yml

最新更新