【发布时间】:2020-03-16 13:21:10
【问题描述】:
我正在使用下面的Jenkinsfile。它在使用jq 命令执行时正在打印upload_id 的值,但是在打印该值时它显示null。
请帮我解决这个变量问题。
sh label: '', script: 'upload_id=$(cat output_file.json | jq -r \'.upload_id\')'
sh "echo \"$upload_id\""**
输出:
[管道] sh 猫输出文件.json jq -r .upload_id upload_id=8f304c6d-804b-440a-xxxx** [管道] sh 回声上传ID:空 upload_id:空
[管道]}
【问题讨论】:
-
它显示带有 jq 参数的上传 ID,但在打印值时显示 null 输出:[管道] sh + cat output_file.json + jq -r .upload_id + upload_id=8f304c6d-804b-440a -8db3-xxxx [管道] sh + echo upload_id : null upload_id : null [管道] }
-
您能否根据您的建议建议我如何使用上述两个命令。 1. sh 标签:'',脚本:'upload_id=$(cat output_file.json | jq -r \'.upload_id\')' 2. sh "echo \"$upload_id\""**
-
在您的情况下,my answer 的“返回单个字符串”部分将适用。
-
这里,我使用的是流水线脚本。像 pipeline{ stage { stage() { steps{ sh label: '', script: 'upload_id=$(cat output_file.json | jq -r \'.upload_id\')' sh "echo \"$upload_id 一样编写此代码\"}}}。你能建议我如何在这里使用来获取 user_id 的值。输出:[Pipeline] sh cat output_file.json jq -r .upload_id upload_id=8f304c6d-804b-440a-xxxx** [Pipeline ] sh echo upload_id : null upload_id : null [管道] }
标签: shell variables jenkins-pipeline jq