org.jenkinsci.plugins.workflow.actions.WarningAction Java Examples

The following examples show how to use org.jenkinsci.plugins.workflow.actions.WarningAction. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PipelineResultHandler.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
@Override
public void setResult(final Result result, final String message) {
    run.setResult(result);
    WarningAction existing = flowNode.getPersistentAction(WarningAction.class);
    if (existing == null || existing.getResult().isBetterThan(result)) {
        flowNode.addOrReplaceAction(new WarningAction(result).withMessage(message));
    }
}
 
Example #2
Source File: StepsITest.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
/**
 * Verifies that when publishIssues marks the build as unstable it also marks the step with
 * WarningAction so that visualizations can display the step as unstable rather than just
 * the whole build.
 *
 * @see <a href="http://issues.jenkins-ci.org/browse/JENKINS-39203">Issue 39203</a>
 */
@Test @org.jvnet.hudson.test.Issue("JENKINS-39203")
public void publishIssuesShouldMarkStepWithWarningAction() {
    WorkflowJob job = createPipelineWithWorkspaceFiles("javac.txt");
    job.setDefinition(asStage(createScanForIssuesStep(new Java(), "java"),
            "publishIssues(issues:[java], qualityGates: [[threshold: 1, type: 'TOTAL', unstable: true]])"));
    WorkflowRun run = (WorkflowRun)buildWithResult(job, Result.UNSTABLE);
    FlowNode publishIssuesNode = new DepthFirstScanner().findFirstMatch(run.getExecution(),
            node -> "publishIssues".equals(Objects.requireNonNull(node).getDisplayFunctionName()));
    assertThat(publishIssuesNode).isNotNull();
    WarningAction warningAction = publishIssuesNode.getPersistentAction(WarningAction.class);
    assertThat(warningAction).isNotNull();
    assertThat(warningAction.getMessage()).isEqualTo("Some quality gates have been missed: overall result is UNSTABLE");
}
 
Example #3
Source File: StepsITest.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
/**
 * Verifies that when recordIssues marks the build as unstable it also marks the step with
 * WarningAction so that visualizations can display the step as unstable rather than just
 * the whole build.
 *
 * @see <a href="http://issues.jenkins-ci.org/browse/JENKINS-39203">Issue 39203</a>
 */
@Test @org.jvnet.hudson.test.Issue("JENKINS-39203")
public void recordIssuesShouldMarkStepWithWarningAction() {
    WorkflowJob job = createPipelineWithWorkspaceFiles("javac.txt");
    job.setDefinition(asStage("recordIssues(tool: java(pattern:'**/*issues.txt', reportEncoding:'UTF-8'),"
            + "qualityGates: [[threshold: 1, type: 'TOTAL', unstable: true]])"));
    WorkflowRun run = (WorkflowRun)buildWithResult(job, Result.UNSTABLE);
    FlowNode publishIssuesNode = new DepthFirstScanner().findFirstMatch(run.getExecution(),
            node -> "recordIssues".equals(Objects.requireNonNull(node).getDisplayFunctionName()));
    assertThat(publishIssuesNode).isNotNull();
    WarningAction warningAction = publishIssuesNode.getPersistentAction(WarningAction.class);
    assertThat(warningAction).isNotNull();
    assertThat(warningAction.getMessage()).isEqualTo("Some quality gates have been missed: overall result is UNSTABLE");
}
 
Example #4
Source File: StageResultHandlerTest.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
@Test
@SuppressWarnings("ConstantConditions")
@SuppressFBWarnings(value = "DP_DO_INSIDE_DO_PRIVILEGED",
        justification = "Needed to keep `FlowNode.getPersistentAction` from failing. "
                + "We can't mock the method directly because it's final.")
void pipelineHandlerShouldSetBuildResultAndAddWarningAction()
        throws IllegalAccessException, IllegalArgumentException, NoSuchFieldException {
    Run run = mock(Run.class);
    FlowNode flowNode = mock(FlowNode.class);
    Field actions = FlowNode.class.getDeclaredField("actions");
    actions.setAccessible(true);
    actions.set(flowNode, new CopyOnWriteArrayList<>());
    StageResultHandler pipelineHandler = new PipelineResultHandler(run, flowNode);
    pipelineHandler.setResult(Result.UNSTABLE, MESSAGE);
    verify(run).setResult(Result.UNSTABLE);
    verify(flowNode).addOrReplaceAction(refEq(new WarningAction(Result.UNSTABLE).withMessage(MESSAGE)));
    pipelineHandler.setResult(Result.FAILURE, MESSAGE);
    verify(flowNode).addOrReplaceAction(refEq(new WarningAction(Result.FAILURE).withMessage(MESSAGE)));
}
 
Example #5
Source File: NodeRunStatus.java    From blueocean-plugin with MIT License 5 votes vote down vote up
public NodeRunStatus(@Nonnull FlowNode endNode) {
    Result result = null;
    ErrorAction errorAction = endNode.getError();
    WarningAction warningAction = endNode.getPersistentAction(WarningAction.class);
    if (errorAction != null) {
        if(errorAction.getError() instanceof FlowInterruptedException) {
            result = ((FlowInterruptedException) errorAction.getError()).getResult();
        }
        if(result == null || result != Result.ABORTED) {
            this.result = BlueRun.BlueRunResult.FAILURE;
        } else {
            this.result = BlueRun.BlueRunResult.ABORTED;
        }
        this.state = endNode.isActive() ? BlueRun.BlueRunState.RUNNING : BlueRun.BlueRunState.FINISHED;
    } else if (warningAction != null) {
        this.result = new NodeRunStatus(GenericStatus.fromResult(warningAction.getResult())).result;
        this.state = endNode.isActive() ? BlueRun.BlueRunState.RUNNING : BlueRun.BlueRunState.FINISHED;
    } else if (QueueItemAction.getNodeState(endNode) == QueueItemAction.QueueState.QUEUED) {
        this.result = BlueRun.BlueRunResult.UNKNOWN;
        this.state = BlueRun.BlueRunState.QUEUED;
    } else if (QueueItemAction.getNodeState(endNode) == QueueItemAction.QueueState.CANCELLED) {
        this.result = BlueRun.BlueRunResult.ABORTED;
        this.state = BlueRun.BlueRunState.FINISHED;
    } else if (endNode.isActive()) {
        this.result = BlueRun.BlueRunResult.UNKNOWN;
        this.state = BlueRun.BlueRunState.RUNNING;
    } else if (NotExecutedNodeAction.isExecuted(endNode)) {
        this.result = BlueRun.BlueRunResult.SUCCESS;
        this.state = BlueRun.BlueRunState.FINISHED;
    } else {
        this.result = BlueRun.BlueRunResult.NOT_BUILT;
        this.state = BlueRun.BlueRunState.QUEUED;
    }
}
 
Example #6
Source File: JUnitResultsStepTest.java    From junit-plugin with MIT License 5 votes vote down vote up
private static BaseMatcher<FlowNode> hasWarningAction() {
    return new BaseMatcher<FlowNode>() {
        @Override
        public boolean matches(Object item) {
            return item instanceof FlowNode && ((FlowNode) item).getPersistentAction(WarningAction.class) != null;
        }
        @Override
        public void describeTo(Description description) {
            description.appendText("a FlowNode with a WarningAction");
        }
    };
}