Java Code Examples for hudson.model.FreeStyleProject#setAssignedNode()

The following examples show how to use hudson.model.FreeStyleProject#setAssignedNode() . 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: DockerContainerITest.java    From warnings-ng-plugin with MIT License 6 votes vote down vote up
/**
 * Build a maven project on a docker container agent.
 *
 * @throws IOException
 *         When the node assignment of the agent fails.
 * @throws InterruptedException
 *         If the creation of the docker container fails.
 */
@Test
public void shouldBuildMavenOnAgent() throws IOException, InterruptedException {
    assumeThat(isWindows()).as("Running on Windows").isFalse();

    DumbSlave agent = createDockerContainerAgent(javaDockerRule.get());

    FreeStyleProject project = createFreeStyleProject();
    project.setAssignedNode(agent);

    createFileInAgentWorkspace(agent, project, "src/main/java/Test.java", getSampleJavaFile());
    createFileInAgentWorkspace(agent, project, "pom.xml", getSampleMavenFile());
    project.getBuildersList().add(new Maven("compile", null));
    enableWarnings(project, createTool(new Java(), ""));

    scheduleSuccessfulBuild(project);

    FreeStyleBuild lastBuild = project.getLastBuild();
    AnalysisResult result = getAnalysisResult(lastBuild);

    assertThat(result).hasTotalSize(2);
    assertThat(lastBuild.getBuiltOn().getLabelString()).isEqualTo(((Node) agent).getLabelString());
}
 
Example 2
Source File: DockerContainerITest.java    From warnings-ng-plugin with MIT License 6 votes vote down vote up
/**
 * Runs a make file to compile a cpp file on a docker container agent.
 *
 * @throws IOException
 *         When the node assignment of the agent fails.
 * @throws InterruptedException
 *         If the creation of the docker container fails.
 */
@Test
public void shouldBuildMakefileOnAgent() throws IOException, InterruptedException {
    assumeThat(isWindows()).as("Running on Windows").isFalse();

    DumbSlave agent = createDockerContainerAgent(gccDockerRule.get());

    FreeStyleProject project = createFreeStyleProject();
    project.setAssignedNode(agent);

    createFileInAgentWorkspace(agent, project, "test.cpp", getSampleCppFile());
    createFileInAgentWorkspace(agent, project, "makefile", getSampleMakefileFile());
    project.getBuildersList().add(new Shell("make"));
    enableWarnings(project, createTool(new Gcc4(), ""));

    scheduleSuccessfulBuild(project);

    FreeStyleBuild lastBuild = project.getLastBuild();
    AnalysisResult result = getAnalysisResult(lastBuild);

    assertThat(result).hasTotalSize(1);
    assertThat(lastBuild.getBuiltOn().getLabelString()).isEqualTo(((Node) agent).getLabelString());
}
 
Example 3
Source File: CucumberLivingDocumentationIT.java    From cucumber-living-documentation-plugin with MIT License 6 votes vote down vote up
@Test
public void shouldGenerateLivingDocumentatationOnSlaveNode() throws Exception{
	DumbSlave slave = jenkins.createOnlineSlave();
	FreeStyleProject project = jenkins.createFreeStyleProject("test");
	project.setAssignedNode(slave);
	
	SingleFileSCM scm = new SingleFileSCM("asciidoctor.json",
			CucumberLivingDocumentationIT.class.getResource("/json-output/asciidoctor/asciidoctor.json").toURI().toURL());
	
	project.setScm(scm);
	CukedoctorPublisher publisher = new CukedoctorPublisher(null, FormatType.HTML, TocType.RIGHT, true, true, "Living Documentation",false,false,false,false,false);
	project.getPublishersList().add(publisher);
	project.save();

	FreeStyleBuild build = jenkins.buildAndAssertSuccess(project);
	jenkins.assertLogContains("Format: html" + NEW_LINE + "Toc: right"+NEW_LINE +
			"Title: Living Documentation"+NEW_LINE+"Numbered: true"+NEW_LINE +
			"Section anchors: true", build);
	jenkins.assertLogContains("Found 4 feature(s)...",build);
	jenkins.assertLogContains("Documentation generated successfully!",build);
	Assert.assertTrue("It should run on slave",build.getBuiltOn().equals(slave));
	
}
 
Example 4
Source File: AbsolutePathGeneratorITest.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
private FreeStyleProject createJobForAgent(final Slave agent) {
    try {
        FreeStyleProject project = createFreeStyleProject();
        project.setAssignedNode(agent);
        return project;
    }
    catch (IOException exception) {
        throw new AssertionError(exception);
    }
}
 
Example 5
Source File: KafkaComputerLauncherTest.java    From remoting-kafka-plugin with MIT License 5 votes vote down vote up
@Test
public void configureRoundTrip() throws Exception {
    GlobalKafkaConfiguration g = GlobalKafkaConfiguration.get();
    String kafkaURL = kafka.getBootstrapServers().split("//")[1];
    String zookeeperURL = kafka.getContainerIpAddress() + ":" + kafka.getMappedPort(2181);
    g.setBrokerURL(kafkaURL);
    g.setZookeeperURL(zookeeperURL);
    g.setEnableSSL(false);
    g.save();
    g.load();
    KafkaComputerLauncher launcher = new KafkaComputerLauncher("", "",
            "", "false");
    DumbSlave agent = new DumbSlave("test", "/tmp/", launcher);
    j.jenkins.addNode(agent);
    Computer c = j.jenkins.getComputer("test");
    assertNotNull(c);
    Thread.sleep(10000); // wait to connect master to kafka.
    String[] urls = j.getInstance().getRootUrl().split("/");
    String jenkinsURL = urls[0] + "//" + urls[1] + urls[2] + "/";
    String[] args = new String[]{"-name", "test", "-master", jenkinsURL, "-secret",
            KafkaSecretManager.getConnectionSecret("test"), "-kafkaURL", kafkaURL, "-noauth"};
    AgentRunnable runnable = new AgentRunnable(args);
    Thread t = new Thread(runnable);
    try {
        t.start();
        Thread.sleep(10000); // wait to connect agent to jenkins master.
        FreeStyleProject p = j.createFreeStyleProject();
        p.setAssignedNode(agent);
        j.buildAndAssertSuccess(p);
    } finally {
        t.interrupt();
    }
}