Skip to content

Commit

Permalink
Add patterns to define stage phases (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikRehmTT committed Oct 10, 2024
1 parent 548ff30 commit e2c7ec2
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions vars/pipeline2ATX.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
}
Expand Down Expand Up @@ -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'
}

/**
Expand Down

0 comments on commit e2c7ec2

Please sign in to comment.