Cherry picks from master

https://osm.etsi.org/gerrit/c/osm/devops/+/10223
https://osm.etsi.org/gerrit/c/osm/devops/+/10195
https://osm.etsi.org/gerrit/c/osm/devops/+/10142

Change-Id: I80cb5afe884c03a6e97553b4b805fc98c4a5e41b
Signed-off-by: beierlm <mark.beierl@canonical.com>
diff --git a/jenkins/ci-pipelines/ci_stage_1.groovy b/jenkins/ci-pipelines/ci_stage_1.groovy
index 53466f7..0f530c5 100644
--- a/jenkins/ci-pipelines/ci_stage_1.groovy
+++ b/jenkins/ci-pipelines/ci_stage_1.groovy
@@ -96,7 +96,7 @@
         println("TEST_INSTALL = ${params.TEST_INSTALL}, downstream job: ${downstream_job_name}")
 		currentBuild.result = 'SUCCESS'
         try {
-           stage_3_merge_result = build job: "${downstream_job_name}", parameters: downstream_params, propagate: true
+            stage_3_merge_result = build job: "${downstream_job_name}", parameters: downstream_params, propagate: true
             if (stage_3_merge_result.getResult() != 'SUCCESS') {
                 project = stage_3_merge_result.getProjectName()
                 build = stage_3_merge_result.getNumber()
@@ -104,28 +104,26 @@
 			    // error("${project} build ${build} failed")
 				currentBuild.result = stage_3_merge_result.getResult()
             }
-		}
-		catch(caughtError) {
-		 echo 'Exception in stage_1'
-		 currentBuild.result = 'FAILURE'
-		}
-		finally {
-		    try {
-			 if((currentBuild.result != 'SUCCESS') && (env.JOB_NAME == 'daily-stage_4')){
-               emailext (
-                   subject: "[OSM-Jenkins] Job: ${env.JOB_NAME} Build: ${env.BUILD_NUMBER} Result: ${currentBuild.result}",
-                   body: """ Check console output at "${env.BUILD_URL}"  """,
-                   to: 'OSM_MDL@list.etsi.org',
-                   recipientProviders: [culprits()]
-                )
+	}
+        catch(caughtError) {
+            echo 'Exception in stage_1'
+            currentBuild.result = 'FAILURE'
+        }
+        finally {
+            try {
+                if((currentBuild.result != 'SUCCESS') && (env.JOB_NAME == 'daily-stage_4')){
+                    emailext (
+                        subject: "[OSM-Jenkins] Job: ${env.JOB_NAME} Build: ${env.BUILD_NUMBER} Result: ${currentBuild.result}",
+                        body: """ Check console output at "${env.BUILD_URL}"  """,
+                        to: 'OSM_MDL@list.etsi.org',
+                        recipientProviders: [culprits()]
+                    )
+                }
             }
-		  }
-		  catch(caughtError) {
-		    echo "Failure in executing email"
-		  }
+            catch(caughtError) {
+                echo "Failure in executing email"
+            }
+        }
+    }
+}
 
-		}
-    } 
-
-	
- }
diff --git a/jenkins/ci-pipelines/ci_stage_2.groovy b/jenkins/ci-pipelines/ci_stage_2.groovy
index 616f569..5cad17b 100644
--- a/jenkins/ci-pipelines/ci_stage_2.groovy
+++ b/jenkins/ci-pipelines/ci_stage_2.groovy
@@ -81,16 +81,16 @@
 
     if (fileExists('snap/snapcraft.yaml')) {
         stage('Snap build') {
+            sh "docker pull snapcore/snapcraft:stable"
             sh "sudo rm -rf ${WORKSPACE}/stage/ ${WORKSPACE}/parts/ ${WORKSPACE}/prime/ ${WORKSPACE}/*.snap"
-            sh "docker run -v ${WORKSPACE}:/build --env BRANCH=${BRANCH_NAME} -w /build snapcore/snapcraft:stable /bin/bash -c 'apt update && snapcraft'"
-            sh "sudo mv ${WORKSPACE}/${mdg}_*.snap ${WORKSPACE}/${mdg}.snap"
+            sh "sudo snapcraft clean --use-lxd"
+            sh "snapcraft --use-lxd"
+            sh "mv ${WORKSPACE}/${mdg}_*.snap ${WORKSPACE}/${mdg}.snap"
             sh "sudo rm -rf ${WORKSPACE}/stage/ ${WORKSPACE}/parts/ ${WORKSPACE}/prime/"
 
             REV=""
             if ( !JOB_NAME.contains('merge') ) {
-                short_ref=sh(returnStdout: true,
-                    script: "git rev-parse --short HEAD").trim()
-                REV="/"+short_ref
+                REV="/"+"${GERRIT_REFSPEC}".replaceAll('/','-')
             }
             channel="latest"
             if (BRANCH_NAME.startsWith("v")) {
@@ -102,6 +102,7 @@
             sh "sudo docker run -v ~/.snapcraft:/snapcraft -v ${WORKSPACE}:/build " +
                 "-w /build snapcore/snapcraft:stable /bin/bash -c " +
                 "\"snapcraft login --with /snapcraft/config ; snapcraft push --release=${channel}/edge${REV} ${mdg}.snap\""
+            sh "sudo rm -rf ${WORKSPACE}/*.snap"
         }
     }
 
diff --git a/jenkins/ci-pipelines/ci_stage_3.groovy b/jenkins/ci-pipelines/ci_stage_3.groovy
index 4ba5630..6e23ba3 100644
--- a/jenkins/ci-pipelines/ci_stage_3.groovy
+++ b/jenkins/ci-pipelines/ci_stage_3.groovy
@@ -32,7 +32,7 @@
         string(defaultValue: 'artifactory-osm', description: '', name: 'ARTIFACTORY_SERVER'),
         string(defaultValue: 'osm-stage_4', description: '', name: 'DOWNSTREAM_STAGE_NAME'),
         string(defaultValue: 'testing-daily', description: '', name: 'DOCKER_TAG'),
-        booleanParam(defaultValue: true, description: '', name: 'SAVE_CONTAINER_ON_FAIL'),
+        booleanParam(defaultValue: false, description: '', name: 'SAVE_CONTAINER_ON_FAIL'),
         booleanParam(defaultValue: false, description: '', name: 'SAVE_CONTAINER_ON_PASS'),
         booleanParam(defaultValue: true, description: '', name: 'SAVE_ARTIFACTS_ON_SMOKE_SUCCESS'),
         booleanParam(defaultValue: true, description: '', name: 'DO_STAGE_4'),