public void testNativeMaven() throws Exception {
    MavenInstallation maven = configureDefaultMaven();
    String mavenPath = maven.getHome();
    Jenkins.getInstance()
        .getDescriptorByType(Maven.DescriptorImpl.class)
        .setInstallations(new MavenInstallation("maven", "THIS IS WRONG", NO_PROPERTIES));

    MavenModuleSet project = createMavenProject();
    project.setScm(new ExtractResourceSCM(getClass().getResource("/simple-projects.zip")));
    project.setAssignedLabel(slave.getSelfLabel());
    project.setJDK(jenkins.getJDK("default"));

    project.setMaven("maven");
    project.setGoals("clean");

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

    ToolLocationNodeProperty property =
        new ToolLocationNodeProperty(
            new ToolLocationNodeProperty.ToolLocation(
                jenkins.getDescriptorByType(MavenInstallation.DescriptorImpl.class),
                "maven",
                mavenPath));
    slave.getNodeProperties().add(property);

    build = project.scheduleBuild2(0).get();
    System.out.println(build.getLog());
    assertBuildStatus(Result.SUCCESS, build);
  }
  /** Make sure we can reset the label of an existing slave. */
  public void testSetLabelString() throws Exception {
    DumbSlave s = createSlave("foo", "", null);

    assertSame(s.getLabelString(), "");

    s.setLabelString("bar");

    assertSame(s.getLabelString(), "bar");
  }
  /**
   * One test for all for faster execution.
   *
   * @throws Exception
   */
  public void testCanRun() throws Exception {
    // init slave
    LabelAtom slaveLabel = new LabelAtom("slave");
    LabelAtom masterLabel = new LabelAtom("master");

    DumbSlave slave = this.createSlave(slaveLabel);
    SlaveComputer c = slave.getComputer();
    c.connect(false).get(); // wait until it's connected
    if (c.isOffline()) {
      fail("Slave failed to go online: " + c.getLog());
    }

    BuildBlockerQueueTaskDispatcher dispatcher = new BuildBlockerQueueTaskDispatcher();

    String blockingJobName = "blockingJob";

    Shell shell = new Shell("sleep 1");

    Future<FreeStyleBuild> future1 = createBlockingProject("xxx", shell, masterLabel);
    Future<FreeStyleBuild> future2 = createBlockingProject(blockingJobName, shell, masterLabel);
    Future<FreeStyleBuild> future3 = createBlockingProject("yyy", shell, slaveLabel);
    // add project to slave
    FreeStyleProject project = this.createFreeStyleProject();
    project.setAssignedLabel(slaveLabel);

    Queue.BuildableItem item =
        new Queue.BuildableItem(
            new Queue.WaitingItem(Calendar.getInstance(), project, new ArrayList<Action>()));

    CauseOfBlockage causeOfBlockage = dispatcher.canRun(item);

    assertNull(causeOfBlockage);

    BuildBlockerProperty property = new BuildBlockerProperty();

    property.setBlockingJobs(".*ocki.*");

    project.addProperty(property);

    causeOfBlockage = dispatcher.canRun(item);
    assertNotNull(causeOfBlockage);

    assertEquals(
        "Blocking job " + blockingJobName + " is running.", causeOfBlockage.getShortDescription());

    while (!(future1.isDone() && future2.isDone() && future3.isDone())) {
      // wait until jobs are done.
    }
  }
示例#4
0
  public void testNodeOfflineCli() throws Exception {
    DumbSlave s = createSlave();

    CLI cli = new CLI(getURL());
    try {
      assertTrue(cli.execute("wait-node-offline", "xxx") != 0);
      assertTrue(cli.execute("wait-node-online", s.getNodeName()) == 0);

      s.toComputer().disconnect().get();

      assertTrue(cli.execute("wait-node-offline", s.getNodeName()) == 0);
    } finally {
      cli.close();
    }
  }
  @Test
  public void doNothingIfItWillNotShortenThePath() throws Exception {
    DumbSlave s = j.createOnlineSlave();

    // Would be turned into 'short_project...XXXXXXXX' which is in fact longer than the original
    FreeStyleProject p = j.createFreeStyleProject("short_project_name");
    p.setAssignedNode(s);

    // Not enough for anything
    setMaxPathLength(s, 1);

    FreeStyleBuild b = p.scheduleBuild2(0).get();
    assertThat(
        b.getWorkspace().getRemote(),
        equalTo(s.getRootPath() + DS + "workspace" + DS + p.getFullName().replace("/", DS)));
  }
  @Test
  public void doNothingIfThereIsEnoughRoom() throws Exception {
    DumbSlave s = j.createOnlineSlave();

    MockFolder f = j.createFolder("this_is_my_folder_alright");
    FreeStyleProject p = f.createProject(FreeStyleProject.class, "and_a_project_in_it");
    p.setAssignedNode(s);

    // Enough for the test - even on windows
    setMaxPathLength(s, 4096);

    FreeStyleBuild b = p.scheduleBuild2(0).get();
    assertThat(
        b.getWorkspace().getRemote(),
        equalTo(s.getRootPath() + DS + "workspace" + DS + p.getFullName().replace("/", DS)));
  }
 public void testCopyToSlave() throws Exception {
   DumbSlave node = createSlave();
   SlaveComputer c = node.getComputer();
   c.connect(false).get(); // wait until it's connected
   if (c.isOffline()) fail("Slave failed to go online: " + c.getLog());
   FreeStyleProject other = createArtifactProject(),
       p = createProject(other.getName(), "", "", false, false, false);
   assertBuildStatusSuccess(other.scheduleBuild2(0, new UserCause()).get());
   p.setAssignedLabel(node.getSelfLabel());
   FreeStyleBuild b = p.scheduleBuild2(0, new UserCause()).get();
   assertBuildStatusSuccess(b);
   assertSame(node, b.getBuiltOn());
   assertFile(true, "foo.txt", b);
   assertFile(true, "subdir/subfoo.txt", b);
   assertFile(true, "deepfoo/a/b/c.log", b);
 }
  @Test
  public void unwrapFolders() throws Exception {
    DumbSlave s = j.createOnlineSlave();

    MockFolder f = j.createFolder("this_is_my_folder_alright");
    FreeStyleProject p = f.createProject(FreeStyleProject.class, "and_a_project_in_it");
    p.setAssignedNode(s);

    // Not enough for anything
    setMaxPathLength(s, 1);

    FreeStyleBuild b = p.scheduleBuild2(0).get();
    String buildWs = b.getWorkspace().getRemote();
    String wsDir = s.getRootPath() + DS + "workspace" + DS;
    assertThat(buildWs, startsWith(wsDir + "and_a_pro"));
    assertThat(buildWs, buildWs.length(), equalTo(wsDir.length() + 24));
  }
  @LocalData
  @Test
  public void slave() throws Exception {
    Assume.assumeFalse(
        "TimeoutException from basic",
        "https://jenkins.ci.cloudbees.com/job/core/job/jenkins_main_trunk/"
            .equals(System.getenv("JOB_URL")));
    DumbSlave s = j.createOnlineSlave();
    project.setAssignedLabel(s.getSelfLabel());

    FilePath src = new FilePath(j.jenkins.getRootPath(), "jobs/junit/workspace/");
    assertNotNull(src);
    FilePath dest = s.getWorkspaceFor(project);
    assertNotNull(dest);
    src.copyRecursiveTo("*.xml", dest);

    basic();
  }
  public void testFormRoundTrip() throws Exception {

    MavenInstallation.DescriptorImpl mavenDescriptor =
        jenkins.getDescriptorByType(MavenInstallation.DescriptorImpl.class);
    mavenDescriptor.setInstallations(new MavenInstallation("maven", "XXX", NO_PROPERTIES));
    AntInstallation.DescriptorImpl antDescriptor =
        jenkins.getDescriptorByType(AntInstallation.DescriptorImpl.class);
    antDescriptor.setInstallations(new AntInstallation("ant", "XXX", NO_PROPERTIES));
    JDK.DescriptorImpl jdkDescriptor = jenkins.getDescriptorByType(JDK.DescriptorImpl.class);
    jdkDescriptor.setInstallations(new JDK("jdk", "XXX"));

    ToolLocationNodeProperty property =
        new ToolLocationNodeProperty(
            new ToolLocationNodeProperty.ToolLocation(jdkDescriptor, "jdk", "foobar"),
            new ToolLocationNodeProperty.ToolLocation(mavenDescriptor, "maven", "barzot"),
            new ToolLocationNodeProperty.ToolLocation(antDescriptor, "ant", "zotfoo"));
    slave.getNodeProperties().add(property);

    WebClient webClient = new WebClient();
    HtmlPage page = webClient.getPage(slave, "configure");
    HtmlForm form = page.getFormByName("config");
    submit(form);

    Assert.assertEquals(1, slave.getNodeProperties().toList().size());

    ToolLocationNodeProperty prop = slave.getNodeProperties().get(ToolLocationNodeProperty.class);
    Assert.assertEquals(3, prop.getLocations().size());

    ToolLocationNodeProperty.ToolLocation location = prop.getLocations().get(0);
    Assert.assertEquals(jdkDescriptor, location.getType());
    Assert.assertEquals("jdk", location.getName());
    Assert.assertEquals("foobar", location.getHome());

    location = prop.getLocations().get(1);
    Assert.assertEquals(mavenDescriptor, location.getType());
    Assert.assertEquals("maven", location.getName());
    Assert.assertEquals("barzot", location.getHome());

    location = prop.getLocations().get(2);
    Assert.assertEquals(antDescriptor, location.getType());
    Assert.assertEquals("ant", location.getName());
    Assert.assertEquals("zotfoo", location.getHome());
  }
示例#11
0
    @Test
    @Issue("JENKINS-21474")
    public void testGetComputersNPE() throws Exception {
        ListView view = listView("aView");
        view.filterExecutors = true;

        DumbSlave dedicatedSlave = j.createOnlineSlave();
        dedicatedSlave.setMode(Mode.EXCLUSIVE);
        view.add(j.createFreeStyleProject());

        FreeStyleProject tiedJob = j.createFreeStyleProject();
        tiedJob.setAssignedNode(dedicatedSlave);
        view.add(tiedJob);

        DumbSlave notIncludedSlave = j.createOnlineSlave();
        notIncludedSlave.setMode(Mode.EXCLUSIVE);

        assertContainsNodes(view, j.jenkins, dedicatedSlave);
        assertNotContainsNodes(view, notIncludedSlave);
    }
 public void setUp() throws Exception {
   super.setUp();
   EnvVars env = new EnvVars();
   // we don't want Maven, Ant, etc. to be discovered in the path for this test to work,
   // but on Unix these tools rely on other basic Unix tools (like env) for its operation,
   // so empty path breaks the test.
   env.put("PATH", "/bin:/usr/bin");
   env.put("M2_HOME", "empty");
   slave = createSlave(new LabelAtom("slave"), env);
   project = createFreeStyleProject();
   project.setAssignedLabel(slave.getSelfLabel());
 }
  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);
  }
  public void testMaven() throws Exception {
    MavenInstallation maven = configureDefaultMaven();
    String mavenPath = maven.getHome();
    Jenkins.getInstance()
        .getDescriptorByType(Maven.DescriptorImpl.class)
        .setInstallations(new MavenInstallation("maven", "THIS IS WRONG", NO_PROPERTIES));

    project.getBuildersList().add(new Maven("--version", "maven"));
    configureDumpEnvBuilder();

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

    ToolLocationNodeProperty property =
        new ToolLocationNodeProperty(
            new ToolLocationNodeProperty.ToolLocation(
                jenkins.getDescriptorByType(MavenInstallation.DescriptorImpl.class),
                "maven",
                mavenPath));
    slave.getNodeProperties().add(property);

    build = project.scheduleBuild2(0).get();
    assertBuildStatus(Result.SUCCESS, build);
  }