From 6f449332323ee288e53bdbc9aa3df2bba952521b Mon Sep 17 00:00:00 2001 From: Philipp Spilger <philipp.spilger@kip.uni-heidelberg.de> Date: Tue, 13 Feb 2024 10:15:11 +0100 Subject: [PATCH] feat: Drop support to execute yashchiki_notify_gerrit in container * works with less env vars now and doesn't require commons.sh anymore Change-Id: I0dbdcda4ad1f9f379f01ab9e801301ad85162e46 --- .ci/Jenkinsfile | 32 ++++++++++++++++++++++++++------ .ci/Jenkinsfile_asic | 14 +++++++++++--- bin/yashchiki_notify_gerrit.sh | 26 +++++++------------------- 3 files changed, 44 insertions(+), 28 deletions(-) diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile index 7f5fca53..feec019e 100755 --- a/.ci/Jenkinsfile +++ b/.ci/Jenkinsfile @@ -71,7 +71,11 @@ pipeline { steps { sh "mkdir -p ${YASHCHIKI_META_DIR}" sh "bash bin/yashchiki_dump_meta_info.sh" - sh "bash bin/yashchiki_notify_gerrit.sh -m 'Build containing this change started..'" + script { + if (isTriggeredByGerrit()) { + sh "bash bin/yashchiki_notify_gerrit.sh -m 'Build containing this change started..'" + } + } } } stage('Deploy utilities') { @@ -109,8 +113,10 @@ pipeline { script { // we only want the container name, tail everything else CONTAINER_IMAGE = sh(script: "bash bin/yashchiki_deploy_container.sh | tail -n 1", returnStdout: true).trim() + if (isTriggeredByGerrit()) { + sh "bash bin/yashchiki_notify_gerrit.sh -t Build -c \"$CONTAINER_IMAGE\"" + } } - sh "bash bin/yashchiki_notify_gerrit.sh -t Build -c \"$CONTAINER_IMAGE\"" } } } @@ -118,8 +124,10 @@ pipeline { failure { script { cache_failed = sh(script: "bash lib/yashchiki/create_temporary_build_cache_after_failure.sh", returnStdout: true).trim() + if (isTriggeredByGerrit()) { + sh "bash bin/yashchiki_notify_gerrit.sh -v -1 -t Build -m \"Successfully built packages stored in cache. Resume by issuing:\nWITH_CACHE_NAME=${cache_failed}\n\nIn your next gerrit comment, NOT commit message!\"" + } } - sh "bash bin/yashchiki_notify_gerrit.sh -v -1 -t Build -m \"Successfully built packages stored in cache. Resume by issuing:\nWITH_CACHE_NAME=${cache_failed}\n\nIn your next gerrit comment, NOT commit message!\"" } cleanup { archiveArtifacts "host.env" @@ -189,13 +197,25 @@ pipeline { } post { success { - jesh "bash bin/yashchiki_notify_gerrit.sh -v 1 -t Tests -c '${CONTAINER_IMAGE}'" + script { + if (isTriggeredByGerrit()) { + jesh "bash bin/yashchiki_notify_gerrit.sh -v 1 -t Tests -c '${CONTAINER_IMAGE}'" + } + } } unstable { - jesh "bash bin/yashchiki_notify_gerrit.sh -v 0 -t Tests -c '${CONTAINER_IMAGE}'" + script { + if (isTriggeredByGerrit()) { + jesh "bash bin/yashchiki_notify_gerrit.sh -v 0 -t Tests -c '${CONTAINER_IMAGE}'" + } + } } failure { - jesh "bash bin/yashchiki_notify_gerrit.sh -v -1 -t Tests -c '${CONTAINER_IMAGE}'" + script { + if (isTriggeredByGerrit()) { + jesh "bash bin/yashchiki_notify_gerrit.sh -v -1 -t Tests -c '${CONTAINER_IMAGE}'" + } + } } } } diff --git a/.ci/Jenkinsfile_asic b/.ci/Jenkinsfile_asic index b38dda96..84edfcb4 100755 --- a/.ci/Jenkinsfile_asic +++ b/.ci/Jenkinsfile_asic @@ -77,7 +77,11 @@ pipeline { steps { sh "mkdir -p ${YASHCHIKI_META_DIR}" sh "bash bin/yashchiki_dump_meta_info.sh" - sh "bash bin/yashchiki_notify_gerrit.sh -m 'Build containing this change started..'" + script { + if (isTriggeredByGerrit()) { + sh "bash bin/yashchiki_notify_gerrit.sh -m 'Build containing this change started..'" + } + } } } stage('Build container image') { @@ -110,8 +114,10 @@ pipeline { script { // we only want the container name, tail everything else CONTAINER_IMAGE = sh(script: "bin/yashchiki_deploy_container.sh | tail -n 1", returnStdout: true).trim() + if (isTriggeredByGerrit()) { + sh "bash bin/yashchiki_notify_gerrit.sh -t Build -c \"$CONTAINER_IMAGE\"" + } } - sh "bash bin/yashchiki_notify_gerrit.sh -t Build -c \"$CONTAINER_IMAGE\"" } } } @@ -119,8 +125,10 @@ pipeline { failure { script { cache_failed = sh(script: "lib/yashchiki/create_temporary_build_cache_after_failure.sh", returnStdout: true).trim() + if (isTriggeredByGerrit()) { + sh "bash bin/yashchiki_notify_gerrit.sh -v -1 -t Build -m \"Successfully built packages stored in cache. Resume by issuing:\nWITH_CACHE_NAME=${cache_failed}\n\nIn your next gerrit comment, NOT commit message!\"" + } } - sh "bash bin/yashchiki_notify_gerrit.sh -v -1 -t Build -m \"Successfully built packages stored in cache. Resume by issuing:\nWITH_CACHE_NAME=${cache_failed}\n\nIn your next gerrit comment, NOT commit message!\"" } cleanup { archiveArtifacts "host.env" diff --git a/bin/yashchiki_notify_gerrit.sh b/bin/yashchiki_notify_gerrit.sh index 8cbe5582..78ad069e 100755 --- a/bin/yashchiki_notify_gerrit.sh +++ b/bin/yashchiki_notify_gerrit.sh @@ -16,8 +16,7 @@ if ! [ "${CONTAINER_BUILD_TYPE:-}" = "testing" ]; then fi ROOT_DIR="$(dirname "$(dirname "$(readlink -m "${BASH_SOURCE[0]}")")")" -source "${ROOT_DIR}/lib/yashchiki/dummy_variables.sh" -source "${ROOT_DIR}/lib/yashchiki/commons.sh" +source "${ROOT_DIR}/lib/yashchiki/gerrit.sh" container_name="" result_type="" @@ -54,7 +53,7 @@ if [ -z "${result}" ] && [ -n "${verified}" ]; then fi fi -message="[$(get_host_env BUILD_URL)] \ +message="[$(echo "${BUILD_URL}")] \ ${container_name:+Change included in container: ${container_name}} \ ${custom_message:-} \ ${result:+${result_type:+${result_type} }Result: ${result}}" @@ -65,26 +64,19 @@ if [ "${CONTAINER_BUILD_TYPE}" = "testing" ]; then # Notify all changes involved that they got built into the current container # yashchiki changes - meta_dir="$(get_var_in_out META_DIR)" - if [ -f "${meta_dir}/current_changes-yashchiki.dat" ]; then - cat "${meta_dir}/current_changes-yashchiki.dat" >> "${tmpfile_commits}" + if [ -f "${YASHCHIKI_META_DIR}/current_changes-yashchiki.dat" ]; then + cat "${YASHCHIKI_META_DIR}/current_changes-yashchiki.dat" >> "${tmpfile_commits}" fi # spack changes - if [ -f "${meta_dir}/current_changes-spack.dat" ]; then - cat "${meta_dir}/current_changes-spack.dat" >> "${tmpfile_commits}" + if [ -f "${YASHCHIKI_META_DIR}/current_changes-spack.dat" ]; then + cat "${YASHCHIKI_META_DIR}/current_changes-spack.dat" >> "${tmpfile_commits}" fi readarray -t commits < <(grep -v "^$" "${tmpfile_commits}") - # if we are in a singularity container we need to go to the spack - # repository so the gerrit notifier can extract gerrit settings all - if [ -n "${SINGULARITY_CONTAINER:-}" ]; then - pushd "${MY_SPACK_FOLDER}" &>/dev/null || exit 1 - fi - # needs to be in git repo for gerrit_notify_change to work - cd ${WORKSPACE}/yashchiki + cd ${YASHCHIKI_INSTALL} for change in "${commits[@]}"; do if ! gerrit_notify_change -c "${change}" \ -v "${verified}" \ @@ -93,9 +85,5 @@ if [ "${CONTAINER_BUILD_TYPE}" = "testing" ]; then fi done - if [ -n "${SINGULARITY_CONTAINER:-}" ]; then - popd &>/dev/null || exit 1 - fi - rm -v "${tmpfile_commits}" 1>&2 fi -- GitLab