1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-11-06 09:09:19 +02:00

Unstash via Utils.unstash (#4381)

We should only unstash using the Utils class.
The Jenkins unstash step does not log which stash was unstashed.
This commit is contained in:
Alexander Link
2023-07-07 14:00:44 +02:00
committed by GitHub
parent 610e212306
commit 1e9d8dfe98
2 changed files with 26 additions and 3 deletions

View File

@@ -68,6 +68,17 @@ class DockerExecuteOnKubernetesTest extends BasePiperTest {
def podSpec
Map resources = [:]
List stashList = []
List unstashList = []
def utilsMock = newUtilsMock()
Utils newUtilsMock() {
def utilsMock = new Utils()
utilsMock.steps = [
unstash : { m -> unstashList.add(m) }
]
utilsMock.echo = { def m -> }
return utilsMock
}
@Before
void init() {
@@ -809,6 +820,18 @@ class DockerExecuteOnKubernetesTest extends BasePiperTest {
hasEntry('excludes', 'container/exclude.test'))))
}
@Test
void testUnstash() {
stepRule.step.dockerExecuteOnKubernetes(
script: nullScript,
juStabUtils: utilsMock,
dockerImage: 'maven:3.5-jdk-8-alpine',
) {}
assertEquals(2, unstashList.size())
assertTrue(unstashList[0].startsWith('workspace-'))
assertTrue(unstashList[1].startsWith('container-'))
}
@Test
void testDockerExecuteWithVolumeProperties() {
stepRule.step.dockerExecuteOnKubernetes(

View File

@@ -346,7 +346,7 @@ void executeOnPod(Map config, utils, Closure body, Script script) {
}
} finally {
if (config.containerName)
unstashWorkspace(config, 'container')
unstashWorkspace(config, utils, 'container')
}
}
@@ -454,9 +454,9 @@ private Map getSecurityContext(Map config) {
return config.securityContext ?: config.jenkinsKubernetes.securityContext ?: [:]
}
private void unstashWorkspace(config, prefix) {
private void unstashWorkspace(config, utils, prefix) {
try {
unstash "${prefix}-${config.uniqueId}"
utils.unstash "${prefix}-${config.uniqueId}"
} catch (AbortException | IOException e) {
echo "${e.getMessage()}\n${e.getCause()}"
} catch (Throwable e) {