[英]Jenkins get status of last build with a specific parameter
我有一个 Jenkins 自由式作业(是的,我知道..),如果它正在运行(或者如果它失败,则根本不运行),有时需要等待另一个具有相同参数的作业才能完成。
使用curl
和 Jenkins API,是否可以查询某个作业并获取上一个 build 的状态,其中certainParam=certainValue
?
(我问如何用 curl 做到这一点的原因是因为它似乎不可能在自由式工作中完成,而且这项工作还不能迁移到 pipeilnes 。似乎 curl 将是东方的方式..)
提前谢谢!
到目前为止,我知道没有直接的方法可以实现它。
我编写了递归脚本,从最后一个版本开始搜索每个构建的值,直到匹配信息。
它打印每个构建 url 和查询结果。
依赖项
脚本
#!/bin/bash
user="admin"
pwd="11966e4dd8c33a730abf88e98fb952ebc3"
builds=$(curl -s --user $user:$pwd localhost:8080/job/test/api/json)
urls=$(echo $builds | jq '.builds[] | .url')
while read -r url
do
url=$(echo $url | sed -nr 's/"([^|]*)"/\1/p')
# get the build log
build=$(curl -s --user $user:$pwd "${url}api/json")
# transform the log in a simple structure
build=$(echo $build | jq '.result as $result | .actions[].parameters[]? | select(.name == "certainParam") | {(.name): .value, "result": $result}')
# check if the parameter value and the build result are the expected
result=$(echo $build | jq 'if .certainParam == "certainValue" and .result == "SUCCESS" then true else false end')
# print the result of each build
echo "url=${url}api/json;result=$result"
if [[ $result == true ]]
then
break
fi
done <<< $urls
结果
sh jenkins.sh
url=http://localhost:8080/job/test/12/api/json;result=false
url=http://localhost:8080/job/test/11/api/json;result=true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.