Java Code Examples for hudson.model.Result#FAILURE

The following examples show how to use hudson.model.Result#FAILURE . 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: ShellScriptRunner.java    From DotCi with MIT License 6 votes vote down vote up
public Result runScript(final ShellCommands commands) throws IOException, InterruptedException {
    Result r = Result.FAILURE;
    //Todo: use VitualChannel to figure out OS
    final String shellInterpreter = Functions.isWindows() ? "sh" : "/bin/bash";
    final Run run = this.buildExecutionContext.getRun();
    addExecutionInfoAction(run, commands);
    try {
        final Shell execution = new Shell("#!" + shellInterpreter + " -le \n" + commands.toShellScript());
        if (this.buildExecutionContext.performStep(execution, this.listener)) {
            r = Result.SUCCESS;
        }
    } catch (final InterruptedException e) {
        r = Executor.currentExecutor().abortResult();
        throw e;
    } finally {
        this.buildExecutionContext.setResult(r);
    }
    return r;
}
 
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: CardBuilderTest.java    From office-365-connector-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void createCompletedCard_OnFirstFailure_ReturnsCard() {

    // given
    Result result = Result.FAILURE;
    when(run.getResult()).thenReturn(result);

    // when
    Card card = cardBuilder.createCompletedCard(Collections.emptyList());

    // then
    assertThat(card.getSections()).hasSize(1);
    assertThat(card.getThemeColor()).isEqualTo(result.color.getHtmlBaseColor());
    Section section = card.getSections().get(0);
    assertThat(section.getActivityTitle()).isEqualTo("Notification from " + JOB_DISPLAY_NAME);
}
 
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 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 5
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 6
Source File: OpenShiftImageStreams.java    From jenkins-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void postCheckout(@Nonnull Run<?, ?> build,
        @Nonnull Launcher launcher, @Nonnull FilePath workspace,
        @Nonnull TaskListener listener) throws IOException,
        InterruptedException {
    if (build.getResult() == Result.FAILURE) {
        EnvVars env = build.getEnvironment(listener);
        String msg = String.format(
                MessageConstants.SCM_IMAGESTREAM_NOT_FOUND,
                getImageStreamName(env), getTag(env));
        throw new AbortException(msg);
    }
}
 
Example 7
Source File: CardBuilder.java    From office-365-connector-plugin with Apache License 2.0 5 votes vote down vote up
public Card createCompletedCard(List<FactDefinition> factDefinitions) {
    // result might be null only for ongoing job - check documentation of Run.getCompletedResult()
    // but based on issue #133 it may happen that result for completed job is null
    Result lastResult = getCompletedResult(run);

    Run previousBuild = run.getPreviousBuild();
    Result previousResult = previousBuild != null ? previousBuild.getResult() : Result.SUCCESS;
    Run lastNotFailedBuild = run.getPreviousNotFailedBuild();

    boolean isRepeatedFailure = isRepeatedFailure(previousResult, lastNotFailedBuild);
    String summary = String.format("%s: Build %s %s", getDisplayName(), getRunName(),
            calculateSummary(lastResult, previousResult, isRepeatedFailure));
    String status = calculateStatus(lastResult, previousResult, isRepeatedFailure);

    if (lastResult == Result.FAILURE) {
        Run failingSinceBuild = getFailingSinceBuild(lastNotFailedBuild);

        if (failingSinceBuild != null && previousResult == Result.FAILURE) {
            factsBuilder.addFailingSinceBuild(failingSinceBuild.getNumber());
        }
    }
    factsBuilder.addStatus(status);
    factsBuilder.addRemarks();
    factsBuilder.addCommitters();
    factsBuilder.addDevelopers();
    factsBuilder.addUserFacts(factDefinitions);

    Section section = buildSection();

    Card card = new Card(summary, section);
    card.setThemeColor(getCardThemeColor(lastResult));
    card.setPotentialAction(potentialActionBuilder.buildActionable());

    return card;
}
 
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 calculateSummary_OnSuccessWithRepeatedFailure_ReturnsRepeatedFailure() {

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

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

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

    // given
    Result lastResult = Result.FAILURE;
    boolean isRepeatedFailure = false;
    Result previousResult = null;

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

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

    // given
    Result result = Result.FAILURE;
    when(run.getResult()).thenReturn(result);

    AbstractBuild previousBuild = mock(AbstractBuild.class);
    when(previousBuild.getResult()).thenReturn(Result.FAILURE);
    when(run.getPreviousBuild()).thenReturn(previousBuild);

    Run previousNotFailedBuild = mock(Run.class);
    int previousNotFailedBuildNumber = BUILD_NUMBER - 3;
    when(previousNotFailedBuild.getNumber()).thenReturn(previousNotFailedBuildNumber);
    when(previousNotFailedBuild.getNextBuild()).thenReturn(previousNotFailedBuild);
    when(run.getPreviousNotFailedBuild()).thenReturn(previousNotFailedBuild);

    // when
    Card card = cardBuilder.createCompletedCard(Collections.emptyList());

    // then
    assertThat(card.getSections()).hasSize(1);
    assertThat(card.getThemeColor()).isEqualTo(result.color.getHtmlBaseColor());
    Section section = card.getSections().get(0);
    assertThat(section.getActivityTitle()).isEqualTo("Notification from " + JOB_DISPLAY_NAME);
    FactAssertion.assertThatLast(section.getFacts(), 2)
            .hasName(FactsBuilder.NAME_FAILING_SINCE_BUILD)
            .hasValue("build #" + previousNotFailedBuildNumber);
}
 
Example 11
Source File: CardBuilderTest.java    From office-365-connector-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void calculateStatus_OnFailure_ReturnsBuildFailure() {

    // given
    Result lastResult = Result.FAILURE;
    boolean isRepeatedFailure = false;
    Result previousResult = null;

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

    // then
    assertThat(status).isEqualTo("Build Failed");
}
 
Example 12
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 13
Source File: BuildChain.java    From build-notifications-plugin with MIT License 4 votes vote down vote up
public static BuildChain failed() {
  return new BuildChain(Result.FAILURE);
}
 
Example 14
Source File: FailureBuilder.java    From jenkins-test-harness with MIT License 4 votes vote down vote up
public FailureBuilder() {
    super(Result.FAILURE);
}
 
Example 15
Source File: JUnitResultArchiver.java    From junit-plugin with MIT License 4 votes vote down vote up
public static TestResultAction parseAndAttach(@Nonnull JUnitTask task, PipelineTestDetails pipelineTestDetails,
                                              Run build, FilePath workspace, Launcher launcher, TaskListener listener)
        throws InterruptedException, IOException {
    listener.getLogger().println(Messages.JUnitResultArchiver_Recording());

    final String testResults = build.getEnvironment(listener).expand(task.getTestResults());

    TestResult result = parse(task, pipelineTestDetails, testResults, build, workspace, launcher, listener);

    synchronized (build) {
        // TODO can the build argument be omitted now, or is it used prior to the call to addAction?
        TestResultAction action = build.getAction(TestResultAction.class);
        boolean appending;
        if (action == null) {
            appending = false;
            action = new TestResultAction(build, result, listener);
        } else {
            appending = true;
            result.freeze(action);
            action.mergeResult(result, listener);
        }
        action.setHealthScaleFactor(task.getHealthScaleFactor()); // overwrites previous value if appending
        if (result.isEmpty()) {
            if (build.getResult() == Result.FAILURE) {
                // most likely a build failed before it gets to the test phase.
                // don't report confusing error message.
                return null;
            }
            if (task.isAllowEmptyResults()) {
                // User allow empty results
                listener.getLogger().println(Messages.JUnitResultArchiver_ResultIsEmpty());
                return null;
            }
            // most likely a configuration error in the job - e.g. false pattern to match the JUnit result files
            throw new AbortException(Messages.JUnitResultArchiver_ResultIsEmpty());
        }

        // TODO: Move into JUnitParser [BUG 3123310]
        if (task.getTestDataPublishers() != null) {
            for (TestDataPublisher tdp : task.getTestDataPublishers()) {
                Data d = tdp.contributeTestData(build, workspace, launcher, listener, result);
                if (d != null) {
                    action.addData(d);
                }
            }
        }

        if (appending) {
            build.save();
        } else {
            build.addAction(action);
        }

        return action;
    }
}
 
Example 16
Source File: AWSCodeDeployPublisher.java    From aws-codedeploy-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public void perform(@Nonnull Run<?,?> build, @Nonnull FilePath workspace, @Nonnull Launcher launcher, @Nonnull TaskListener listener) throws IOException, InterruptedException {
    this.logger = listener.getLogger();
    envVars = build.getEnvironment(listener);
    final boolean buildFailed = build.getResult() == Result.FAILURE;
    if (buildFailed) {
        logger.println("Skipping CodeDeploy publisher as build failed");
        return;
    }

    final AWSClients aws;
    if ("awsAccessKey".equals(credentials)) {
        if (StringUtils.isEmpty(this.awsAccessKey) && StringUtils.isEmpty(this.awsSecretKey)) {
            aws = AWSClients.fromDefaultCredentialChain(
                    this.region,
                    this.proxyHost,
                    this.proxyPort);
        } else {
            aws = AWSClients.fromBasicCredentials(
                    this.region,
                    this.awsAccessKey,
                    this.awsSecretKey,
                    this.proxyHost,
                    this.proxyPort);
        }
    } else {
        aws = AWSClients.fromIAMRole(
            this.region,
            this.iamRoleArn,
            this.getDescriptor().getExternalId(),
            this.proxyHost,
            this.proxyPort);
    }

    boolean success = false;

    try {

        verifyCodeDeployApplication(aws);

        final String projectName = build.getDisplayName();
        if (workspace == null) {
            throw new IllegalArgumentException("No workspace present for the build.");
        }

        RevisionLocation revisionLocation;

        if (!StringUtils.isEmpty(this.githubRepository) && !StringUtils.isEmpty(this.githubCommitId)) {
          revisionLocation = createFromGitHub();
        } else {
          final FilePath sourceDirectory = getSourceDirectory(workspace);
          revisionLocation = zipAndUpload(aws, projectName, sourceDirectory);
        }

        registerRevision(aws, revisionLocation);
        if ("onlyRevision".equals(deploymentMethod)){
          success = true;
        } else {

          String deploymentId = createDeployment(aws, revisionLocation);

          success = waitForDeployment(aws, deploymentId);
        }

    } catch (Exception e) {

        this.logger.println("Failed CodeDeploy post-build step; exception follows.");
        this.logger.println(e.getMessage());
        e.printStackTrace(this.logger);
    }

    if (!success) {
        throw new AbortException();
    }
}
 
Example 17
Source File: CardBuilder.java    From office-365-connector-plugin with Apache License 2.0 4 votes vote down vote up
private boolean isRepeatedFailure(Result previousResult, Run lastNotFailedBuild) {
    Run failingSinceRun = getFailingSinceBuild(lastNotFailedBuild);

    return failingSinceRun != null && previousResult == Result.FAILURE;
}
 
Example 18
Source File: GitHubCommentPublisherDslContext.java    From github-integration-plugin with MIT License 4 votes vote down vote up
public void onlyFailedBuilds() {
    verifier = new StatusVerifier(Result.FAILURE);
}
 
Example 19
Source File: DecisionMaker.java    From office-365-connector-plugin with Apache License 2.0 4 votes vote down vote up
private boolean isNotifyRepeatedFailure(Result result, Webhook webhook) {
    return webhook.isNotifyRepeatedFailure()
            && result == Result.FAILURE
            && previousResult == Result.FAILURE;
}
 
Example 20
Source File: DecisionMaker.java    From office-365-connector-plugin with Apache License 2.0 4 votes vote down vote up
private boolean isNotifyFailure(Result result, Webhook webhook) {
    return webhook.isNotifyFailure()
            && result == Result.FAILURE
            && previousResult != Result.FAILURE;
}