From 5fdfe8c26e79aeaca0099ecfeffbe23fe17db657 Mon Sep 17 00:00:00 2001 From: Davlet Panech Date: Thu, 6 Oct 2022 10:21:50 -0400 Subject: [PATCH] PATCH_LIST: workaround for Jenkins bugs Some versions of Jenkins crash when a multi-line parameter is empty. Solution: set PATCH_LIST to "-" by default, and treat it as empty. Signed-off-by: Davlet Panech Change-Id: I7bd8f994debbfe86bc914ce469b81518ca13ea4a --- pipelines/monolithic.Jenkinsfile | 1 + pipelines/parts/clone-source.Jenkinsfile | 3 ++- scripts/clone-source.sh | 9 +++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/pipelines/monolithic.Jenkinsfile b/pipelines/monolithic.Jenkinsfile index 600125f..d17cd06 100644 --- a/pipelines/monolithic.Jenkinsfile +++ b/pipelines/monolithic.Jenkinsfile @@ -202,6 +202,7 @@ pipeline { ) text ( name: 'PATCH_LIST', + defaultValue: '-', description: '''\
List of Gerrit URLs to apply before running the build, one per line "[PATH] URL REF", eg:
 
diff --git a/pipelines/parts/clone-source.Jenkinsfile b/pipelines/parts/clone-source.Jenkinsfile
index cd4b6ac..bf4396c 100644
--- a/pipelines/parts/clone-source.Jenkinsfile
+++ b/pipelines/parts/clone-source.Jenkinsfile
@@ -44,7 +44,8 @@ pipeline {
             name: 'REFRESH_SOURCE'
         )
         text (
-            name: 'PATCH_LIST'
+            name: 'PATCH_LIST',
+            defaultValue: '-'
         )
     }
     stages {
diff --git a/scripts/clone-source.sh b/scripts/clone-source.sh
index b956019..3859479 100755
--- a/scripts/clone-source.sh
+++ b/scripts/clone-source.sh
@@ -13,6 +13,15 @@ source $(dirname "$0")/lib/retries.sh
 require_job_env BUILD_HOME
 require_job_env DRY_RUN
 require_job_env REFRESH_SOURCE
+declare_job_env PATCH_LIST
+
+# Some jenkins versions have a bug that causes misbehavior
+# when a multi-line parameter is empty. Treat "-" as empty
+# as a workaround.
+PATCH_LIST="$(echo "$PATCH_LIST" | grep -v -E '^\s*(#.*)?$' | sed -r -e 's/^\s+//g' -e 's/\s+$//g')"
+if [[ "$PATCH_LIST" == "-" ]] ; then
+    PATCH_LIST=
+fi
 
 load_build_env