From 63ed456f4a464c3ea1fa3b184f49a7d24b318149 Mon Sep 17 00:00:00 2001 From: Timotheus Bachinger Date: Tue, 11 Feb 2025 18:11:56 +0100 Subject: [PATCH] Globalize bazel remote activation Change-Id: I9541758a28510660e0cca1387828d2722c67e96e --- buildscripts/scripts/build-cmk-distro-package.groovy | 8 +++----- buildscripts/scripts/jenkins_job_entry.groovy | 4 +++- buildscripts/scripts/test-python3-unit-all.groovy | 6 ++---- buildscripts/scripts/utils/common.groovy | 4 ++-- buildscripts/scripts/utils/gerrit_stages.groovy | 3 +-- buildscripts/scripts/utils/test_helper.groovy | 10 ++++------ 6 files changed, 15 insertions(+), 20 deletions(-) diff --git a/buildscripts/scripts/build-cmk-distro-package.groovy b/buildscripts/scripts/build-cmk-distro-package.groovy index 215867cf153..579a1171966 100644 --- a/buildscripts/scripts/build-cmk-distro-package.groovy +++ b/buildscripts/scripts/build-cmk-distro-package.groovy @@ -161,11 +161,9 @@ def main() { passwordVariable: 'NEXUS_PASSWORD', usernameVariable: 'NEXUS_USERNAME'), ]) { - withCredentialFileAtLocation(credentialsId:"remote.bazelrc", location:"${checkout_dir}/remote.bazelrc") { - /// Don't use withEnv, see - /// https://issues.jenkins.io/browse/JENKINS-43632 - sh("${omd_env_vars.join(' ')} make -C omd ${package_type}"); - } + /// Don't use withEnv, see + /// https://issues.jenkins.io/browse/JENKINS-43632 + sh("${omd_env_vars.join(' ')} make -C omd ${package_type}"); } package_name = cmd_output("ls check-mk-${edition}-${cmk_version}*.${package_type}"); diff --git a/buildscripts/scripts/jenkins_job_entry.groovy b/buildscripts/scripts/jenkins_job_entry.groovy index ef6f0dc8ccc..9379b3266fb 100644 --- a/buildscripts/scripts/jenkins_job_entry.groovy +++ b/buildscripts/scripts/jenkins_job_entry.groovy @@ -43,7 +43,9 @@ def main(job_definition_file) { def notify = load("${checkout_dir}/buildscripts/scripts/utils/notify.groovy"); try { - load("${checkout_dir}/${job_definition_file}").main(); + withCredentialFileAtLocation(credentialsId:"remote.bazelrc", location:"${checkout_dir}/remote.bazelrc") { + load("${checkout_dir}/${job_definition_file}").main(); + } } catch(Exception exc) { dir("${checkout_dir}") { notify.notify_error(exc); diff --git a/buildscripts/scripts/test-python3-unit-all.groovy b/buildscripts/scripts/test-python3-unit-all.groovy index 31dbd5b2fea..a44f0751551 100644 --- a/buildscripts/scripts/test-python3-unit-all.groovy +++ b/buildscripts/scripts/test-python3-unit-all.groovy @@ -11,10 +11,8 @@ def main() { dir("${checkout_dir}") { withCredentials([ ]) { - withCredentialFileAtLocation(credentialsId:"remote.bazelrc", location:"${checkout_dir}/remote.bazelrc") { - lock(label: "bzl_lock_${env.NODE_NAME.split('\\.')[0].split('-')[-1]}", quantity: 1, resource: null) { - sh("make -C tests test-unit-all"); - } + lock(label: "bzl_lock_${env.NODE_NAME.split('\\.')[0].split('-')[-1]}", quantity: 1, resource: null) { + sh("make -C tests test-unit-all"); } } } diff --git a/buildscripts/scripts/utils/common.groovy b/buildscripts/scripts/utils/common.groovy index db863db4959..b9d48d804ef 100644 --- a/buildscripts/scripts/utils/common.groovy +++ b/buildscripts/scripts/utils/common.groovy @@ -76,11 +76,11 @@ withCredentialFileAtLocation = {Map args, Closure body -> body.delegate = [:]; try { withCredentials([file(credentialsId: args.credentialsId, variable: "SECRET_LOCATION")]) { - sh("cp ${SECRET_LOCATION} ${args.location}"); + cmd_output("cp ${SECRET_LOCATION} ${args.location}"); body(); } return true; } finally { - sh("rm -f ${args.location}"); + cmd_output("rm -f ${args.location}"); } }; diff --git a/buildscripts/scripts/utils/gerrit_stages.groovy b/buildscripts/scripts/utils/gerrit_stages.groovy index 91c53f9e199..fe50e2d371a 100644 --- a/buildscripts/scripts/utils/gerrit_stages.groovy +++ b/buildscripts/scripts/utils/gerrit_stages.groovy @@ -42,7 +42,6 @@ def create_stage(Map args, time_stage_started) { withCredentials(args.SEC_VAR_LIST.collect{string(credentialsId: it, variable: it)}) { withEnv(args.ENV_VAR_LIST) { - withCredentialFileAtLocation(credentialsId:"remote.bazelrc", location:"${checkout_dir}/remote.bazelrc") { catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') { dir(args.DIR) { // be very carefull here. Setting quantity to 0 or null, takes all available resources @@ -72,7 +71,7 @@ def create_stage(Map args, time_stage_started) { /// make the stage fail if the command returned nonzero sh("exit ${cmd_status}"); - }} + } } } return [cmd_status == 0, issues]; diff --git a/buildscripts/scripts/utils/test_helper.groovy b/buildscripts/scripts/utils/test_helper.groovy index 007ef35b8ad..17d982fcb23 100644 --- a/buildscripts/scripts/utils/test_helper.groovy +++ b/buildscripts/scripts/utils/test_helper.groovy @@ -20,12 +20,10 @@ def execute_test(Map config = [:]) { if (defaultDict.output_file) { cmd += " 2>&1 | tee ${defaultDict.output_file}"; } - withCredentialFileAtLocation(credentialsId:"remote.bazelrc", location:"${checkout_dir}/remote.bazelrc") { - sh(""" - set -o pipefail - ${cmd} - """); - } + sh(""" + set -o pipefail + ${cmd} + """); } } }