我想驗證一個tomcat中的所有Web應用程序在執行Jenkins管道後運行。Jenkins管道循環意外終止
我正在驗證多個網址,所以我想在for循環中這樣做。 它以集合中的第一個url結尾。
這裏是我的代碼
@NonCPS
def verifyServices(list) {
echo "Services: "+list.size()
def result = true
for(int i = 0; i < list.size(); i++){
if(result) {
result = testUrl(list[i])
}
}
return result
}
def verify = []
verify.add("http://example.com:8082")
verify.add("http://example.com:8082/rest/version")
verify.add("http://example.com:8082/mobile/version")
verifyServices(verify)
而且testUrl功能
def call(urlString) {
echo "Testing ${urlString}"
def url = new URL(urlString)
def HttpURLConnection connection = url.openConnection()
connection.setRequestMethod("GET")
connection.setDoInput(true)
try {
connection.connect()
def code = connection.getResponseCode()
echo "Response code ${code}"
return code == 200
} finally {
connection.disconnect()
}
}
這是我的日誌
Proceeding
[Pipeline] echo
Services: 3
[Pipeline] echo
Testing http://example.com:8082
[Pipeline] echo
Response code 200
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
當我刪除調用testUrl
功能verifyServices
它遍歷所有的他們。
我做錯了什麼?或者for循環被破壞了?
For循環不壞 –
太好了。那麼我做錯了什麼?當我使用一個函數(或者只是sh裏面的「echo test」for循環時,它會停止迭代... –
假設的'testUrl'函數叫做'call'?你確定這個調用不會出現異常,或者爲什麼有一個_finally_塊? –