Make Jenkins pipeline wait until server is up

They just released a new version of the Pipeline Nodes and Processes Plugin which adds support for returning the exit status. This seems to do the job now:

timeout(5) {
    waitUntil {
       script {
         def r = sh script: 'wget -q http://remoterhoste/welcome.jsf -O /dev/null', returnStdout: true
         return (r == 0);
       }
    }
}

You can use wget options to achieve that:

waitUntil {
    sh 'wget --retry-connrefused --tries=120 --waitretry=1 -q http://server:8080/app/welcome.jsf -O /dev/null'
}

120 tries, plus wait 1s between retries, retry even in case of connection refused, this might be slightly more seconds. So to make sure it is only 120s, then you can use timeout from shell:

waitUntil {
    sh 'timeout 120 wget --retry-connrefused --tries=120 --waitretry=1 -q http://server:8080/app/welcome.jsf -O /dev/null'
}

If you don't have wget on the jenkins node (e.g. the default docker image) you can also install and use the HTTPRequest Plugin like this.

timeout(5) {
    waitUntil {
        script {
            try {
                def response = httpRequest 'http://server:8080/app/welcome.jsf'
                return (response.status == 200)
            }
            catch (exception) {
                 return false
            }
        }
    }
}