Amélioration de l'attente de connectivité SSH

This commit is contained in:
wpetit 2019-03-01 10:41:41 +01:00
parent c90b26695a
commit 5ef2c5bf95

View File

@ -4,6 +4,7 @@ import groovy.util.XmlSlurper
import groovy.util.slurpersupport.GPathResult
import groovy.util.slurpersupport.NodeChild
import groovy.xml.XmlUtil
import org.jenkinsci.plugins.workflow.steps.FlowInterruptedException
class Client {
@ -149,17 +150,16 @@ def runInNewVM(Map args) {
initWithCredentials(urlCredentialsId, userCredentialsId) { client ->
client.withNewVM(vmTemplate, terminateOnExit) { host ->
def sshArgs = "-i \'${VM_SSH_KEY}\' -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
def sshArgs = "-i '${VM_SSH_KEY}' -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
// On attend que la connexion SSH soit disponible
println "En attente de l'accès SSH..."
waitUntil {
try {
sh "ssh -q ${sshArgs} -o ConnectTimeout=1 root@${host} exit"
return true
} catch (e) {
return false
println "En attente de l'accès SSH sur la machine ${host}..."
while(true) {
def status = sh script: "nc -zv ${host} 22", returnStatus: true
if (status == 0) {
break;
}
sleep(5)
}
// On créait un script temporaire à exécuter sur la machine distante