From e2c7ec23faed89a1b48f51a19f2c6b11260be651 Mon Sep 17 00:00:00 2001 From: Erik Rehm Date: Wed, 4 Sep 2024 16:25:41 +0200 Subject: [PATCH] Add patterns to define stage phases (#36) --- vars/pipeline2ATX.groovy | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/vars/pipeline2ATX.groovy b/vars/pipeline2ATX.groovy index f0f8eb9..7804fe6 100644 --- a/vars/pipeline2ATX.groovy +++ b/vars/pipeline2ATX.groovy @@ -254,7 +254,6 @@ def generateJsonReport(build, attributes, constants, executionTestSteps, paramet * @return a map containing the calculated durations in seconds and percentages */ def calculateTime(executionTestSteps, build) { - def currentPhase = 'setup' def setupDuration = 0.0 def executionDuration = 0.0 def teardownDuration = 0.0 @@ -263,15 +262,14 @@ def calculateTime(executionTestSteps, build) { def fromCommitToStartTime = currentBuild.getBuildCauses('jenkins.branch.BranchEventCause').isEmpty() ? null : getTimeFromCommitToStart(build) executionTestSteps.each { stage -> - def stageName = stage.name // Update the current phase based on the stage name - currentPhase = getCurrentPhase(stageName, currentPhase) + def stagePhase = getStagePhase(stage.name) - if (currentPhase == 'teardown') { + if (stagePhase == 'teardown') { teardownDuration += stage.duration - } else if (currentPhase == 'setup') { + } else if (stagePhase == 'setup') { setupDuration += stage.duration - } else if (currentPhase == 'execution') { + } else if (stagePhase == 'execution') { executionDuration += stage.duration } } @@ -356,13 +354,13 @@ def calculateErrorTime(executionTestSteps) { * the corresponding phase in which the current stage is located * @return the current phase */ -def getCurrentPhase(stageName, currentPhase) { - if (stageName.contains("stage (Declarative: Post")) { +def getStagePhase(stageName) { + if (stageName.contains("Post Actions") || stageName.contains("Post:")) { return 'teardown' - } else if (!stageName.contains("stage (Declarative") && currentPhase == 'setup') { - return 'execution' + } else if (stageName.contains("Declarative:") || stageName.contains("Pre:")) { + return 'setup' } - return currentPhase + return 'execution' } /**