From 9ffe52d1f490ad068155767b34c305bcbf600cad Mon Sep 17 00:00:00 2001 From: Tom Kiemes Date: Wed, 7 Oct 2020 10:56:25 +0200 Subject: [PATCH] Add a milestone for Confirm stage (#2087) This commit will prevent abortion of older builds which are waiting in the Confirm stage, if a newer build fails in the last stage before the Confirm stage. Example: If the 'Compliance' stage of the general purpose pipeline (piperPipeline.groovy) fails, it will abort all former builds which are waiting in the 'Confirm' stage. The milestone function is called without an explicit ordinal since people might use the stage on different positions within their pipeline. When no ordinal is given, the last milestone ordinal value will be increased by 1. Note: Confirming a build will still abort all older builds waiting at the Confirm stage. --- .../templates/PiperPipelineStageConfirmTest.groovy | 14 ++++++++++++++ vars/piperPipelineStageConfirm.groovy | 2 ++ 2 files changed, 16 insertions(+) diff --git a/test/groovy/templates/PiperPipelineStageConfirmTest.groovy b/test/groovy/templates/PiperPipelineStageConfirmTest.groovy index a67612a03..b0d917b71 100644 --- a/test/groovy/templates/PiperPipelineStageConfirmTest.groovy +++ b/test/groovy/templates/PiperPipelineStageConfirmTest.groovy @@ -16,6 +16,7 @@ class PiperPipelineStageConfirmTest extends BasePiperTest { private Map timeoutSettings private Map inputSettings + private milestoneCalled = false @Rule public RuleChain rules = Rules @@ -37,6 +38,10 @@ class PiperPipelineStageConfirmTest extends BasePiperTest { inputSettings = m return [reason: 'this is my test reason for failing step 1 and step 3', acknowledgement: true] }) + + helper.registerAllowedMethod('milestone', [],{ + milestoneCalled = true + }) } @Test @@ -77,4 +82,13 @@ class PiperPipelineStageConfirmTest extends BasePiperTest { assertThat(jlr.log, containsString('this is my test reason')) assertThat(jlr.log, containsString('Acknowledgement\n---------------\n☑ I acknowledge that for traceability purposes the approval reason is stored together with my user name / user id')) } + + @Test + void callsMilestone(){ + jsr.step.piperPipelineStageConfirm( + script: nullScript + ) + + assertThat(milestoneCalled, is(true)) + } } diff --git a/vars/piperPipelineStageConfirm.groovy b/vars/piperPipelineStageConfirm.groovy index d8813f773..0ea87db44 100644 --- a/vars/piperPipelineStageConfirm.groovy +++ b/vars/piperPipelineStageConfirm.groovy @@ -48,6 +48,8 @@ void call(Map parameters = [:]) { boolean approval = false def userInput + milestone() + timeout( unit: 'HOURS', time: config.manualConfirmationTimeout