From ea03e88b4ac9fec61d29a8b0a04c65b8e599c0fd Mon Sep 17 00:00:00 2001 From: Thomas Dy Date: Mon, 18 Mar 2024 00:52:45 +0900 Subject: [PATCH] Only return names in getStageOrBranchName if it's a stage or branch If `stageOrBranchName` is present, we skip processing errors. This is on the assumption that if `stageOrBranchName` is present it is a stage or branch. However, normal steps like `sh` can have labels too and was returned as the `stageOrBranchName`. This causes labeled steps to not have their errors processed. We fix this by returning empty in `getStageOrBranchName` if the node is not a `BlockStartNode`. --- .../plugins/checks/status/FlowExecutionAnalyzer.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/jenkins/plugins/checks/status/FlowExecutionAnalyzer.java b/src/main/java/io/jenkins/plugins/checks/status/FlowExecutionAnalyzer.java index 553d6213..4083c49a 100644 --- a/src/main/java/io/jenkins/plugins/checks/status/FlowExecutionAnalyzer.java +++ b/src/main/java/io/jenkins/plugins/checks/status/FlowExecutionAnalyzer.java @@ -26,6 +26,7 @@ import org.jenkinsci.plugins.workflow.actions.ThreadNameAction; import org.jenkinsci.plugins.workflow.actions.WarningAction; import org.jenkinsci.plugins.workflow.flow.FlowExecution; +import org.jenkinsci.plugins.workflow.graph.BlockStartNode; import org.jenkinsci.plugins.workflow.graph.FlowNode; import org.jenkinsci.plugins.workflow.graph.StepNode; import org.jenkinsci.plugins.workflow.steps.StepDescriptor; @@ -53,9 +54,14 @@ class FlowExecutionAnalyzer { } private static Optional getStageOrBranchName(final FlowNode node) { - return getParallelName(node) - .map(Optional::of) - .orElse(getStageName(node)); + if (node instanceof BlockStartNode) { + // a stage or parallel branch must be a BlockStartNode + return getParallelName(node).or(() -> getStageName(node)); + } + else { + // otherwise, this is a regular step, don't return a name + return Optional.empty(); + } } private static Optional getStageName(final FlowNode node) {