Java Code Examples for hudson.model.Result#UNSTABLE

The following examples show how to use hudson.model.Result#UNSTABLE . 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: GitLabMessagePublisher.java    From gitlab-plugin with GNU General Public License v2.0 6 votes vote down vote up
private String getNote(Run<?, ?> build, TaskListener listener) {
    String message;
    if (this.replaceSuccessNote && build.getResult() == Result.SUCCESS) {
        message = replaceMacros(build, listener, this.getSuccessNoteText());
    } else if (this.replaceAbortNote && build.getResult() == Result.ABORTED) {
        message = replaceMacros(build, listener, this.getAbortNoteText());
    } else if (this.replaceUnstableNote && build.getResult() == Result.UNSTABLE) {
        message = replaceMacros(build, listener, this.getUnstableNoteText());
    } else if (this.replaceFailureNote && build.getResult() == Result.FAILURE) {
        message = replaceMacros(build, listener, this.getFailureNoteText());
    } else {
        String icon = getResultIcon(build.getResult());
        String buildUrl = Jenkins.getInstance().getRootUrl() + build.getUrl();
        message = MessageFormat.format("{0} Jenkins Build {1}\n\nResults available at: [Jenkins [{2} #{3}]]({4})",
                                       icon, build.getResult().toString(), build.getParent().getDisplayName(), build.getNumber(), buildUrl);
    }
    return message;
}
 
Example 2
Source File: CardBuilder.java    From office-365-connector-plugin with Apache License 2.0 6 votes vote down vote up
String calculateStatus(Result lastResult, Result previousResult, boolean isRepeatedFailure) {
    if (lastResult == Result.SUCCESS) {
        // back to normal
        if (previousResult == Result.FAILURE || previousResult == Result.UNSTABLE) {
            return "Back to Normal";
        }
        // success remains
        return "Build Success";
    }
    if (lastResult == Result.FAILURE) {
        if (isRepeatedFailure) {
            return "Repeated Failure";
        }
        return "Build Failed";
    }
    if (lastResult == Result.ABORTED) {
        return "Build Aborted";
    }
    if (lastResult == Result.UNSTABLE) {
        return "Build Unstable";
    }

    return lastResult.toString();
}
 
Example 3
Source File: CardBuilder.java    From office-365-connector-plugin with Apache License 2.0 6 votes vote down vote up
String calculateSummary(Result completedResult, Result previousResult, boolean isRepeatedFailure) {

        if (completedResult == Result.SUCCESS) {
            // back to normal
            if (previousResult == Result.FAILURE || previousResult == Result.UNSTABLE) {
                return "Back to Normal";
            }
            // success remains
            return "Success";
        }
        if (completedResult == Result.FAILURE) {
            if (isRepeatedFailure) {
                return "Repeated Failure";
            }
            return "Failed";
        }
        if (completedResult == Result.ABORTED) {
            return "Aborted";
        }
        if (completedResult == Result.UNSTABLE) {
            return "Unstable";
        }

        return completedResult.toString();
    }
 
Example 4
Source File: CardBuilderTest.java    From office-365-connector-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void calculateStatus_OnSuccess_ReturnsBackToNormal() {

    // given
    Result lastResult = Result.SUCCESS;
    boolean isRepeatedFailure = false;
    Result[] previousResults = {Result.FAILURE, Result.UNSTABLE};

    for (Result previousResult : previousResults) {
        // when
        String status = cardBuilder.calculateStatus(lastResult, previousResult, isRepeatedFailure);

        // then
        assertThat(status).isEqualTo("Back to Normal");
    }
}
 
Example 5
Source File: CardBuilderTest.java    From office-365-connector-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void calculateSummary_OnSuccess_ReturnsBackToNormal() {

    // given
    Result lastResult = Result.SUCCESS;
    boolean isRepeatedFailure = false;
    Result[] previousResults = {Result.FAILURE, Result.UNSTABLE};

    for (Result previousResult : previousResults) {
        // when
        String status = cardBuilder.calculateSummary(lastResult, previousResult, isRepeatedFailure);

        // then
        assertThat(status).isEqualTo("Back to Normal");
    }
}
 
Example 6
Source File: TelegramBotPublisher.java    From telegram-notifications-plugin with MIT License 6 votes vote down vote up
@Override
public void perform(
        @Nonnull Run<?, ?> run,
        @Nonnull FilePath filePath,
        @Nonnull Launcher launcher,
        @Nonnull TaskListener taskListener) throws InterruptedException, IOException {

    Result result = run.getResult();

    boolean success  = result == Result.SUCCESS  && whenSuccess;
    boolean unstable = result == Result.UNSTABLE && whenUnstable;
    boolean failed   = result == Result.FAILURE  && whenFailed;
    boolean aborted  = result == Result.ABORTED  && whenAborted;

    boolean neededToSend = success || unstable || failed || aborted;

    if (neededToSend) {
        TelegramBotRunner.getInstance().getBot()
                .sendMessage(getMessage(), run, filePath, taskListener);
    }
}
 
Example 7
Source File: CommentBuilder.java    From phabricator-jenkins-plugin with MIT License 6 votes vote down vote up
void processBuildResult(
        Result result,
        boolean commentOnSuccess,
        boolean commentWithConsoleLinkOnFailure,
        boolean runHarbormaster) {
    if (result == Result.SUCCESS) {
        if (comment.length() == 0 && (commentOnSuccess || !runHarbormaster)) {
            comment.append("Build is green");
        }
    } else if (result == Result.UNSTABLE) {
        comment.append("Build is unstable");
    } else if (result == Result.FAILURE) {
        if (!runHarbormaster || commentWithConsoleLinkOnFailure) {
            comment.append("Build has FAILED");
        }
    } else if (result == Result.ABORTED) {
        comment.append("Build was aborted");
    } else {
        logger.info(UBERALLS_TAG, "Unknown build status " + result.toString());
    }
}
 
Example 8
Source File: CardBuilderTest.java    From office-365-connector-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void getCardThemeColor_OnUnstableResult_ReturnsBallColor() {
    // given
    Result unstableResult = Result.UNSTABLE;
    String ballColorString = Result.UNSTABLE.color.getHtmlBaseColor();

    // when
    String themeColor = Deencapsulation.invoke(CardBuilder.class, "getCardThemeColor", unstableResult);
    
    // then
    assertThat(themeColor).isEqualToIgnoringCase(ballColorString);
}
 
Example 9
Source File: GitLabMessagePublisher.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
private String getResultIcon(Result result) {
    if (result == Result.SUCCESS) {
        return ":white_check_mark:";
    } else if (result == Result.ABORTED) {
        return ":point_up:";
    } else if (result == Result.UNSTABLE) {
        return ":warning:";
    } else {
        return ":negative_squared_cross_mark:";
    }
}
 
Example 10
Source File: GitLabMessagePublisher.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void perform(Run<?, ?> build, TaskListener listener, GitLabClient client, MergeRequest mergeRequest) {
    try {
        if (!onlyForFailure || build.getResult() == Result.FAILURE || build.getResult() == Result.UNSTABLE) {
            client.createMergeRequestNote(mergeRequest, getNote(build, listener));
        }
    } catch (WebApplicationException | ProcessingException e) {
        listener.getLogger().printf("Failed to add comment on Merge Request for project '%s': %s%n", mergeRequest.getProjectId(), e.getMessage());
        LOGGER.log(Level.SEVERE, String.format("Failed to add comment on Merge Request for project '%s'", mergeRequest.getProjectId()), e);
    }
}
 
Example 11
Source File: GitLabCommitStatusPublisher.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
    Result buildResult = build.getResult();
    if (buildResult == Result.SUCCESS || (buildResult == Result.UNSTABLE && markUnstableAsSuccess)) {
        CommitStatusUpdater.updateCommitStatus(build, listener, BuildState.success, name);
    } else if (buildResult == Result.ABORTED) {
        CommitStatusUpdater.updateCommitStatus(build, listener, BuildState.canceled, name);
    } else {
        CommitStatusUpdater.updateCommitStatus(build, listener, BuildState.failed, name);
    }
    return true;
}
 
Example 12
Source File: BuildStatusAction.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
private BuildStatus getStatus(Run<?, ?> build) {
    if (build == null) {
        return BuildStatus.NOT_FOUND;
    } else if (build.isBuilding()) {
        return BuildStatus.RUNNING;
    } else if (build.getResult() == Result.ABORTED) {
        return BuildStatus.CANCELED;
    } else if (build.getResult() == Result.SUCCESS) {
        return BuildStatus.SUCCESS;
    } else if (build.getResult() == Result.UNSTABLE) {
        return BuildStatus.UNSTABLE;
    } else {
        return BuildStatus.FAILED;
    }
}
 
Example 13
Source File: TestResult.java    From junit-plugin with MIT License 5 votes vote down vote up
/**
 * Mark a build as unstable if there are failures. Otherwise, leave the
 * build result unchanged.
 *
 * @return {@link Result#UNSTABLE} if there are test failures, null otherwise.
 *
 */
public Result getBuildResult() {
    if (getFailCount() > 0) {
        return Result.UNSTABLE;
    } else {
        return null;
    }
}
 
Example 14
Source File: CardBuilderTest.java    From office-365-connector-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void getCompletedResult_ReturnsSuccess() {

    // given
    final Result result = Result.UNSTABLE;
    Run run = mock(Run.class);
    when(run.getResult()).thenReturn(result);

    // when
    Result completedResult = Deencapsulation.invoke(cardBuilder, "getCompletedResult", run);

    // then
    assertThat(completedResult).isEqualTo(result);
}
 
Example 15
Source File: CardBuilderTest.java    From office-365-connector-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void calculateSummary_OnUnstable_ReturnsUnstable() {

    // given
    Result lastResult = Result.UNSTABLE;
    boolean isRepeatedFailure = true;
    Result previousResult = null;

    // when
    String status = cardBuilder.calculateSummary(lastResult, previousResult, isRepeatedFailure);

    // then
    assertThat(status).isEqualTo("Unstable");
}
 
Example 16
Source File: CardBuilderTest.java    From office-365-connector-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void calculateStatus_OnUnstable_ReturnsUnstable() {

    // given
    Result lastResult = Result.UNSTABLE;
    boolean isRepeatedFailure = true;
    Result previousResult = null;

    // when
    String status = cardBuilder.calculateStatus(lastResult, previousResult, isRepeatedFailure);

    // then
    assertThat(status).isEqualTo("Build Unstable");
}
 
Example 17
Source File: DecisionMaker.java    From office-365-connector-plugin with Apache License 2.0 5 votes vote down vote up
private boolean isNotifyBackToNormal(Result result, Webhook webhook) {

        if (!webhook.isNotifyBackToNormal() || result != Result.SUCCESS) {
            return false;
        }

        Run previousBuild = findLastCompletedBuild();
        if (previousBuild == null) {
            return false;
        } else {
            Result previousResult = previousBuild.getResult();
            return (previousResult == Result.FAILURE || previousResult == Result.UNSTABLE);
        }
    }
 
Example 18
Source File: GitHubCommentPublisherDslContext.java    From github-integration-plugin with MIT License 4 votes vote down vote up
public void commentErrorIsUnstable() {
    errorHandler = new PublisherErrorHandler(Result.UNSTABLE);
}
 
Example 19
Source File: ZulipNotifier.java    From zulip-plugin with MIT License 4 votes vote down vote up
private boolean publish(@Nonnull Run<?, ?> build, @Nonnull TaskListener listener) throws InterruptedException {
    if (shouldPublish(build)) {
        String configuredTopic = ZulipUtil.getDefaultValue(topic, DESCRIPTOR.getTopic());
        Result result = getBuildResult(build);
        String changeString = "";
        try {
            changeString = getChangeSet(build);
        } catch (Exception e) {
            logger.log(Level.WARNING,
                    "Exception while computing changes since last build:\n"
                            + ExceptionUtils.getStackTrace(e));
            changeString += "\nError determining changes since last build - please contact [email protected].";
        }
        String resultString = result.toString();
        String message = "";
        // If we are sending to fixed topic, we will want to add project name into the message
        if (ZulipUtil.isValueSet(configuredTopic)) {
            message += hundsonUrlMesssage("Project: ", build.getParent().getDisplayName(), build.getParent().getUrl(), DESCRIPTOR) + " : ";
        }
        message += hundsonUrlMesssage("Build: ", build.getDisplayName(), build.getUrl(), DESCRIPTOR);
        message += ": ";
        message += "**" + resultString + "**";
        if (result == Result.SUCCESS) {
            message += " :check_mark:";
        }
        else if (result == Result.UNSTABLE) {
            message += " :warning:";
            AbstractTestResultAction testResultAction = build.getAction(AbstractTestResultAction.class);
            String failCount = testResultAction != null ? Integer.toString(testResultAction.getFailCount()) : "?";
            message += " (" + failCount + " broken tests)";
        } else {
            message += " :x:";
        }
        if (changeString.length() > 0) {
            message += "\n\n";
            message += changeString;
        }
        String destinationStream =
                ZulipUtil.expandVariables(build, listener, ZulipUtil.getDefaultValue(stream, DESCRIPTOR.getStream()));
        String destinationTopic = ZulipUtil.expandVariables(build, listener,
                ZulipUtil.getDefaultValue(configuredTopic, build.getParent().getDisplayName()));
        Zulip zulip = new Zulip(DESCRIPTOR.getUrl(), DESCRIPTOR.getEmail(), DESCRIPTOR.getApiKey());
        zulip.sendStreamMessage(destinationStream, destinationTopic, message);
    }
    return true;
}
 
Example 20
Source File: UnstableBuilder.java    From jenkins-test-harness with MIT License 4 votes vote down vote up
public UnstableBuilder() {
    super(Result.UNSTABLE);
}