Java Code Examples for hudson.model.Run#getActions()

The following examples show how to use hudson.model.Run#getActions() . 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: ResetQualityGateCommand.java    From warnings-ng-plugin with MIT License 6 votes vote down vote up
/**
 * Returns whether the command to reset the quality gate for the specified analysis tool is enabled or not.
 *
 * @param selectedBuild
 *         the selected build that will show the action link
 * @param id
 *         the ID of the static analysis tool that should be reset
 *
 * @return {@code true} if the command is enabled, {@code false} otherwise
 */
public boolean isEnabled(final Run<?, ?> selectedBuild, final String id) {
    if (!jenkinsFacade.hasPermission(Item.CONFIGURE)) {
        return false;
    }

    if (selectedBuild.getNextBuild() != null) {
        return false;
    }

    List<ResetReferenceAction> actions = selectedBuild.getActions(ResetReferenceAction.class);
    if (actions.stream().map(ResetReferenceAction::getId).anyMatch(id::equals)) {
        return false;
    }

    Optional<ResultAction> resultAction = selectedBuild.getActions(ResultAction.class)
            .stream()
            .filter(action -> action.getId().equals(id))
            .findAny();
    if (!resultAction.isPresent()) {
        return false;
    }

    QualityGateStatus status = resultAction.get().getResult().getQualityGateStatus();
    return status == QualityGateStatus.FAILED || status == QualityGateStatus.WARNING;
}
 
Example 2
Source File: IssuesPublisher.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
private QualityGateEvaluationMode determineQualityGateEvaluationMode(final Report filtered) {
    Run<?, ?> previous = run.getPreviousCompletedBuild();
    if (previous != null) {
        List<ResetReferenceAction> actions = previous.getActions(ResetReferenceAction.class);
        for (ResetReferenceAction action : actions) {
            if (report.getId().equals(action.getId())) {
                filtered.logInfo("Resetting reference build, ignoring quality gate result for one build");

                return IGNORE_QUALITY_GATE;
            }
        }
    }
    return qualityGateEvaluationMode;
}
 
Example 3
Source File: ByIdResultSelector.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
@Override
public Optional<ResultAction> get(final Run<?, ?> build) {
    List<ResultAction> actions = build.getActions(ResultAction.class);
    for (ResultAction action : actions) {
        if (id.equals(action.getId())) {
            return Optional.of(action);
        }
    }
    return Optional.empty();
}
 
Example 4
Source File: StepsITest.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
/**
 * Creates a JenkinsFile with parallel steps and aggregates the warnings.
 */
@Test
public void shouldRecordOutputOfParallelSteps() {
    WorkflowJob job = createPipeline();

    copySingleFileToAgentWorkspace(createAgent("node1"), job, "eclipse.txt", "issues.txt");
    copySingleFileToAgentWorkspace(createAgent("node2"), job, "eclipse.txt", "issues.txt");

    job.setDefinition(readJenkinsFile("parallel.jenkinsfile"));

    Run<?, ?> run = buildSuccessfully(job);
    List<ResultAction> actions = run.getActions(ResultAction.class);

    assertThat(actions).hasSize(2);

    ResultAction first;
    ResultAction second;
    if (actions.get(0).getId().equals("java-1")) {
        first = actions.get(0);
        second = actions.get(1);
    }
    else {
        first = actions.get(1);
        second = actions.get(0);
    }

    assertThat(first.getResult().getIssues()).hasSize(5);
    assertThat(second.getResult().getIssues()).hasSize(3);
}
 
Example 5
Source File: HTMLArtifact.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@Override
public Collection<BlueArtifact> getArtifacts(Run<?, ?> run, Reachable parent) {
    List<HtmlPublisherTarget.HTMLBuildAction> actions = run.getActions(HtmlPublisherTarget.HTMLBuildAction.class);
    if (actions.isEmpty()) {
        return null;
    }
    return actions.stream()
        .map( action -> new HTMLArtifact(action, parent.getLink()))
        .collect(Collectors.toList());
}
 
Example 6
Source File: FakeChangeLogSCM.java    From jenkins-test-harness with MIT License 5 votes vote down vote up
@SuppressWarnings("rawtypes")
@Override
public FakeChangeLogSet parse(Run build, RepositoryBrowser<?> browser, File changelogFile) throws IOException, SAXException {
    for (ChangelogAction action : build.getActions(ChangelogAction.class)) {
        if (changelogFile.getName().equals(action.changeLogFile)) {
            return new FakeChangeLogSet(build, action.entries);
        }
    }
    return new FakeChangeLogSet(build, Collections.emptyList());
}
 
Example 7
Source File: BuildUtil.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
public static Run<?, ?> getBuildBySHA1WithoutMergeBuilds(Job<?, ?> project, String sha1) {
    for (Run<?, ?> build : project.getBuilds()) {
        MergeRecord merge = build.getAction(MergeRecord.class);
        for(BuildData data : build.getActions(BuildData.class)) {
            if (hasLastBuild(data) && isNoMergeBuild(data, merge) && data.lastBuild.isFor(sha1)) {
                return build;
            }
        }
    }
    return null;
}
 
Example 8
Source File: BuildUtil.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
public static Run<?, ?> getBuildBySHA1IncludingMergeBuilds(Job<?, ?> project, String sha1) {
    for (Run<?, ?> build : project.getBuilds()) {
        for(BuildData data : build.getActions(BuildData.class)) {
            if (data != null
                && data.lastBuild != null
                && data.lastBuild.getMarked() != null
                && data.lastBuild.getMarked().getSha1String().equals(sha1)) {
                return build;
            }
        }
    }
    return null;
}
 
Example 9
Source File: DockerRunListener.java    From docker-plugin with MIT License 5 votes vote down vote up
@Override
public void onDeleted(Run<?, ?> run) {
    super.onDeleted(run);
    List<DockerBuildImageAction> actions = run.getActions(DockerBuildImageAction.class);
    for(DockerBuildImageAction action : actions) {
        if( action.cleanupWithJenkinsJobDelete ) {
            LOGGER.info("Attempting to clean up docker image for " + run);
            if( action.pushOnSuccess ) {

                // TODO:

                /*
                DockerRegistryClient registryClient;

                try {

                    Identifier identifier = Identifier.fromCompoundString(action.taggedId);

                    registryClient = DockerRegistryClient.builder()
                            .withUrl(identifier.repository.getURL())
                            .build();

                    registryClient.registryApi().deleteRepositoryTag("library",
                            identifier.repository.getPath(),
                            identifier.tag.orNull());



                } catch (Exception ex) {

                    LOGGER.log(Level.WARNING, "Failed to clean up", ex);
                }
                      */
            }
        }
    }
}
 
Example 10
Source File: DockerBuilderControlOption.java    From docker-plugin with MIT License 5 votes vote down vote up
/**
 * @return first DockerLaunchAction attached to build
 */
protected DockerLaunchAction getLaunchAction(Run<?, ?> build) {
    List<DockerLaunchAction> launchActionList = build.getActions(DockerLaunchAction.class);
    DockerLaunchAction launchAction;
    if (launchActionList.size() > 0 ) {
        launchAction = launchActionList.get(0);
    } else {
        launchAction = new DockerLaunchAction();
        build.addAction(launchAction);
    }
    return launchAction;
}
 
Example 11
Source File: AutogradingPluginITest.java    From warnings-ng-plugin with MIT License 4 votes vote down vote up
/**
 * Ensures that the autographing plugin outputs the expected score after passing the checks.
 * Used tools: CheckStyle, SpotBugs, CPD, and PMD.
 */
@Test
public void checksCorrectGradingWithSeveralTools() {
    FreeStyleProject project = createFreeStyleProjectWithWorkspaceFiles("checkstyle.xml", "spotbugs.xml", "cpd.xml", "pmd.xml");

    IssuesRecorder recorder = new IssuesRecorder();

    CheckStyle checkStyle = new CheckStyle();
    checkStyle.setPattern("**/*checkstyle*");

    SpotBugs spotBugs = new SpotBugs();
    spotBugs.setPattern("**/spotbugs*");

    Cpd cpd = new Cpd();
    cpd.setPattern("**/cpd*");

    Pmd pmd = new Pmd();
    pmd.setPattern("**/pmd*");

    recorder.setTools(checkStyle, spotBugs, cpd, pmd);

    project.getPublishersList().add(recorder);
    project.getPublishersList().add(new AutoGrader(AUTOGRADER_RESULT));

    Run<?, ?> baseline = buildSuccessfully(project);

    List<AutoGradingBuildAction> actions = baseline.getActions(AutoGradingBuildAction.class);
    assertThat(actions).hasSize(1);
    List<ResultAction> analysisActions = baseline.getActions(ResultAction.class);

    AggregatedScore score = actions.get(0).getResult();
    List<AnalysisScore> analysisScore = score.getAnalysisScores();
    assertThat(score.getAchieved()).isEqualTo(22);

    assertThat(analysisScore).hasSize(4);

    ResultAction checkStyleAction = analysisActions.get(0);
    assertThat(checkStyleAction.getId()).isEqualTo(CHECKSTYLE);
    assertThat(checkStyleAction.getResult()).hasTotalErrorsSize(6);
    assertThat(analysisScore.get(0).getId()).isEqualTo(CHECKSTYLE);
    assertThat(analysisScore.get(0).getTotalImpact()).isEqualTo(-60);

    ResultAction spotBugsAction = analysisActions.get(1);
    assertThat(spotBugsAction.getId()).isEqualTo(SPOTBUGS);
    assertThat(spotBugsAction.getResult()).hasTotalNormalPrioritySize(2);
    assertThat(analysisScore.get(1).getId()).isEqualTo(SPOTBUGS);
    assertThat(analysisScore.get(1).getTotalImpact()).isEqualTo(-4);

    ResultAction cpdAction = analysisActions.get(2);
    assertThat(cpdAction.getId()).isEqualTo(CPD);
    assertThat(cpdAction.getResult()).hasTotalLowPrioritySize(2);
    assertThat(analysisScore.get(2).getId()).isEqualTo(CPD);
    assertThat(analysisScore.get(2).getTotalImpact()).isEqualTo(-2);

    ResultAction pmdAction = analysisActions.get(3);
    assertThat(pmdAction.getId()).isEqualTo(PMD);
    assertThat(pmdAction.getResult()).hasTotalErrorsSize(1);
    assertThat(pmdAction.getResult()).hasTotalNormalPrioritySize(1);
    assertThat(analysisScore.get(3).getId()).isEqualTo(PMD);
    assertThat(analysisScore.get(3).getTotalImpact()).isEqualTo(-12);
}
 
Example 12
Source File: IntegrationTest.java    From warnings-ng-plugin with MIT License 2 votes vote down vote up
/**
 * Returns the created {@link AnalysisResult analysis results} of a build.
 *
 * @param build
 *         the run that has the actions attached
 *
 * @return the created results
 */
protected List<AnalysisResult> getAnalysisResults(final Run<?, ?> build) {
    List<ResultAction> actions = build.getActions(ResultAction.class);

    return actions.stream().map(ResultAction::getResult).collect(Collectors.toList());
}