Meridio: update node to 2204
[infra/cicd.git] / jjb / nsm / Jenkinsfile
index e54acf6a0cd5a1103e84898f25e9ae1ea5cc1b14..e30b92eb6188a32b645e4df0d787262a08983a0b 100644 (file)
@@ -27,7 +27,7 @@ failed = 'Failed'
 exception_message_exec = 'failed to execute the following command: '
 exception_message_code_generation = 'Generated code verification failed'
 
-node('nordix-nsm-build-ubuntu1804') {
+node('nordix-nsm-build-ubuntu2204') {
     build_number = env.BUILD_NUMBER
     workspace = env.WORKSPACE
     ws("${workspace}/${build_number}") {
@@ -57,12 +57,19 @@ node('nordix-nsm-build-ubuntu1804') {
             }
             stage('Verify') {
                 Verify().call()
+                if (currentBuild.result == 'FAILURE') {
+                    Error('Failed at verification stage').call()
+                }
             }
             stage('Docker login') {
-                withCredentials([usernamePassword(credentialsId: 'nordix-cicd-harbor-credentials', passwordVariable: 'HARBOR_PASSWORD', usernameVariable: 'HARBOR_USERNAME')]) {
-                    sh '''#!/bin/bash -eu
+                if (env.DRY_RUN != 'true') {
+                    withCredentials([usernamePassword(credentialsId: 'nordix-cicd-harbor-credentials', passwordVariable: 'HARBOR_PASSWORD', usernameVariable: 'HARBOR_USERNAME')]) {
+                        sh '''#!/bin/bash -eu
                     echo $HARBOR_PASSWORD | docker login --username $HARBOR_USERNAME --password-stdin $IMAGE_REGISTRY
                     '''
+                    }
+                } else {
+                    Utils.markStageSkippedForConditional('Docker login')
                 }
             }
             stage('Base Image') {
@@ -70,9 +77,16 @@ node('nordix-nsm-build-ubuntu1804') {
             }
             stage('Images') {
                 Images(image_names, version, build_steps, image_registry, local_version).call()
+                if (currentBuild.result == 'FAILURE') {
+                    Error('Failed to build image(s)').call()
+                }
             }
             stage('E2E') {
-                E2e(e2e_enabled).call()
+                if (e2e_enabled == 'true' && env.DRY_RUN != 'true') {
+                    E2e(e2e_enabled).call()
+                } else {
+                    Utils.markStageSkippedForConditional('E2E')
+                }
             }
         }
         stage('Cleanup') {
@@ -107,7 +121,8 @@ def UnitTests() {
                 SetBuildStatus(completed, context, success)
             } catch (Exception e) {
                 SetBuildStatus(failed, context, failure)
-                Error(exception_message_exec + command).call()
+                unstable "${exception_message_exec} ${command}"
+                currentBuild.result = 'FAILURE'
             }
         }
     }
@@ -125,7 +140,8 @@ def Linter() {
                 SetBuildStatus(completed, context, success)
             } catch (Exception e) {
                 SetBuildStatus(failed, context, failure)
-                Error(exception_message_exec + command).call()
+                unstable "${exception_message_exec} ${command}"
+                currentBuild.result = 'FAILURE'
             }
         }
     }
@@ -167,17 +183,6 @@ def GeneratedCode() {
         stage('Proto') {
             // TODO: protoc version could be different
             Utils.markStageSkippedForConditional('Proto')
-        // try {
-        //     sh 'make proto'
-        //     if (GetModifiedFiles() != '') {
-        //         throw new Exception(exception_message)
-        //     }
-        // } catch (Exception e) {
-        //     SetBuildStatus(failed, context, failure)
-        //     sh 'git diff'
-        //     sh 'git status -s'
-        //     Error(e).call()
-        // }
         }
         SetBuildStatus(completed, context, success)
     }
@@ -215,7 +220,8 @@ def Build(image, version, build_steps, registry, local_version) {
                 SetBuildStatus(completed_message, context, success)
             } catch (Exception e) {
                 SetBuildStatus(failed_message, context, failure)
-                Error(exception_message_exec + command).call()
+                unstable "${exception_message_exec} ${command}"
+                currentBuild.result = 'FAILURE'
             }
         }
     }
@@ -224,14 +230,8 @@ def Build(image, version, build_steps, registry, local_version) {
 // Run the E2e Tests
 // Currently skipped
 def E2e(e2e_enabled) {
-    if (e2e_enabled == 'true') {
-        return {
-            echo 'make e2e' // todo
-        }
-    } else {
-        return {
-            Utils.markStageSkippedForConditional('E2E')
-        }
+    return {
+        echo 'make e2e' // todo
     }
 }
 
@@ -253,24 +253,30 @@ def Cleanup() {
 // Execute command
 def ExecSh(command) {
     return {
-        sh """
-            . \${HOME}/.profile
-            ${command}
-        """
+        if (env.DRY_RUN != 'true') {
+            sh """
+                . \${HOME}/.profile
+                ${command}
+            """
+        } else {
+            echo "${command}"
+        }
     }
 }
 
 // Set the commit status on Github
 // https://plugins.jenkins.io/github/#plugin-content-pipeline-examples
 def SetBuildStatus(String message, String context, String state) {
-    step([
-        $class: 'GitHubCommitStatusSetter',
-        reposSource: [$class: 'ManuallyEnteredRepositorySource', url: 'https://github.com/Nordix/Meridio'],
-        commitShaSource: [$class: 'ManuallyEnteredShaSource', sha: GetCommitSha()],
-        contextSource: [$class: 'ManuallyEnteredCommitContextSource', context: context],
-        errorHandlers: [[$class: 'ShallowAnyErrorHandler']], // Prevent GitHubCommitStatusSetter to set the job status to unstable
-        statusResultSource: [ $class: 'ConditionalStatusResultSource', results: [[$class: 'AnyBuildResult', message: message, state: state]] ]
-  ])
+    if (env.DRY_RUN != 'true') {
+        step([
+            $class: 'GitHubCommitStatusSetter',
+            reposSource: [$class: 'ManuallyEnteredRepositorySource', url: 'https://github.com/Nordix/Meridio'],
+            commitShaSource: [$class: 'ManuallyEnteredShaSource', sha: GetCommitSha()],
+            contextSource: [$class: 'ManuallyEnteredCommitContextSource', context: context],
+            errorHandlers: [[$class: 'ShallowAnyErrorHandler']], // Prevent GitHubCommitStatusSetter to set the job status to unstable
+            statusResultSource: [ $class: 'ConditionalStatusResultSource', results: [[$class: 'AnyBuildResult', message: message, state: state]] ]
+        ])
+    }
 }
 
 // Return the current commit sha