azure - 将输出保存到变量在 Azure-CLI DevOps 任务中不起作用
问题描述
尝试将 azure advisor 推荐的输出保存到变量中,以便我可以传递到下一个任务。
但是,无论我尝试什么语法,相信我已经尝试了所有可能的组合,变量都不会被保存。有趣的是,这些在 Cloud shell (bash) 中为 Eg 工作
rgName="$(az group list --query "[?tags.Test=='yes'].name" --output tsv)"
az group show -n $rgName
这在云壳中工作得很好。但不在 DevOps azurecli 任务中。我还提到了堆栈溢出本身给出的多个示例,但它们都不起作用。使用任务版本 1.*
rgName' is not recognised as an internal or external command,
有人可以举一个 DevOps Task 的工作示例吗?
注意:顺便说一句,我使用 cli 的全部原因是因为找不到 Advisor RM 模块,并且 Az 模块无法在任务版本 4 中正确加载。*
解决方案
As Shayki mentioned above, task.setvariable
can help with setting a variable from a script. The same has been detailed in this document. In a nutshell, you would have to do this:
rgName=$(az group list --query "[?tags.Test=='yes'].name" -o tsv | tr '\n' ' ')
echo "##vso[task.setvariable variable=RESULT]$rgName"
The task.setvariable
is a logging command and does not update the environment variables, but it does make the new variable available to downstream steps within the same job. Notice that the results are separated by CRLF and not spaces, and hence the trimming tr '\n' ' '
. Now, in the subsequent tasks where you need the variable, you may use it in this way:
echo "Result: $(RESULT)"
Refer to this blog to get a detailed walkthrough. Hope this helps!
推荐阅读
- r - 尝试在 R 中应用函数时,为什么我得到“二进制运算符的非数字参数”
- javascript - 从 gatsby 的 drupal 检索数据时连接超时
- c# - RDLC 报告查看器表达式返回 #ERROR 和 IIF 表达式
- javascript - javascript 日期对象是否与 python 日期时间对象兼容
- python - 在 python 中为 selenium 识别的搜索输入项元素的位置
- apache-kafka - Kafka - 哪个值将被视为最终值
- .net-core - 如何通过 dotnet fsi 使用服务器垃圾收集?
- javascript - 我的 POST 方法不起作用,而我的 GET 函数却是。我究竟做错了什么?
- consul - 如何使用 Consul DNS 向服务发送请求
- wso2-am - 使用 wso2 apictl 工具登录新环境时出错