mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-01-30 05:59:39 +02:00
fix(groovy): handle NPE in utils unstash (#4969)
* Fix NPE in utils unstash * fix test --------- Co-authored-by: Vijayan T <vijayanjay@gmail.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
This commit is contained in:
parent
8e962a7729
commit
4d32de1c1a
@ -90,7 +90,6 @@ boolean isInsidePod(Script script) {
|
||||
}
|
||||
|
||||
def unstash(name, msg = "Unstash failed:") {
|
||||
|
||||
def unstashedContent = []
|
||||
try {
|
||||
echo "Unstash content: ${name}"
|
||||
@ -98,7 +97,7 @@ def unstash(name, msg = "Unstash failed:") {
|
||||
unstashedContent += name
|
||||
} catch (e) {
|
||||
echo "$msg $name (${e.getMessage()})"
|
||||
if (e.getMessage().contains("JNLP4-connect")) {
|
||||
if (e.getMessage() != null && e.getMessage().contains("JNLP4-connect")) {
|
||||
sleep(3) // Wait 3 seconds in case it has been a network hiccup
|
||||
try {
|
||||
echo "[Retry JNLP4-connect issue] Unstashing content: ${name}"
|
||||
|
@ -227,6 +227,29 @@ class UtilsTest extends BasePiperTest {
|
||||
assert(stashResult == [])
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUnstashFailsNoExceptionMessage() {
|
||||
def logMessages = []
|
||||
def examinee = newExaminee(
|
||||
unstashClosure: {
|
||||
def stashName -> throw new RuntimeException()
|
||||
},
|
||||
echoClosure: {
|
||||
// coerce to java.lang.String, we might have GStrings.
|
||||
// comparism with java.lang.String might fail.
|
||||
message -> logMessages << message.toString()
|
||||
}
|
||||
)
|
||||
def stashResult = examinee.unstash('a')
|
||||
|
||||
// in case unstash fails (maybe the stash does not exist, or we cannot unstash due to
|
||||
// some colliding files in conjunction with file permissions) we emit a log message
|
||||
// and continue silently instead of failing. In that case we get an empty array back
|
||||
// instead an array containing the name of the unstashed stash.
|
||||
assertThat(logMessages, hasItem('Unstash failed: a (null)'))
|
||||
assert(stashResult == [])
|
||||
}
|
||||
|
||||
private Utils newExaminee(Map parameters) {
|
||||
def examinee = new Utils()
|
||||
examinee.steps = [
|
||||
|
Loading…
x
Reference in New Issue
Block a user