From ee8073b37025b05de373633de63f9644548ac3b2 Mon Sep 17 00:00:00 2001
From: Philipp Spilger <philipp.spilger@kip.uni-heidelberg.de>
Date: Thu, 23 Jun 2022 11:08:48 +0200
Subject: [PATCH] Only cleanup at end of job

* allows using the repos cloned into the workspace beforehand for
  gerrit notifications, required for checkout via waf because there
  the repos reside in the workspace and would be deleted prematurely
  without this change
* requires contiguous allocation of an agent, but the verification
  is not dominating anymore, therefore not much parallelization
  drawback expected

Change-Id: I06f8b826303fbf34dd58b026f7270eed6ab1b870
---
 .ci/Jenkinsfile | 39 +++++++++++++++++----------------------
 1 file changed, 17 insertions(+), 22 deletions(-)

diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile
index b3120e39..52b618c2 100755
--- a/.ci/Jenkinsfile
+++ b/.ci/Jenkinsfile
@@ -14,7 +14,7 @@ Closure cleanupSteps = {
 }
 
 pipeline {
-	agent none
+	agent { label 'conviz1||conviz2' }
 
 	options {
 		timestamps()
@@ -33,7 +33,6 @@ pipeline {
 
 	stages {
 		stage('Container Build') {
-			agent { label 'conviz1||conviz2' }
 			environment {
 				DOCKER_BASE_IMAGE = "debian:bullseye"
 				// FIXME: ^${DEPENDENCY_PYTHON} is a workaround for an invalid spectrum-mpi concretization
@@ -136,11 +135,6 @@ pipeline {
 				cleanup {
 					archiveArtifacts "jenkins.env"
 					archiveArtifacts "out_singularity_build_visionary_recipe.txt"
-					// Clean build artifacts because otherwise the latest build from each jenkins job can take up to 50GB.
-					// 2 executors and 5 Jenkins-Jobs (testing, testing-spack, testing-asic, stable, stable-asic) will slowly but surely eat away memory.
-					script {
-						cleanupSteps()
-					}
 				}
 			}
 		}
@@ -213,27 +207,21 @@ pipeline {
 			}
 			post {
 				success {
-					node('conviz1||conviz2') {
-						// singularityArgs needed because conviz is still running singularity 2.6 due to faster image build times
-						inSingularity(image: CONTAINER_IMAGE, singularityArgs: "-B /etc/passwd") {
-							jesh "/opt/spack_install_scripts/notify_gerrit.sh -v 1 -t Tests -c '${CONTAINER_IMAGE}'"
-						}
+					// singularityArgs needed because conviz is still running singularity 2.6 due to faster image build times
+					inSingularity(image: CONTAINER_IMAGE, singularityArgs: "-B /etc/passwd") {
+						jesh "/opt/spack_install_scripts/notify_gerrit.sh -v 1 -t Tests -c '${CONTAINER_IMAGE}'"
 					}
 				}
 				unstable {
-					node ('conviz1||conviz2') {
-						// singularityArgs needed because conviz is still running singularity 2.6 due to faster image build times
-						inSingularity(image: CONTAINER_IMAGE, singularityArgs: "-B /etc/passwd") {
-							jesh "/opt/spack_install_scripts/notify_gerrit.sh -v 0 -t Tests -c '${CONTAINER_IMAGE}'"
-						}
+					// singularityArgs needed because conviz is still running singularity 2.6 due to faster image build times
+					inSingularity(image: CONTAINER_IMAGE, singularityArgs: "-B /etc/passwd") {
+						jesh "/opt/spack_install_scripts/notify_gerrit.sh -v 0 -t Tests -c '${CONTAINER_IMAGE}'"
 					}
 				}
 				failure {
-					node ('conviz1||conviz2') {
-						// singularityArgs needed because conviz is still running singularity 2.6 due to faster image build times
-						inSingularity(image: CONTAINER_IMAGE, singularityArgs: "-B /etc/passwd") {
-							jesh "/opt/spack_install_scripts/notify_gerrit.sh -v -1 -t Tests -c '${CONTAINER_IMAGE}'"
-						}
+					// singularityArgs needed because conviz is still running singularity 2.6 due to faster image build times
+					inSingularity(image: CONTAINER_IMAGE, singularityArgs: "-B /etc/passwd") {
+						jesh "/opt/spack_install_scripts/notify_gerrit.sh -v -1 -t Tests -c '${CONTAINER_IMAGE}'"
 					}
 				}
 			}
@@ -243,5 +231,12 @@ pipeline {
 		failure {
 			notifyFailure(mattermostChannel: "#spack")
 		}
+		cleanup {
+			// Clean build artifacts because otherwise the latest build from each jenkins job can take up to 50GB.
+			// 2 executors and 5 Jenkins-Jobs (testing, testing-spack, testing-asic, stable, stable-asic) will slowly but surely eat away memory.
+			script {
+				cleanupSteps()
+			}
+		}
 	}
 }
-- 
GitLab