Bug 1903: Better SSH check
[osm/devops.git] / jenkins / ci-pipelines / ci_stage_3.groovy
index 83671d1..c203313 100644 (file)
@@ -418,10 +418,16 @@ node("${params.NODE}") {
                     println("Waiting for VM at ${IP_ADDRESS} to be reachable")
 
                     alive = false
-                    while (!alive) {
-                        output = sh(returnStdout: true, script: "sleep 1 ; nc -zv ${IP_ADDRESS} 22 2>&1 || true").trim()
-                        println("output is [$output]")
-                        alive = output.contains('succeeded')
+                    timeout(time: 1, unit: 'MINUTES') {
+                        while (!alive) {
+                            output = sh(
+                                returnStatus: true,
+                                script: "ssh -T -i ${SSH_KEY} " +
+                                    "-o StrictHostKeyChecking=no " +
+                                    "-o UserKnownHostsFile=/dev/null " +
+                                    "-o ConnectTimeout=5 ubuntu@${IP_ADDRESS} 'echo Alive'")
+                            alive = (output == 0)
+                        }
                     }
                     println('VM is ready and accepting ssh connections')
                 } // stage("Spawn Remote VM")
@@ -453,15 +459,15 @@ node("${params.NODE}") {
                         repo_base_url = "-u http://${NODE_IP_ADDRESS}:${repo_port}"
                     }
 
-                    remote.with {
-                        name = containerName
-                        host = IP_ADDRESS
-                        user = 'ubuntu'
-                        identityFile = SSH_KEY
-                        allowAnyHosts = true
-                        logLevel = 'INFO'
-                        pty = true
-                    }
+                    remote = [
+                        name: containerName,
+                        host: IP_ADDRESS,
+                        user: 'ubuntu',
+                        identityFile: SSH_KEY,
+                        allowAnyHosts: true,
+                        logLevel: 'INFO',
+                        pty: true
+                    ]
 
                     // Force time sync to avoid clock drift and invalid certificates
                     sshCommand remote: remote, command: '''
@@ -605,10 +611,10 @@ EOF"""
                         stage('Publish to Dockerhub') {
                             parallelSteps = [:]
                             for (buildStep in containerList) {
-                                module = buildStep
-                                moduleName = buildStep.toLowerCase()
-                                dockerTag = params.DOCKER_TAG
-                                moduleTag = containerName
+                                def module = buildStep
+                                def moduleName = buildStep.toLowerCase()
+                                def dockerTag = params.DOCKER_TAG
+                                def moduleTag = containerName
 
                                 parallelSteps[module] = {
                                     dir("$module") {