如果变量不等于null,则azure devops yaml运行步骤 - 如何在条件下引用yaml变量
如果数字变量具有值,我想在模板中运行此步骤。问题似乎是即使设置(如下面)变量,number似乎仍然是空的。我认为我需要另一种方法来引用此变量?我认为,如果我通过GUI设置变量,但似乎并没有从YAML捡起它,这将有效。有人知道吗?
yaml
stages:
- stage: Run
variables:
- name: number
value: '123'
jobs:
- job:
steps:
- template: .\run.yml
模板
- ${{if ne(variables.number, '')}}:
- powershell: Write-Host "Its working!"
I want to run this step in a template if the number variable has a value. Issue seems to be that even when set, like below, variables.number still seems to be empty. I think I need another way to reference this variable? I think this would work if I set the variable via the GUI but doesn't seem to pick it up from the YAML. Does anybody know?
YAML
stages:
- stage: Run
variables:
- name: number
value: '123'
jobs:
- job:
steps:
- template: .\run.yml
TEMPLATE
- ${{if ne(variables.number, '')}}:
- powershell: Write-Host "Its working!"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要这样使用:
从模板无法访问变量。
You need to use it like this:
Variables is not accessible from the template.
则需要注意单引号的等效性。
由于将比较值设置为空
''
,因此您的变量需要引用'variables.number'
,否则其条件始终为false :
我的测试YAML脚本:
child.yml:
它在我这边工作正常。
You need to pay attention to the equivalence of single quotes.
Since you set the comparison value to be empty
''
, then your variable needs to be quoted'variables.number'
, otherwise its condition is alwaysFalse
:My test YAML scripts:
child.yml:
It works fine on my side.