Jenkins 管道循环意外结束
Jenkins Pipeline loop ends unexpectedly
我正在尝试验证一个 tomcat 中的所有 Web 应用程序在执行 Jenkins 管道后是否 运行。
我正在验证多个 url 所以我想在 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
当我删除 verifyServices
中对 testUrl
函数的调用时,它会遍历所有函数。
我是不是做错了什么?或者 for 循环刚刚被破坏?
@NonCPS
注释以某种方式干扰了您的方法调用。删除它,你会没事的。另外我不认为你首先需要它,你的代码似乎没有引入任何可序列化的问题 @NonCPS
注释会修复...
您可以在 CPS technical design or tutorial recommendations on how to serializable variables 上阅读更多内容。
我正在尝试验证一个 tomcat 中的所有 Web 应用程序在执行 Jenkins 管道后是否 运行。
我正在验证多个 url 所以我想在 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
当我删除 verifyServices
中对 testUrl
函数的调用时,它会遍历所有函数。
我是不是做错了什么?或者 for 循环刚刚被破坏?
@NonCPS
注释以某种方式干扰了您的方法调用。删除它,你会没事的。另外我不认为你首先需要它,你的代码似乎没有引入任何可序列化的问题 @NonCPS
注释会修复...
您可以在 CPS technical design or tutorial recommendations on how to serializable variables 上阅读更多内容。