[英]Azure DevOps conditional can't evaluate Powershell set-variable
I have a powershell script, which is not in a job, task, or stage, it's on its own.我有一个 powershell 脚本,它不在工作、任务或阶段,它是独立的。 running in my DevOps build yaml like this:在我的 DevOps 构建 yaml 中运行,如下所示:
- powershell: |
if (//something that's irrelevant) {
Write-Host "##vso[task.setvariable variable=myCustomVar;isOutput=true]true"
} else {
Write-Host "##vso[task.setvariable variable=myCustomVar;isOutput=true]false"
}
After this powershell script, I have another script to echo out myCustomVar to see what the value is.在这个 powershell 脚本之后,我有另一个脚本来回显 myCustomVar 以查看值是什么。 Like this:像这样:
- script: |
echo "What is my custom variable?"
echo $(myCustomVar)
When the build runs, in the devops logs, it echos literally "$(myCustomVar)" and not either True/False当构建运行时,在 devops 日志中,它会逐字地回显“$(myCustomVar)”,而不是 True/False
After that, I have a task which sends an email, but we only want to send an email if myCustomVar
is true.之后,我有一个发送 email 的任务,但如果myCustomVar
为真,我们只想发送 email。 So I use a conditional.所以我使用条件。
- task: SendEmail@1
displayName: "Send email"
condition: and(succeeded(), eq(variables.myCustomVar, true))
however, this is breaking.然而,这是打破。 I've tried a few other ways of doing it.我已经尝试了其他几种方法。 myCustomVar
, on the task condition, always returns NULL. myCustomVar
,在任务条件下,总是返回 NULL。 Any help on syntax?语法上有什么帮助吗?
You could use ##vso[task.setvariable]value
to set variables from a script in pipeline.您可以使用##vso[task.setvariable]value
从管道中的脚本设置变量。 The first task can set a variable, and following tasks are able to use the variable.第一个任务可以设置一个变量,后面的任务可以使用这个变量。 The variable is exposed to the following tasks as an environment variable.该变量作为环境变量公开给以下任务。
Check following useful links:检查以下有用的链接:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.