在 VSTS 上的 Azure CLI 任务中设置输出变量 [英] Set Output Variable in Azure CLI task on VSTS

查看:26
本文介绍了在 VSTS 上的 Azure CLI 任务中设置输出变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了完成这个非常简单的任务,我快疯了.我需要在 Visual Studio Team Services 的 Azure CLI 任务中设置输出变量,因为发布定义中的下一个任务将根据该变量的值执行.
我写了这个简单的代码

I am getting crazy to achieve this very simple task. I need to set an Output Variable in an Azure CLI task on Visual Studio Team Services, because next task in the Release definition will be executed according to the value of this variable.
I wrote this simple code

call az extension add --name azure-cli-iot-ext
call echo ##vso[task.setvariable variable=iotEdgeExists;]$(az iot hub query -n $(iotHub) -q "select * from devices.modules where devices.deviceId ='$(iotEdge)'")

这有效,但没有预期的那样,事实上,当我在下一个 Azure CLI 任务中读取输出变量并尝试将其打印在屏幕上时,我得到的是命令字符串而不是输出...

which works, but not as exepected, in fact when I read the Ouput Variable in the next Azure CLI task and I try to print it on the screen I get the command string instead of the output...

call echo"$(az iot hub query -n <IOT_HUB> -q "select * from devices.modules where devices.deviceId ='<IOT_EDGE>'")"

我做错了什么?

推荐答案

参考以下代码:

call {your command}>tmpFile1
set /p myvar= < tmpFile1 
echo "##vso[task.setvariable variable=testvar;]%myvar%"

FOR /F "tokens=* USEBACKQ" %%F IN (`{your command}`) DO (
SET var=%%F
)
echo "##vso[task.setvariable variable=testvar;]%var%"

Mechaflash 在 如何回答将命令输出设置为批处理文件中的变量

Mechaflash's answer in How to set commands output as a variable in a batch file

这篇关于在 VSTS 上的 Azure CLI 任务中设置输出变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆