Joy Joy - 1 month ago 33
Groovy Question

Jenkins Pipeline script to check the website is up

In my Jenkins pipeline code, I am trying test if a web site is available or not.

withEnv([
"ipaddrs=$FINAL_IP",
"appuri=http://$FINAL_IP:8080"
]){
timeout(time: 15, unit: 'MINUTES') {
waitUntil {
try {

sh "curl -s --head --request GET $appuri/gameoflife | grep '200 OK'"
return true
} catch (Exception e) {
return false
}


But even though the website is up, Jenkins pipeline is not able to understand the same and it keep on run till 15 min and timeing out

I have manually ran curl from Jenkins node and I am able to get the response back when web site comes up. Any idea what could be the isssue?

Answer

Maybe it would work if you would use URL instead of shell?

try {         
    new URL("$appuri/gameoflife").getText()
    return true
} catch (Exception e) {
    return false
}