我有一個 Jenkins 作業(腳本化管道),它在“sh”塊中有 curl 請求。這是對 Github 組織的 API 呼叫,我需要將它用于該組織中的一些存盤庫(大約 15 個)。我可以創建 15 行 curl 請求,但我想知道是否可以將存盤庫作為陣列傳遞并添加一個回圈。像這樣的東西:
def REPOS = ['repo1', 'repo2'] sh """ curl -d "mydata" -X POST 'www.website/api/{REPOS}' """
但是考慮到我有 Groovy sh curl,我不明白如何使它與陣列和回圈一起使用
uj5u.com熱心網友回復:
這對你有用。
steps {
script {
def repos = ['repo1', 'repo2']
repos.each() {
sh """
echo $it
echo "CURl here for ${it}"
curl -d "mydata" -X POST 'https://www.website/api/${it}'
"""
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/488091.html
下一篇:如何呼叫存盤在陣列中的函式
