From a6901a2b02cf18acd8412c817f486e2c3c8a4b77 Mon Sep 17 00:00:00 2001 From: Stuart Rowe Date: Fri, 24 Mar 2023 14:41:30 -0700 Subject: [PATCH] Filter nodes with propagate: false arguments when evaluating WarningActions --- .../modeldefinition/model/BuildCondition.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pipeline-model-extensions/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/model/BuildCondition.java b/pipeline-model-extensions/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/model/BuildCondition.java index f2675f659..8e1224054 100644 --- a/pipeline-model-extensions/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/model/BuildCondition.java +++ b/pipeline-model-extensions/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/model/BuildCondition.java @@ -30,6 +30,7 @@ import hudson.model.Result; import org.jenkinsci.plugins.pipeline.modeldefinition.CommonUtils; import org.jenkinsci.plugins.structs.SymbolLookup; +import org.jenkinsci.plugins.workflow.actions.ArgumentsAction; import org.jenkinsci.plugins.workflow.actions.WarningAction; import org.jenkinsci.plugins.workflow.cps.CpsFlowExecution; import org.jenkinsci.plugins.workflow.flow.FlowExecution; @@ -147,6 +148,24 @@ public static Result getCombinedResult(@NonNull WorkflowRun run, @CheckForNull T return getCombinedResult(run, error, null); } + private static boolean hasPropagateFalseArgument(@NonNull FlowNode node) { + Map arguments = ArgumentsAction.getArguments(node); + if (arguments == null || arguments.isEmpty()) { + return false; + } + + Object propagate = arguments.get("propagate"); + if (propagate == null) { + return false; + } + + if (!(propagate instanceof Boolean)) { + return false; + } + + return !((Boolean) propagate); + } + @NonNull public static Result getCombinedResult(@NonNull WorkflowRun run, @CheckForNull Throwable error, @CheckForNull Object context) { Result errorResult = Result.SUCCESS; @@ -158,6 +177,7 @@ public static Result getCombinedResult(@NonNull WorkflowRun run, @CheckForNull T DepthFirstScanner scanner = new DepthFirstScanner(); if (scanner.setup(startAndEnd.get(1), Collections.singletonList(startAndEnd.get(0)))) { WarningAction warningAction = StreamSupport.stream(scanner.spliterator(), false) + .filter(node -> !hasPropagateFalseArgument(node)) .map(node -> node.getPersistentAction(WarningAction.class)) .filter(Objects::nonNull) .max(Comparator.comparing(warning -> warning.getResult().ordinal))