1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-03-05 15:15:44 +02:00

Execute closures when evaluating shell calls

This allows us to e.g. also throw exceptions (e.g. hudson.AbortException) when dealing with
mocked shell calls.
This commit is contained in:
Marcus Holl 2018-09-07 14:28:26 +02:00
parent bc7b1e0890
commit cce1eb0f9a

View File

@ -61,14 +61,18 @@ class JenkinsShellCallRule implements TestRule {
shell.add(m.script.replaceAll(/\s+/," ").trim())
if (m.returnStdout || m.returnStatus) {
def unifiedScript = unify(m.script)
def result = null
for(def e : returnValues.entrySet()) {
if(e.key.type == Type.REGEX && unifiedScript =~ e.key.script) {
return e.value
result = e.value
break
} else if(e.key.type == Type.PLAIN && unifiedScript.equals(e.key.script)) {
return e.value
result = e.value
break
}
}
return null
if(result instanceof Closure) result = result()
return result
}
})