将curl jq的输出存储到Windows cmd中的环境变量

问题描述 投票:0回答:1

我想将

curl -X GET "http://localhost:8080/test" ^| jq -r ".integrations.[0].id"
的输出保存到Windows8中jenkins批处理命令中的环境变量中,以便我可以在后续命令中使用它。

如何做到这一点?

我尝试过但没有成功。

@echo off ^
for /F "delims=" %%i in ("curl -X GET "http://localhost:8080/test" ^| jq -r ".integrations.[0].id"") do (set "response=%%i") ^
echo ID = %response% ^
endlocal
jenkins curl cmd jq multiline
1个回答
0
投票

以下对我有用:

@echo off
for /f "usebackq delims=" %%i in (`echo xyz`) do (set response=%%i)
echo "ID = %response%"

我做的不同的事情:

  • 启用反引号选项
  • 将命令放在反引号内
  • 使用“echo“xyz”而不是通过管道将curl输入jq。
© www.soinside.com 2019 - 2024. All rights reserved.