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

发布于 2025-01-28 07:17:25 字数 823 浏览 4 评论 0原文

我无法弄清楚这个。任何帮助都将受到赞赏。这让我发疯,不确定我在做什么错。

我尝试用“ eq”和“ startswith”代替“包含”,但由于某种原因,它一直告诉我它是一个意外的象征。

确切的错误:(

线:33,col:3):意外符号:“包含”。位于表达式中的位置8:elseif包含(变量['build.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

I can't figure this one out. Any help is appreciated. This is driving me nuts, not sure what I am doing wrong.

I have tried replacing 'contains' with 'eq' and 'startsWith' but for some reason it keeps telling me its an unexpected symbol.

Exact error:

(Line: 33, Col: 3): Unexpected symbol: 'contains'. Located at position 8 within expression: elseif contains(variables['Build.SourceBranch'], 'user')

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乖乖 2025-02-04 07:17:25

我遇到了完全相同的问题。

我不确定为什么是这种情况,但是缩进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

I came across the exact same issue.

I am not sure why this is the case, but indenting elseif and else conditions further in seems to solve the issue.

Try this

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文