From 5f07490cf246289d0207e69f92aac617c49825c4 Mon Sep 17 00:00:00 2001 From: Marcus Holl Date: Mon, 11 Feb 2019 12:47:15 +0100 Subject: [PATCH] Unstash in loop only if identifier is available In case unstashAll is called with a Set containing a null value we get an ugly message in the log: Unstash failed: null (Could not instantiate {name=null} for UnstashStep(name: String): This can be avoided by unstashing only in case we have an ID. --- src/com/sap/piper/Utils.groovy | 5 ++++- test/groovy/com/sap/piper/UtilsTest.groovy | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/com/sap/piper/Utils.groovy b/src/com/sap/piper/Utils.groovy index 47f1e8f49..71b5161d1 100644 --- a/src/com/sap/piper/Utils.groovy +++ b/src/com/sap/piper/Utils.groovy @@ -54,6 +54,7 @@ def stashWithMessage(name, msg, include = '**/*.*', exclude = '') { } def unstash(name, msg = "Unstash failed:") { + def unstashedContent = [] try { echo "Unstash content: ${name}" @@ -69,7 +70,9 @@ def unstashAll(stashContent) { def unstashedContent = [] if (stashContent) { for (i = 0; i < stashContent.size(); i++) { - unstashedContent += unstash(stashContent[i]) + if(stashContent[i]) { + unstashedContent += unstash(stashContent[i]) + } } } return unstashedContent diff --git a/test/groovy/com/sap/piper/UtilsTest.groovy b/test/groovy/com/sap/piper/UtilsTest.groovy index f951b010d..3ce51dbf7 100644 --- a/test/groovy/com/sap/piper/UtilsTest.groovy +++ b/test/groovy/com/sap/piper/UtilsTest.groovy @@ -38,6 +38,7 @@ class UtilsTest extends BasePiperTest { void setup() { parameters = [:] + } @Test @@ -70,4 +71,11 @@ class UtilsTest extends BasePiperTest { // generated with "echo -n 'ContinuousDelivery' | sha1sum | sed 's/ -//'" assertThat(result, is('0dad6c33b6246702132454f604dee80740f399ad')) } + + @Test + void testUnstashAllSkipNull() { + + def stashResult = utils.unstashAll(['a', null, 'b']) + assert stashResult == ['a', 'b'] + } }