Amélioration de l'attente de connectivité SSH
This commit is contained in:
parent
c90b26695a
commit
5ef2c5bf95
|
@ -4,6 +4,7 @@ import groovy.util.XmlSlurper
|
||||||
import groovy.util.slurpersupport.GPathResult
|
import groovy.util.slurpersupport.GPathResult
|
||||||
import groovy.util.slurpersupport.NodeChild
|
import groovy.util.slurpersupport.NodeChild
|
||||||
import groovy.xml.XmlUtil
|
import groovy.xml.XmlUtil
|
||||||
|
import org.jenkinsci.plugins.workflow.steps.FlowInterruptedException
|
||||||
|
|
||||||
class Client {
|
class Client {
|
||||||
|
|
||||||
|
@ -149,17 +150,16 @@ def runInNewVM(Map args) {
|
||||||
initWithCredentials(urlCredentialsId, userCredentialsId) { client ->
|
initWithCredentials(urlCredentialsId, userCredentialsId) { client ->
|
||||||
client.withNewVM(vmTemplate, terminateOnExit) { host ->
|
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
|
// On attend que la connexion SSH soit disponible
|
||||||
println "En attente de l'accès SSH..."
|
println "En attente de l'accès SSH sur la machine ${host}..."
|
||||||
waitUntil {
|
while(true) {
|
||||||
try {
|
def status = sh script: "nc -zv ${host} 22", returnStatus: true
|
||||||
sh "ssh -q ${sshArgs} -o ConnectTimeout=1 root@${host} exit"
|
if (status == 0) {
|
||||||
return true
|
break;
|
||||||
} catch (e) {
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
sleep(5)
|
||||||
}
|
}
|
||||||
|
|
||||||
// On créait un script temporaire à exécuter sur la machine distante
|
// On créait un script temporaire à exécuter sur la machine distante
|
||||||
|
|
Loading…
Reference in New Issue