Feature 10982: adapt Jenkinsfile for public clouds to work with ETSI Jenkins 42/14042/2
authoraguilard <e.dah.tid@telefonica.com>
Fri, 17 Nov 2023 07:53:43 +0000 (07:53 +0000)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Mon, 20 Nov 2023 10:37:08 +0000 (12:37 +0200)
Change-Id: Ia8c47d3bfdcac69d6547a5eae1788acf5f9d3ab1
Signed-off-by: aguilard <e.dah.tid@telefonica.com>
jenkins/public-clouds-tests/Jenkinsfile

index 9fe0435..d5f55a6 100644 (file)
@@ -16,7 +16,6 @@
  */
 
 pipeline {
-    agent none
     parameters {
         // string(defaultValue: 'artifactory-osm', description: '', name: 'ARTIFACTORY_SERVER')
 
@@ -36,8 +35,6 @@ pipeline {
         string(defaultValue: '', description: 'Jenkins credential containing SSH public key used in VMs', name: 'SSH_PUBLIC_KEY')
 
         // Parameter to set the target environment
-        // string(defaultValue: 'azure-etsi-environment', description: 'Defines the VIM target', name: 'VIM_TARGET_ENVIRONMENT')
-        // string(defaultValue: 'azure/azure.rc', description: 'Cloud config environment file', name: 'CLOUD_ENV_FILE')
         // Parameter to set the name of secret in Jenkins for Azure JSON credentials
         string(defaultValue: 'azure-credentials', description: 'Jenkins secret that contains Azure JSON credentials', name: 'AZURE_CREDENTIALS')
         // File format (take care of brackets in clientId):
@@ -107,114 +104,112 @@ pipeline {
         OSM_VIM_MULTIPLIER_TIMEOUT = '4.0'
     */
     }
+    agent {
+        docker {
+            label 'osm4'
+            image "${params.TEST_IMAGE}:${params.TEST_TAG}"
+            args "-u root:root --entrypoint=''"
+        }
+    }
     stages {
-        stage('E2E TESTS') {
-            agent {
-                docker {
-                    image "${params.TEST_IMAGE}:${params.TEST_TAG}"
-                    args "-u root:root --entrypoint=''"
-                }
-            }
-            stages {
-                stage('Set environment') {
-                    steps {
-                        script {
-                            if (params.SSH_PUBLIC_KEY == '') {
-                                // Gererate SSH private and public keys
-                                sh "mkdir -m 700 ~/.ssh"
-                                sh "ssh-keygen -t rsa -f ~/.ssh/id_rsa -N ''"
-                            }
-                            else {
-                                // SSH private and public keys from Jenkins credentials
-                                sh "mkdir -m 700 ~/.ssh"
-                                withCredentials([file(credentialsId: "${params.SSH_PRIVATE_KEY}", variable: 'SSHPATH')]) {
-                                    sh "cp ${SSHPATH} ~/.ssh/id_rsa"
-                                }
-                                withCredentials([file(credentialsId: "${params.SSH_PUBLIC_KEY}", variable: 'SSHPATH')]) {
-                                    sh "cp ${SSHPATH} ~/.ssh/id_rsa.pub"
-                                }
-                                sh "chmod 400 ~/.ssh/id_rsa ~/.ssh/id_rsa.pub"
-                            }
-                            // This file is used by some Robot test (BASIC12)
-                            sh "cp ~/.ssh/id_rsa ~/osm_id_rsa"
+        stage('Set environment') {
+            steps {
+                script {
+                    if (params.SSH_PUBLIC_KEY == '') {
+                        // Gererate SSH private and public keys
+                        sh "mkdir -m 700 ~/.ssh"
+                        sh "ssh-keygen -t rsa -f ~/.ssh/id_rsa -N ''"
+                    }
+                    else {
+                        // SSH private and public keys from Jenkins credentials
+                        sh "mkdir -m 700 ~/.ssh"
+                        withCredentials([file(credentialsId: "${params.SSH_PRIVATE_KEY}", variable: 'SSHPATH')]) {
+                            sh "cp ${SSHPATH} ~/.ssh/id_rsa"
                         }
-                        // Azure credentials
-                        withCredentials([file(credentialsId: "${params.AZURE_CREDENTIALS}", variable: 'PATH')]) {
-                            sh "cp ${PATH} ~/azure-creds.json"
-                            sh """
-                            set +x; \
-                            AZURE_CLIENT_ID=\$(cat ~/azure-creds.json | jq -r .clientId  | sed s/[{}]//g) ; \
-                            AZURE_SECRET=\$(cat ~/azure-creds.json | jq -r .clientSecret) ; \
-                            AZURE_TENANT=\$(cat ~/azure-creds.json | jq -r .tenantId) ; \
-                            az login --service-principal --username \$AZURE_CLIENT_ID --password \$AZURE_SECRET --tenant \$AZURE_TENANT
-                            """
-                            sh "az vm list -o table"
+                        withCredentials([file(credentialsId: "${params.SSH_PUBLIC_KEY}", variable: 'SSHPATH')]) {
+                            sh "cp ${SSHPATH} ~/.ssh/id_rsa.pub"
                         }
+                        sh "chmod 400 ~/.ssh/id_rsa ~/.ssh/id_rsa.pub"
                     }
+                    // This file is used by some Robot test (BASIC12)
+                    sh "cp ~/.ssh/id_rsa ~/osm_id_rsa"
+                    sh "echo Reading credential ${params.AZURE_CREDENTIALS}"
                 }
-                stage('Create k8s cluster') {
-                    steps {
-                        sh "/robot-systest/cloud-scripts/create-k8s.sh"
-                        sh "cat /robot-systest/results/k8s_environment.rc"
-                    }
-                }
-                stage('Install OSM') {
-                    steps {
-                        sh "/robot-systest/cloud-scripts/create-osm-vm.sh"
-                        sh "cat /robot-systest/results/osm_environment.rc"
-                        sh ". /robot-systest/results/osm_environment.rc ; /robot-systest/cloud-scripts/remote-install-osm.sh"
-                    }
-                }
-                stage('Add VIM and K8s cluster to OSM') {
-                    steps {
-                        sh """
-                            . /robot-systest/results/osm_environment.rc ; \
-                            . /robot-systest/results/k8s_environment.rc ; \
-                            osm version ; \
-                            set +x; \
-                            export AZURE_CLIENT_ID=\$(cat ~/azure-creds.json | jq -r .clientId  | sed s/[{}]//g) ; \
-                            export AZURE_SECRET=\$(cat ~/azure-creds.json | jq -r .clientSecret) ; \
-                            export AZURE_TENANT=\$(cat ~/azure-creds.json | jq -r .tenantId) ; \
-                            export AZURE_SUBSCRIPTION_ID=\$(cat ~/azure-creds.json | jq -r .subscriptionId) ; \
-                            /robot-systest/cloud-scripts/add-vim-and-k8scluster.sh
-                            """
-                    }
-
-                }
-                stage('Run Robot tests') {
-                    steps {
-                        sh """
-                            . /robot-systest/results/osm_environment.rc ; \
-                            . /robot-systest/results/k8s_environment.rc ; \
-                            /robot-systest/run_test.sh -t ${params.ROBOT_RUN_TAG}
-                            """
-                    }
+                // Azure credentials
+                withCredentials([file(credentialsId: "${params.AZURE_CREDENTIALS}", variable: 'FILE')]) {
+                    sh "cp ${FILE} ~/azure-creds.json"
+                    sh """
+                    set +x; \
+                    AZURE_CLIENT_ID=\$(cat ~/azure-creds.json | jq -r .clientId  | sed s/[{}]//g) ; \
+                    AZURE_SECRET=\$(cat ~/azure-creds.json | jq -r .clientSecret) ; \
+                    AZURE_TENANT=\$(cat ~/azure-creds.json | jq -r .tenantId) ; \
+                    az login --service-principal --username \$AZURE_CLIENT_ID --password \$AZURE_SECRET --tenant \$AZURE_TENANT
+                    """
+                    sh "az vm list -o table"
                 }
             }
-            post {
-                always {
-                    echo "Retrieve container logs"
-                    sh """
+        }
+        stage('Create k8s cluster') {
+            steps {
+                sh "/robot-systest/cloud-scripts/create-k8s.sh"
+                sh "cat /robot-systest/results/k8s_environment.rc"
+            }
+        }
+        stage('Install OSM') {
+            steps {
+                sh "/robot-systest/cloud-scripts/create-osm-vm.sh"
+                sh "cat /robot-systest/results/osm_environment.rc"
+                sh ". /robot-systest/results/osm_environment.rc ; /robot-systest/cloud-scripts/remote-install-osm.sh"
+            }
+        }
+        stage('Add VIM and K8s cluster to OSM') {
+            steps {
+                sh """
+                    . /robot-systest/results/osm_environment.rc ; \
+                    . /robot-systest/results/k8s_environment.rc ; \
+                    osm version ; \
+                    set +x; \
+                    export AZURE_CLIENT_ID=\$(cat ~/azure-creds.json | jq -r .clientId  | sed s/[{}]//g) ; \
+                    export AZURE_SECRET=\$(cat ~/azure-creds.json | jq -r .clientSecret) ; \
+                    export AZURE_TENANT=\$(cat ~/azure-creds.json | jq -r .tenantId) ; \
+                    export AZURE_SUBSCRIPTION_ID=\$(cat ~/azure-creds.json | jq -r .subscriptionId) ; \
+                    /robot-systest/cloud-scripts/add-vim-and-k8scluster.sh
+                    """
+            }
+
+        }
+        stage('Run Robot tests') {
+            steps {
+                sh """
                     . /robot-systest/results/osm_environment.rc ; \
-                    /robot-systest/cloud-scripts/remote-extract-logs.sh
+                    . /robot-systest/results/k8s_environment.rc ; \
+                    /robot-systest/run_test.sh -t ${params.ROBOT_RUN_TAG}
                     """
+            }
+        }
+    }
+    post {
+        always {
+            echo "Retrieve container logs"
+            sh """
+            . /robot-systest/results/osm_environment.rc ; \
+            /robot-systest/cloud-scripts/remote-extract-logs.sh
+            """
 
-                    echo "Save results"
-                    sh "rm -rf results"
-                    sh "cp -var /robot-systest/results /robot-systest/reports/* ."
-                    archiveArtifacts artifacts: 'results/**/*', fingerprint: true
+            echo "Save results"
+            sh "rm -rf results"
+            sh "cp -var /robot-systest/results /robot-systest/reports/* ."
+            archiveArtifacts artifacts: 'results/**/*', fingerprint: true
 
-                    echo "Updates the Robot dashboard in Jenkins"
-                    robot outputPath: '.', passThreshold: "${params.ROBOT_PASS_THRESHOLD}", unstableThreshold: "${params.ROBOT_UNSTABLE_THRESHOLD}"
+            echo "Updates the Robot dashboard in Jenkins"
+            robot outputPath: '.', passThreshold: "${params.ROBOT_PASS_THRESHOLD}", unstableThreshold: "${params.ROBOT_UNSTABLE_THRESHOLD}"
 
-                    echo "Destroy the K8s cluster"
-                    sh '. /robot-systest/results/k8s_environment.rc ; /robot-systest/cloud-scripts/delete-k8s.sh'
+            echo "Destroy the K8s cluster"
+            sh '. /robot-systest/results/k8s_environment.rc ; /robot-systest/cloud-scripts/delete-k8s.sh'
 
-                    echo "Destroy the OSM host"
-                    sh '. /robot-systest/results/osm_environment.rc ; /robot-systest/cloud-scripts/delete-osm-vm.sh'
-                    sh "az vm list -o table"
-                }
-            }
+            echo "Destroy the OSM host"
+            sh '. /robot-systest/results/osm_environment.rc ; /robot-systest/cloud-scripts/delete-osm-vm.sh'
+            sh "az vm list -o table"
         }
     }
 }