azure - Azure DevOps 条件无法评估 Powershell 设置变量
问题描述
我有一个 powershell 脚本,它不在工作、任务或阶段,它是独立的。像这样在我的 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"
}
在这个 powershell 脚本之后,我有另一个脚本来回显 myCustomVar 以查看值是什么。像这样:
- script: |
echo "What is my custom variable?"
echo $(myCustomVar)
当构建运行时,在 devops 日志中,它会逐字地回显“$(myCustomVar)”,而不是 True/False
myCustomVar
之后,我有一个发送电子邮件的任务,但如果是真的,我们只想发送一封电子邮件。所以我使用条件。
- task: SendEmail@1
displayName: "Send email"
condition: and(succeeded(), eq(variables.myCustomVar, true))
然而,这是打破。我已经尝试了其他几种方法。myCustomVar
,在任务条件下,始终返回 NULL。语法上有什么帮助吗?
解决方案
您可以使用##vso[task.setvariable]value
从管道中的脚本设置变量。第一个任务可以设置一个变量,后面的任务可以使用这个变量。该变量作为环境变量公开给以下任务。
检查以下有用的链接:
推荐阅读
- html - 带有 PDF 嵌入的 IFrame 在 Chrome 中工作,但在 IE11 中不工作
- android - 如何使用 QR 码捕获 pdf 表单字段?
- http - File upload : who is responsible for setting HTTP headers
- r - 在 data.table 中拆分和连接字符串
- wordpress - 从 Wordpress 迁移到 Shopify 后如何重定向(或带回)/services/ 页面?
- compression - 为什么 Zipalign 无法正常处理 .pvr 文件?
- r - 按另一个数据框的行名称对列进行子集化
- spring-boot - GKE: How to handle deployments with CPU intensive initialization?
- postgresql - 如何强制查询仅从窗口返回第一行?
- python-3.x - 使用python将包含micros的excel表转换为pdf