1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00

fix(kubernetes): invalidate stashes after usage (#1064)

* fix(kubernetes): invalidate stashes after usage

fixes #1057

* adjust test case
This commit is contained in:
Christopher Fenner 2019-12-17 15:10:57 +01:00 committed by GitHub
parent 68ef5393c7
commit 57ae0e8f8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View File

@ -465,7 +465,7 @@ class DockerExecuteOnKubernetesTest extends BasePiperTest {
} }
@Test @Test
void tastStashIncludesAndExcludes() { void testStashIncludesAndExcludes() {
nullScript.commonPipelineEnvironment.configuration = [ nullScript.commonPipelineEnvironment.configuration = [
steps: [ steps: [
dockerExecuteOnKubernetes: [ dockerExecuteOnKubernetes: [
@ -487,8 +487,14 @@ class DockerExecuteOnKubernetesTest extends BasePiperTest {
) { ) {
bodyExecuted = true bodyExecuted = true
} }
assertThat(stashList[0], allOf(hasEntry('includes','workspace/include.test'), hasEntry('excludes','workspace/exclude.test'))) assertThat(stashList, hasItem(allOf(
assertThat(stashList[1], allOf(hasEntry('includes','container/include.test'), hasEntry('excludes','container/exclude.test'))) not(hasEntry('allowEmpty', true)),
hasEntry('includes','workspace/include.test'),
hasEntry('excludes','workspace/exclude.test'))))
assertThat(stashList, hasItem(allOf(
not(hasEntry('allowEmpty', true)),
hasEntry('includes','container/include.test'),
hasEntry('excludes','container/exclude.test'))))
} }

View File

@ -249,6 +249,8 @@ void executeOnPod(Map config, utils, Closure body, Script script) {
container(containerParams) { container(containerParams) {
try { try {
utils.unstashAll(stashContent) utils.unstashAll(stashContent)
echo "invalidate stash workspace-${config.uniqueId}"
stash name: "workspace-${config.uniqueId}", excludes: '**/*', allowEmpty: true
body() body()
} finally { } finally {
stashWorkspace(config, 'container', true, true) stashWorkspace(config, 'container', true, true)
@ -325,6 +327,8 @@ private Map getSecurityContext(Map config) {
private void unstashWorkspace(config, prefix) { private void unstashWorkspace(config, prefix) {
try { try {
unstash "${prefix}-${config.uniqueId}" unstash "${prefix}-${config.uniqueId}"
echo "invalidate stash ${prefix}-${config.uniqueId}"
stash name: "${prefix}-${config.uniqueId}", excludes: '**/*', allowEmpty: true
} catch (AbortException | IOException e) { } catch (AbortException | IOException e) {
echo "${e.getMessage()}" echo "${e.getMessage()}"
} }