Last active
February 17, 2025 20:49
-
-
Save pwalkr/bf801f0e3a8cd3a1ab3aece6809799bd to your computer and use it in GitHub Desktop.
Mark previous step unstable (Jenkins shared library)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.jenkinsci.plugins.workflow.actions.WarningAction | |
import org.jenkinsci.plugins.workflow.graph.FlowNode | |
import org.jenkinsci.plugins.workflow.job.WorkflowRun | |
import hudson.model.Result | |
/** | |
* Mark previous step unstable, without marking the whole build unstable | |
* | |
* This can be used to highlight inefficiencies or non-ideal usage of a pipeline, while permitting overall | |
* status (e.g. pull request checks) to return green/success. This will highlight the step and stage in | |
* Jenkins graph and stage views. E.g. usage: | |
* | |
* echo "Using deprecation option ____ in pipeline. Please use ____" | |
* unstableStep() | |
* | |
* This will show "Using deprecated option..." in the console and as a step in console view, and the step | |
* will be marked yellow/unstable, along with the current stage. The overall build will still show success. | |
*/ | |
void call(String message) { | |
WorkflowRun run = currentBuild.rawBuild | |
List<FlowNode> nodes = run.getExecution().getCurrentHeads() | |
if (nodes.isEmpty()) { | |
throw new IllegalStateException("No current heads found") | |
} | |
FlowNode currentNode = nodes.get(0) | |
// Not sure if message adds anything in this context | |
//currentNode.addOrReplaceAction(new WarningAction(Result.UNSTABLE).withMessage(message)) | |
currentNode.addOrReplaceAction(new WarningAction(Result.UNSTABLE)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment