1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-01-30 05:59:39 +02:00

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.
This commit is contained in:
Marcus Holl 2019-02-11 12:47:15 +01:00
parent 56d3a6ed97
commit 5f07490cf2
2 changed files with 12 additions and 1 deletions

View File

@ -54,6 +54,7 @@ def stashWithMessage(name, msg, include = '**/*.*', exclude = '') {
}
def unstash(name, msg = "Unstash failed:") {
def unstashedContent = []
try {
echo "Unstash content: ${name}"
@ -69,9 +70,11 @@ def unstashAll(stashContent) {
def unstashedContent = []
if (stashContent) {
for (i = 0; i < stashContent.size(); i++) {
if(stashContent[i]) {
unstashedContent += unstash(stashContent[i])
}
}
}
return unstashedContent
}

View File

@ -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']
}
}