Dibyendu Jana
2020-02-27 33fc99134cf9441f64c8ad17eadc55b88e3fcee8
tests/jenkins/fuse-on-openshift.groovy
File was renamed from tests/jenkins/openshift-service-mesh-lab.groovy
@@ -8,7 +8,7 @@
def imap_creds = 'd8762f05-ca66-4364-adf2-bc3ce1dca16c'
def imap_server = 'imap.gmail.com'
// Notifications
def notification_email = 'gucore@redhat.com'
def notification_email = 'djana@redhat.com'
def rocketchat_hook = '5d28935e-f7ca-4b11-8b8e-d7a7161a013a'
// SSH key
@@ -20,20 +20,31 @@
// state variables
def guid=''
def openshift_location = ''
//def ssh_location = ''
//def ssh_p = ''
// Catalog items
def choices = [
    'OPENTLC OpenShift Labs / OpenShift Service Mesh Lab',
    'DevOps Team Development / DEV - OpenShift Service Mesh Lab',
    'OPENTLC Middleware Solutions Labs / Fuse on OpenShift',
    'Middleware Preprod / Fuse on OpenShift - Preprod',
    'Shared Cluster Development / DEV Fuse on OpenShift',
].join("\n")
def region_choice = [
    'na_sandboxes_gpte',
    'apac_sandboxes_gpte',
    'emea_sandboxes_gpte',
    'na',
    'emea',
    'latam',
    'apac',
].join("\n")
def nodes_choice = [
    '3',
    '1',
    '2',
    '4',
    '5',
    '6',
    '7',
    '8',
].join("\n")
pipeline {
@@ -59,6 +70,11 @@
            description: 'Region',
            name: 'region',
        )
        choice(
            choices: nodes_choice,
            description: 'Number of Nodes',
            name: 'nodes',
        )
    }
    stages {
@@ -77,6 +93,7 @@
                    def catalog = params.catalog_item.split(' / ')[0].trim()
                    def item = params.catalog_item.split(' / ')[1].trim()
                    def region = params.region.trim()
                    def nodes = params.nodes.trim()
                    echo "'${catalog}' '${item}'"
                    guid = sh(
                        returnStdout: true,
@@ -85,7 +102,7 @@
                          -c '${catalog}' \
                          -i '${item}' \
                          -G '${cf_group}' \
                          -d 'expiration=6,runtime=8,region=${region}'
                          -d 'check=t,expiration=7,runtime=8,quotacheck=t,region=${region},nodes=${nodes}'
                        """
                    ).trim()
@@ -93,6 +110,7 @@
                }
            }
        }
        /* Skip this step because sometimes the completed email arrives
         before the 'has started' email */
        stage('Wait for first email') {
@@ -127,49 +145,25 @@
                          ./tests/jenkins/downstream/poll_email.py \
                          --server '${imap_server}' \
                          --guid ${guid} \
                          --timeout 100 \
                          --timeout 150 \
                          --filter 'has completed'
                        """
                    ).trim()
                    try {
                       def m = email =~ /Openshift Master Console: (.*)/
                       openshift_location = m[0][1]
                       echo "Openshift Master Console: ${openshift_location}"
//                  m = email =~ /This cluster has authentication enabled. (.*)/
//                  echo "Cluster authentication:  ${m[0][1]}"
//                       m = email =~ /SSH Access: (.*)/
//                  ssh_location = m[0][1]
//                  echo "SSH Access: ${ssh_location}"
//                  m = email =~ /SSH password: (.*)/
//                  ssh_p =​ m[0][1]
//                  echo "SSH password: ${ssh_p}"
                       def m = email =~ /Connect to the shared cluster by pointing your web browser to <a href="(.*)"/
                        openshift_location = m[0]
                        echo "openshift_location = ${openshift_location}"
                    } catch(Exception ex) {
                        echo "Could not parse email:"
                        echo email
                        echo ex.toString()
                        throw ex
                    }
                }
            }
        }
//        stage('SSH') {
//            steps {
//                withCredentials([
//                    sshUserPrivateKey(
//                        credentialsId: ssh_creds,
//                        keyFileVariable: 'ssh_key',
//                        usernameVariable: 'ssh_username')
//                ]) {
//                    sh "ssh -o StrictHostKeyChecking=no -i ${ssh_key} ${ssh_location} w"
//                    sh "ssh -o StrictHostKeyChecking=no -i ${ssh_key} ${ssh_location} oc version"
//                }
//            }
//        }
        stage('Confirm before retiring') {
            when {
@@ -251,6 +245,21 @@
                """
            }
            /* Print ansible logs */
            withCredentials([
                string(credentialsId: ssh_admin_host, variable: 'ssh_admin'),
                sshUserPrivateKey(
                    credentialsId: ssh_creds,
                    keyFileVariable: 'ssh_key',
                    usernameVariable: 'ssh_username')
            ]) {
                sh("""
                    ssh -o StrictHostKeyChecking=no -i ${ssh_key} ${ssh_admin} \
                    "find deployer_logs -name '*${guid}*log' | xargs cat"
                """.trim()
                )
            }
            withCredentials([usernameColonPassword(credentialsId: imap_creds, variable: 'credentials')]) {
                mail(
                    subject: "${env.JOB_NAME} (${env.BUILD_NUMBER}) failed GUID=${guid}",