[英]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.