在声明变量yaml时,为什么我会遇到错误

发布于 2025-02-05 19:45:54 字数 518 浏览 4 评论 0 原文

我的代码在下面有效,

variables:
  - group: docker-settings

我需要添加一个在条件中使用的变量,因此我将变量插入下面的变量,但后来又有一个错误?如果我删除-group:docker -settings它可以工作,如果我删除了ismaster行,则它可以正常工作,但在那里不喜欢它们吗?我在做什么错?

variables:
  - group: docker-settings
  isMaster: $[eq(variables['Build.SourceBranch'], 'refs/heads

我用这些文档

I have the code as below which works fine

variables:
  - group: docker-settings

I need to add a variable to use in a condition so i insert the variable as below but then I get an error? If I remove -group :docker-settings it works, if I remove isMaster line instead it works but it doesnt like them both there? What am I doing wrong?

variables:
  - group: docker-settings
  isMaster: $[eq(variables['Build.SourceBranch'], 'refs/heads

I used these docs
https://learn.microsoft.com/en-us/azure/devops/pipelines/process/conditions?view=azure-devops&tabs=yaml

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

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

发布评论

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

评论(1

作妖 2025-02-12 19:45:54

我使用了 name/value 符号,并根据 ms示例和set master 而不是 main 。我想这就是您想要的。

variables:
  - group: docker-settings
  - name: 'isMaster'
    value: $[eq(variables['Build.SourceBranch'], 'refs/heads/master')]

Microsoft示例:

variables:
  staticVar: 'my value' # static variable
  compileVar: ${{ variables.staticVar }} # compile time expression
  isMain: $[eq(variables['Build.SourceBranch'], 'refs/heads/main')] # runtime expression

steps:
  - script: |
      echo ${{variables.staticVar}} # outputs my value
      echo $(compileVar) # outputs my value
      echo $(isMain) # outputs True

不要放弃yaml和azure devops; - )

I used the name / value notation and fixed the value based on the MS example and set master instead of main. I guess this is what you want to have.

variables:
  - group: docker-settings
  - name: 'isMaster'
    value: $[eq(variables['Build.SourceBranch'], 'refs/heads/master')]

Microsoft example:

variables:
  staticVar: 'my value' # static variable
  compileVar: ${{ variables.staticVar }} # compile time expression
  isMain: $[eq(variables['Build.SourceBranch'], 'refs/heads/main')] # runtime expression

steps:
  - script: |
      echo ${{variables.staticVar}} # outputs my value
      echo $(compileVar) # outputs my value
      echo $(isMain) # outputs True

Don't give up with yaml and Azure DevOps ;-)

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