/**
  * Tests with no extensions.
  *
  * @throws IOException IOException
  * @throws InterruptedException InterruptedException
  * @throws ExecutionException ExecutionException
  */
 public void testNoRebuildValidatorExtension()
     throws IOException, InterruptedException, ExecutionException {
   Project projectA = createFreeStyleProject("testFreeStyleA");
   Build buildA =
       (Build)
           projectA
               .scheduleBuild2(
                   0,
                   new Cause.UserIdCause(),
                   new ParametersAction(new StringParameterValue("party", "megaparty")))
               .get();
   assertNotNull(buildA.getAction(RebuildAction.class));
 }
 /**
  * Tests with an extension returning isApplicable false.
  *
  * @throws IOException IOException
  * @throws InterruptedException InterruptedException
  * @throws ExecutionException ExecutionException
  */
 public void testRebuildValidatorExtensionIsApplicableFalse()
     throws IOException, InterruptedException, ExecutionException {
   hudson.getExtensionList(RebuildValidator.class).add(0, new ValidatorNeverApplicable());
   Project projectA = createFreeStyleProject("testFreeStyleC");
   Build buildA =
       (Build)
           projectA
               .scheduleBuild2(
                   0,
                   new Cause.UserIdCause(),
                   new ParametersAction(new StringParameterValue("party", "megaparty")))
               .get();
   assertNotNull(buildA.getAction(RebuildAction.class));
 }
  public void testAnt() throws Exception {
    Ant.AntInstallation ant = configureDefaultAnt();
    String antPath = ant.getHome();
    Jenkins.getInstance()
        .getDescriptorByType(Ant.DescriptorImpl.class)
        .setInstallations(new AntInstallation("ant", "THIS IS WRONG"));

    project.setScm(new SingleFileSCM("build.xml", "<project name='foo'/>"));
    project.getBuildersList().add(new Ant("-version", "ant", null, null, null));
    configureDumpEnvBuilder();

    Build build = project.scheduleBuild2(0).get();
    assertBuildStatus(Result.FAILURE, build);

    ToolLocationNodeProperty property =
        new ToolLocationNodeProperty(
            new ToolLocationNodeProperty.ToolLocation(
                jenkins.getDescriptorByType(AntInstallation.DescriptorImpl.class), "ant", antPath));
    slave.getNodeProperties().add(property);

    build = project.scheduleBuild2(0).get();
    System.out.println(build.getLog());
    assertBuildStatus(Result.SUCCESS, build);
  }
 @Test
 public void errorDropdownIsPresentAndIsNotEmpty() throws Exception {
   JenkinsRule.WebClient wc = j.createWebClient();
   wc.login("user1", "user1");
   HtmlPage page = wc.goTo("job/x/" + build.getNumber());
   page.getElementById("claim").click();
   HtmlForm form = page.getFormByName("claim");
   HtmlSelect select = form.getSelectByName("_.errors");
   HashSet<String> set = new HashSet<String>();
   for (HtmlOption option : select.getOptions()) {
     set.add(option.getValueAttribute());
   }
   assertTrue(set.contains("Default"));
   assertTrue(set.contains(CAUSE_NAME_2));
   assertTrue(set.contains(CAUSE_NAME_1));
 }
  private ClaimBuildAction applyClaimWithFailureCauseSelected(
      String element, String error, String reason, String description) throws Exception {
    HtmlPage page = whenNavigatingtoClaimPage();
    page.getElementById(element).click();
    HtmlForm form = page.getFormByName("claim");
    form.getTextAreaByName("reason").setText(reason);
    HtmlSelect select = form.getSelectByName("_.errors");
    HtmlOption option = select.getOptionByValue(error);
    select.setSelectedAttribute(option, true);

    assertEquals(description, form.getTextAreaByName("errordesc").getTextContent());

    form.submit((HtmlButton) j.last(form.getHtmlElementsByTagName("button")));

    ClaimBuildAction action = build.getAction(ClaimBuildAction.class);
    return action;
  }
 @Test
 public void assertNullIsReturnedWithBuildWithoutRequestedAction() {
   Build<?, ?> build = mock(Build.class);
   when(build.getActions(Action.class)).thenReturn(null);
   assertThat(new ActionSequenceRetriever(Action.class, 1).getSequence(build), is(nullValue()));
 }
  /** {@inheritDoc} */
  public boolean perform(Build<?, ?> build, Launcher launcher, BuildListener listener)
      throws InterruptedException, IOException {
    if (coverageReportPattern == null) {
      listener.getLogger().println("Skipping coverage reports as coverageReportPattern is null");
      return false;
    }
    if (!Result.SUCCESS.equals(build.getResult())) {
      listener.getLogger().println("Skipping coverage reports as the build was not successful...");
      return true;
    }

    listener.getLogger().println("Publishing PureCoverage reports...");
    FilePath buildTarget = new FilePath(build.getRootDir());

    FilePath[] reports = new FilePath[0];
    final FilePath moduleRoot = build.getParent().getWorkspace();
    try {
      reports = moduleRoot.list(coverageReportPattern);
    } catch (IOException e) {
      Util.displayIOException(e, listener);
      e.printStackTrace(listener.fatalError("Unable to find PureCoverage results"));
      build.setResult(Result.FAILURE);
    }

    if (reports.length == 0) {
      listener
          .getLogger()
          .println(
              "No coverage results were found using the pattern '"
                  + coverageReportPattern
                  + "'.  Did you generate the report(s)?");
      build.setResult(Result.FAILURE);
      return true;
    }

    if (reports.length > 1) {
      listener
          .getLogger()
          .println(
              "PureCoverage publisher found more than one report that match the pattern. "
                  + "Currently, accumulating PureCoverage results is not implemented!");
      build.setResult(Result.FAILURE);
      return true;
    }

    FilePath singleReport = reports[0];
    final FilePath targetPath = new FilePath(buildTarget, CoverageReportsFinder.COVERAGE_PREFIX);
    try {
      singleReport.copyTo(targetPath);
    } catch (IOException e) {
      Util.displayIOException(e, listener);
      e.printStackTrace(
          listener.fatalError(
              "Unable to copy coverage from " + singleReport + " to " + buildTarget));
      build.setResult(Result.FAILURE);
    }

    listener.getLogger().println("Parsing PureCoverage results...");
    ProjectCoverage projectCoverage = null;
    CoverageReportsFinder finder = new CoverageReportsFinder();
    for (File coverageResult : finder.findReports(build)) {
      try {
        CoverageParser coverageParser = new PureCoverageParser();
        projectCoverage = coverageParser.parse(coverageResult);
      } catch (IOException e) {
        Util.displayIOException(e, listener);
        e.printStackTrace(listener.fatalError("Unable to parse " + coverageResult));
        build.setResult(Result.FAILURE);
        return false;
      }
    }

    CoverageResult coverageResult = new CoverageResult(build, projectCoverage);
    build.getActions().add(new CoverageBuildAction(build, coverageResult));

    return true;
  }
 @Override
 public void addAction(Action a) {
   super.addAction(a);
 }
 @Override
 public synchronized void doStop(StaplerRequest req, StaplerResponse rsp)
     throws IOException, ServletException {
   super.doStop(req, rsp);
 }
Пример #10
0
 private HtmlPage whenNavigatingtoClaimPage() throws Exception {
   JenkinsRule.WebClient wc = j.createWebClient();
   wc.login("user1", "user1");
   HtmlPage page = wc.goTo("job/x/" + build.getNumber());
   return page;
 }
 private static void assertFile(boolean exists, String path, Build<?, ?> b)
     throws IOException, InterruptedException {
   if (b.getWorkspace().child(path).exists() != exists)
     assertEquals(path + ": " + getLog(b), exists, !exists);
 }