From 57ae0e8f8de8b96759c738c6281c55e31814307f Mon Sep 17 00:00:00 2001 From: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> Date: Tue, 17 Dec 2019 15:10:57 +0100 Subject: [PATCH] fix(kubernetes): invalidate stashes after usage (#1064) * fix(kubernetes): invalidate stashes after usage fixes #1057 * adjust test case --- test/groovy/DockerExecuteOnKubernetesTest.groovy | 12 +++++++++--- vars/dockerExecuteOnKubernetes.groovy | 4 ++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/test/groovy/DockerExecuteOnKubernetesTest.groovy b/test/groovy/DockerExecuteOnKubernetesTest.groovy index 383aac5dc..423c224c7 100644 --- a/test/groovy/DockerExecuteOnKubernetesTest.groovy +++ b/test/groovy/DockerExecuteOnKubernetesTest.groovy @@ -465,7 +465,7 @@ class DockerExecuteOnKubernetesTest extends BasePiperTest { } @Test - void tastStashIncludesAndExcludes() { + void testStashIncludesAndExcludes() { nullScript.commonPipelineEnvironment.configuration = [ steps: [ dockerExecuteOnKubernetes: [ @@ -487,8 +487,14 @@ class DockerExecuteOnKubernetesTest extends BasePiperTest { ) { bodyExecuted = true } - assertThat(stashList[0], allOf(hasEntry('includes','workspace/include.test'), hasEntry('excludes','workspace/exclude.test'))) - assertThat(stashList[1], allOf(hasEntry('includes','container/include.test'), hasEntry('excludes','container/exclude.test'))) + assertThat(stashList, hasItem(allOf( + 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')))) } diff --git a/vars/dockerExecuteOnKubernetes.groovy b/vars/dockerExecuteOnKubernetes.groovy index 9781a099c..f933883c9 100644 --- a/vars/dockerExecuteOnKubernetes.groovy +++ b/vars/dockerExecuteOnKubernetes.groovy @@ -249,6 +249,8 @@ void executeOnPod(Map config, utils, Closure body, Script script) { container(containerParams) { try { utils.unstashAll(stashContent) + echo "invalidate stash workspace-${config.uniqueId}" + stash name: "workspace-${config.uniqueId}", excludes: '**/*', allowEmpty: true body() } finally { stashWorkspace(config, 'container', true, true) @@ -325,6 +327,8 @@ private Map getSecurityContext(Map config) { private void unstashWorkspace(config, prefix) { try { unstash "${prefix}-${config.uniqueId}" + echo "invalidate stash ${prefix}-${config.uniqueId}" + stash name: "${prefix}-${config.uniqueId}", excludes: '**/*', allowEmpty: true } catch (AbortException | IOException e) { echo "${e.getMessage()}" }