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

The following examples show how to use hudson.model.Run#getAction() . 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: TestResultProjectAction.java    From junit-plugin with MIT License 6 votes vote down vote up
public AbstractTestResultAction getLastTestResultAction() {
    final Run<?,?> tb = job.getLastSuccessfulBuild();

    Run<?,?> b = job.getLastBuild();
    while(b!=null) {
        AbstractTestResultAction a = b.getAction(AbstractTestResultAction.class);
        if(a!=null && (!b.isBuilding())) return a;
        if(b==tb)
            // if even the last successful build didn't produce the test result,
            // that means we just don't have any tests configured.
            return null;
        b = b.getPreviousBuild();
    }

    return null;
}
 
Example 2
Source File: AnchoreProjectAction.java    From anchore-container-scanner-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * @return the most current AnchoreAction of the associated job
 */
public AnchoreAction getLastAnchoreAction() {
  final Run<?,?> tb = this.job.getLastSuccessfulBuild();

  Run<?,?> b = this.job.getLastBuild();
  while (b != null) {
    AnchoreAction a = b.getAction(AnchoreAction.class);
    if (a != null && (!b.isBuilding())) {
      return a;
    }
    if (b == tb) {
      // no Anchore result available
      return null;
    }
    b = b.getPreviousBuild();
  }
  return null;
}
 
Example 3
Source File: CoverageStatus.java    From jenkins-status-badges-plugin with MIT License 6 votes vote down vote up
public int getCoverage( Job<?, ?> project )
{
    Run<?, ?> lastBuild = project.getLastBuild();
    CloverBuildAction cloverAction;
    CoberturaBuildAction coberturaAction;
    int percentage;
    try
    {
        cloverAction = lastBuild.getAction( hudson.plugins.clover.CloverBuildAction.class );
        percentage = cloverAction.getResult().getElementCoverage().getPercentage();
    }
    catch ( Exception cloverE )
    {
        try
        {
            coberturaAction = lastBuild.getAction( hudson.plugins.cobertura.CoberturaBuildAction.class );
            percentage = coberturaAction.getResult().getCoverage( CoverageMetric.LINE ).getPercentage();
        }
        catch ( Exception coberturaE )
        {
            return -1;
        }
    }
    return percentage;
}
 
Example 4
Source File: GithubNotificationConfig.java    From github-autostatus-plugin with MIT License 6 votes vote down vote up
/**
 * Extracts the branch info from a build.
 *
 * @param build the build
 * @return true if branch info was extracted; false otherwise
 */
private Boolean extractBranchInfo(Run<?, ?> build) {
    SCMRevisionAction scmRevisionAction = build.getAction(SCMRevisionAction.class);
    if (null == scmRevisionAction) {
        return false;
    }
    SCMRevision revision = scmRevisionAction.getRevision();
    if (revision instanceof AbstractGitSCMSource.SCMRevisionImpl) {
        branchName = ((AbstractGitSCMSource.SCMRevisionImpl) revision).getHead().getName();
    } else if (revision instanceof PullRequestSCMRevision) {
        PullRequestSCMHead pullRequestSCMHead = (PullRequestSCMHead) ((PullRequestSCMRevision) revision).getHead();

        branchName = pullRequestSCMHead.getSourceBranch();
    }
    return true;
}
 
Example 5
Source File: DeflakeListener.java    From flaky-test-handler-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public void onCompleted(Run run, TaskListener listener) {
  // TODO consider the possibility that there is >1 such action
  TestResultAction testResultAction = run.getAction(TestResultAction.class);

  HistoryAggregatedFlakyTestResultAction historyAction = run.getParent()
      .getAction(HistoryAggregatedFlakyTestResultAction.class);

  // Aggregate test running results
  if (historyAction != null) {
    historyAction.aggregateOneBuild(run);
  }

  if (testResultAction != null && testResultAction.getFailCount() > 0) {
    // Only add deflake action if there are test failures
    run.addAction(
        new DeflakeAction(getFailingTestClassMethodMap(testResultAction.getFailedTests())));
  }
}
 
Example 6
Source File: DockerComposeBuild.java    From DotCi with MIT License 5 votes vote down vote up
private void addProcessedYamlToDotCiInfoAction(final Run run, final Map config) throws IOException {
    final DotCiBuildInfoAction dotCiBuildInfoAction = run.getAction(DotCiBuildInfoAction.class);
    if (dotCiBuildInfoAction == null) {
        run.addAction(new DotCiBuildInfoAction(new Yaml().dump(config)));
    } else {
        dotCiBuildInfoAction.setBuildConfiguration(new Yaml().dump(config));
    }
    run.save();
}
 
Example 7
Source File: QualityGateITest.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
@SuppressWarnings("illegalcatch")
private void scheduleBuildAndAssertStatus(final AbstractProject<?, ?> job, final Result result,
        final QualityGateStatus qualityGateStatus) {
    try {
        Run<?, ?> build = getJenkins().assertBuildStatus(result, job.scheduleBuild2(0));
        ResultAction action = build.getAction(ResultAction.class);
        assertThat(action.getResult()).hasQualityGateStatus(qualityGateStatus);
    }
    catch (Exception e) {
        throw new AssertionError(e);
    }
}
 
Example 8
Source File: AbstractRunImpl.java    From blueocean-plugin with MIT License 5 votes vote down vote up
static Collection<BlueCause> getCauses(Run run) {
    CauseAction action = run.getAction(CauseAction.class);
    if (action == null) {
        return null;
    }
    return getCauses(action.getCauses());
}
 
Example 9
Source File: JUnitResultsStepTest.java    From junit-plugin with MIT License 5 votes vote down vote up
private void assertExpectedResults(Run<?,?> run, int suiteCount, int testCount, String... nodeIds) throws Exception {
    TestResultAction action = run.getAction(TestResultAction.class);
    assertNotNull(action);

    TestResult result = action.getResult().getResultByNodes(Arrays.asList(nodeIds));
    assertNotNull(result);
    assertEquals(suiteCount, result.getSuites().size());
    assertEquals(testCount, result.getTotalCount());
}
 
Example 10
Source File: TestResult.java    From junit-plugin with MIT License 5 votes vote down vote up
/**
 * Gets the counter part of this {@link TestResult} in the specified run.
 *
 * @return null if no such counter part exists.
 */
@Override public TestResult getResultInRun(Run<?,?> build) {
    AbstractTestResultAction tra = build.getAction(getParentAction().getClass());
    if (tra == null) {
        tra = build.getAction(AbstractTestResultAction.class);
    }
    return (tra == null) ? null : tra.findCorrespondingResult(this.getId());
}
 
Example 11
Source File: GitLabSCMRunListener.java    From gitlab-branch-source-plugin with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onStarted(Run<?, ?> build, TaskListener listener) {
    GitLabSCMHeadMetadataAction metadata = getMetadataAction(build);
    GitLabSCMPublishAction publishAction = build.getParent().getAction(GitLabSCMPublishAction.class);
    if (metadata != null && publishAction != null) {
        GitLabSCMCauseAction cause = build.getAction(GitLabSCMCauseAction.class);
        String description = (cause != null) ? cause.getDescription() : "";
        publishAction.updateBuildDescription(build, description, listener);
        publishAction.publishStarted(build, metadata, description);
    }
}
 
Example 12
Source File: GithubNotificationConfig.java    From github-autostatus-plugin with MIT License 5 votes vote down vote up
/**
 * Extracts the SHA for the build.
 *
 * @param build the build
 * @return true if SHA was extracted; false if it could not be extracted
 */
private Boolean extractCommitSha(Run<?, ?> build) {
    SCMRevisionAction scmRevisionAction = build.getAction(SCMRevisionAction.class);
    if (null == scmRevisionAction) {
        log(Level.INFO, "Could not find commit sha - status will not be provided for this build");
        return false;
    }
    SCMRevision revision = scmRevisionAction.getRevision();
    if (revision instanceof AbstractGitSCMSource.SCMRevisionImpl) {
        this.shaString = ((AbstractGitSCMSource.SCMRevisionImpl) revision).getHash();
    } else if (revision instanceof PullRequestSCMRevision) {
        this.shaString = ((PullRequestSCMRevision) revision).getPullHash();
    }
    return true;
}
 
Example 13
Source File: GithubBuildStatusGraphListener.java    From github-autostatus-plugin with MIT License 5 votes vote down vote up
private static @CheckForNull BuildStatusAction buildStatusActionFor(FlowExecution exec) {
    BuildStatusAction buildStatusAction = null;
    Run<?, ?> run = runFor(exec);
    if (run != null) {
        buildStatusAction = run.getAction(BuildStatusAction.class);
    }
    return buildStatusAction;
}
 
Example 14
Source File: ResourceVariableNameAction.java    From lockable-resources-plugin with MIT License 5 votes vote down vote up
@Override
public void buildEnvironmentFor(Run r, EnvVars envs, TaskListener listener)
		throws IOException, InterruptedException {
	ResourceVariableNameAction a = r.getAction(ResourceVariableNameAction.class);
	if (a != null && a.getParameter() != null && a.getParameter().getValue() != null) {
		envs.put(a.getParameter().getName(), String.valueOf(a.getParameter().getValue()));
	}
}
 
Example 15
Source File: BuildQueueListener.java    From github-autostatus-plugin with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void onLeaveBlocked(Queue.BlockedItem item) {
    if (!(item.task instanceof ExecutorStepExecution.PlaceholderTask)) {
        return;
    }
    Run run = ((ExecutorStepExecution.PlaceholderTask) item.task).run();

    if (run != null) {
        BuildBlockedAction action = run.getAction(BuildBlockedAction.class);
        if (action != null) {
            action.setTimeReleased(System.currentTimeMillis());
        }
    }
}
 
Example 16
Source File: AWSDeviceFarmUtils.java    From aws-device-farm-jenkins-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the most recent AWS Device Farm test result from the previous build.
 *
 * @param job The job which generated an AWS Device Farm test result
 * @return The previous Device Farm build result.
 */
public static AWSDeviceFarmTestResult previousAWSDeviceFarmBuildResult(Job job) {
    Run prev = job.getLastCompletedBuild();
    if (prev == null) {
        return null;
    }
    AWSDeviceFarmTestResultAction action = prev.getAction(AWSDeviceFarmTestResultAction.class);
    if (action == null) {
        return null;
    }
    return action.getResult();
}
 
Example 17
Source File: AggregatedTestResultAction.java    From junit-plugin with MIT License 4 votes vote down vote up
/**
 * Uses {@link #resolveChild(Child)} and obtain the
 * {@link AbstractTestResultAction} object for the given child.
 */
protected AbstractTestResultAction getChildReport(Child child) {
    Run<?,?> b = resolveRun(child);
    if(b==null) return null;
    return b.getAction(AbstractTestResultAction.class);
}
 
Example 18
Source File: HistoryAggregatedFlakyTestResultActionTest.java    From flaky-test-handler-plugin with Apache License 2.0 4 votes vote down vote up
@Test
public void testAggregate() throws Exception {
  FreeStyleProject project = jenkins.createFreeStyleProject("project");
  List<FlakyTestResultAction> flakyTestResultActions = setUpFlakyTestResultAction();

  List<FlakyTestResultAction> flakyTestResultActionList = new ArrayList<FlakyTestResultAction>(
      flakyTestResultActions);

  // First non-deflake build
  Run firstBuild = project
      .scheduleBuild2(0, flakyTestResultActionList.get(0)).get();
  while (firstBuild.isBuilding()) {
    Thread.sleep(100);
  }

  // Second deflake build
  Run secondBuild = project
      .scheduleBuild2(0, flakyTestResultActionList.get(1),
          new CauseAction(new DeflakeCause(firstBuild))).get();
  while (secondBuild.isBuilding()) {
    Thread.sleep(100);
  }

  // Third deflake build with HistoryAggregatedFlakyTestResultAction
  Run thirdBuild = project
      .scheduleBuild2(0, flakyTestResultActionList.get(2),
          new HistoryAggregatedFlakyTestResultAction(project)).get();
  while (thirdBuild.isBuilding()) {
    Thread.sleep(100);
  }

  HistoryAggregatedFlakyTestResultAction action = thirdBuild
      .getAction(HistoryAggregatedFlakyTestResultAction.class);
  action.aggregate();

  Map<String, SingleTestFlakyStats> aggregatedFlakyStatsMap = action.getAggregatedFlakyStats();

  // Make sure revisions are inserted in the order of their appearance
  Map<String, SingleTestFlakyStats> revisionMap = action.getAggregatedTestFlakyStatsWithRevision()
      .get(TEST_ONE);
  assertArrayEquals("Incorrect revision history", new String[]{REVISION_ONE, REVISION_TWO},
      revisionMap.keySet().toArray(new String[revisionMap.size()]));

  assertEquals("wrong number of entries for flaky stats", 4, aggregatedFlakyStatsMap.size());

  SingleTestFlakyStats testOneStats = aggregatedFlakyStatsMap.get(TEST_ONE);
  SingleTestFlakyStats testTwoStats = aggregatedFlakyStatsMap.get(TEST_TWO);
  SingleTestFlakyStats testThreeStats = aggregatedFlakyStatsMap.get(TEST_THREE);
  SingleTestFlakyStats testFourStats = aggregatedFlakyStatsMap.get(TEST_FOUR);

  assertEquals("wrong number passes", 1, testOneStats.getPass());
  assertEquals("wrong number fails", 0, testOneStats.getFail());
  assertEquals("wrong number flakes", 1, testOneStats.getFlake());

  assertEquals("wrong number passes", 1, testTwoStats.getPass());
  assertEquals("wrong number fails", 0, testTwoStats.getFail());
  assertEquals("wrong number flakes", 1, testTwoStats.getFlake());

  assertEquals("wrong number passes", 0, testThreeStats.getPass());
  assertEquals("wrong number fails", 1, testThreeStats.getFail());
  assertEquals("wrong number flakes", 1, testThreeStats.getFlake());

  assertEquals("wrong number passes", 1, testFourStats.getPass());
  assertEquals("wrong number fails", 0, testFourStats.getFail());
  assertEquals("wrong number flakes", 1, testFourStats.getFlake());
}
 
Example 19
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 20
Source File: IntegrationTest.java    From warnings-ng-plugin with MIT License 2 votes vote down vote up
/**
 * Returns the {@link ResultAction} for the specified run. Note that this method does only return the first match,
 * even if a test registered multiple actions.
 *
 * @param build
 *         the build
 *
 * @return the action of the specified build
 */
protected ResultAction getResultAction(final Run<?, ?> build) {
    ResultAction action = build.getAction(ResultAction.class);
    assertThat(action).as("No ResultAction found in run %s", build).isNotNull();
    return action;
}