Search in sources :

Example 1 with Slave

use of hudson.model.Slave in project support-core-plugin by jenkinsci.

the class SupportActionTest method anonymizationSmokes.

@Test
public void anonymizationSmokes() throws Exception {
    Slave node = j.createSlave(Label.get("super_secret_node"));
    File bundleFile = temp.newFile();
    List<Component> componentsToCreate = Collections.singletonList(ExtensionList.lookup(Component.class).get(AboutJenkins.class));
    try (OutputStream os = Files.newOutputStream(bundleFile.toPath())) {
        ContentFilters.get().setEnabled(false);
        SupportPlugin.writeBundle(os, componentsToCreate);
        ZipFile zip = new ZipFile(bundleFile);
        String nodeComponentText = IOUtils.toString(zip.getInputStream(zip.getEntry("nodes.md")), StandardCharsets.UTF_8);
        assertThat("Node name should be present when anonymization is disabled", nodeComponentText, containsString(node.getNodeName()));
    }
    bundleFile = temp.newFile();
    try (OutputStream os = Files.newOutputStream(bundleFile.toPath())) {
        ContentFilters.get().setEnabled(true);
        SupportPlugin.writeBundle(os, componentsToCreate);
        ZipFile zip = new ZipFile(bundleFile);
        String nodeComponentText = IOUtils.toString(zip.getInputStream(zip.getEntry("nodes.md")), StandardCharsets.UTF_8);
        assertThat("Node name should not be present when anonymization is enabled", nodeComponentText, not(containsString(node.getNodeName())));
        String anonymousNodeName = ContentMappings.get().getMappings().get(node.getNodeName());
        assertThat("Anonymous node name should be present when anonymization is enabled", nodeComponentText, containsString(anonymousNodeName));
    }
}
Also used : Slave(hudson.model.Slave) ZipFile(java.util.zip.ZipFile) OutputStream(java.io.OutputStream) Matchers.containsString(org.hamcrest.Matchers.containsString) ConfigFileComponent(com.cloudbees.jenkins.support.configfiles.ConfigFileComponent) Component(com.cloudbees.jenkins.support.api.Component) AboutJenkins(com.cloudbees.jenkins.support.impl.AboutJenkins) ZipFile(java.util.zip.ZipFile) File(java.io.File) Test(org.junit.Test)

Example 2 with Slave

use of hudson.model.Slave in project blueocean-plugin by jenkinsci.

the class PipelineNodeTest method sequentialParallelStagesWithPost.

@Test
@Issue("JENKINS-49779")
public void sequentialParallelStagesWithPost() throws Exception {
    WorkflowJob p = createWorkflowJobWithJenkinsfile(getClass(), "sequentialParallelWithPost.jenkinsfile");
    Slave s = j.createOnlineSlave();
    s.setNumExecutors(2);
    // Run until completed
    j.buildAndAssertSuccess(p);
    List<Map> nodes = get("/organizations/jenkins/pipelines/" + p.getName() + "/runs/1/nodes/", List.class);
    assertEquals(9, nodes.size());
    Optional<Map> thirdSeqStage = nodes.stream().filter(map -> map.get("displayName").equals("third-sequential-stage")).findFirst();
    assertTrue(thirdSeqStage.isPresent());
    List<Map> steps = get("/organizations/jenkins/pipelines/" + p.getName() + "/runs/1/nodes/" + thirdSeqStage.get().get("id") + "/steps/", List.class);
    assertEquals(2, steps.size());
    assertEquals("echo 'dummy text third-sequential-stage'", steps.get(0).get("displayDescription"));
    assertEquals("echo 'dummy text post multiple-stages'", steps.get(1).get("displayDescription"));
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) Arrays(java.util.Arrays) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) Issue(org.jvnet.hudson.test.Issue) QueueTaskFuture(hudson.model.queue.QueueTaskFuture) URL(java.net.URL) InputAction(org.jenkinsci.plugins.workflow.support.steps.input.InputAction) PARAMETERS_ELEMENT(io.jenkins.blueocean.rest.impl.pipeline.PipelineStepImpl.PARAMETERS_ELEMENT) StringUtils(org.apache.commons.lang3.StringUtils) RunList(hudson.util.RunList) MemoryFlowChunk(org.jenkinsci.plugins.workflow.graphanalysis.MemoryFlowChunk) Map(java.util.Map) FlowExecution(org.jenkinsci.plugins.workflow.flow.FlowExecution) BluePipelineNode(io.jenkins.blueocean.rest.model.BluePipelineNode) Jenkins(jenkins.model.Jenkins) MapsHelper(io.jenkins.blueocean.commons.MapsHelper) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Run(hudson.model.Run) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) NodeDownstreamBuildAction(io.jenkins.blueocean.listeners.NodeDownstreamBuildAction) FilePath(hudson.FilePath) Result(hudson.model.Result) JSONObject(net.sf.json.JSONObject) WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) Optional(java.util.Optional) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Link(io.jenkins.blueocean.rest.hal.Link) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode) BeforeClass(org.junit.BeforeClass) SemaphoreStep(org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep) FreeStyleProject(hudson.model.FreeStyleProject) CpsFlowExecution(org.jenkinsci.plugins.workflow.cps.CpsFlowExecution) FlowGraphTable(org.jenkinsci.plugins.workflow.support.visualization.table.FlowGraphTable) UnstableStep(org.jenkinsci.plugins.workflow.steps.UnstableStep) GitSampleRepoRule(jenkins.plugins.git.GitSampleRepoRule) Unirest(com.mashape.unirest.http.Unirest) SCMSource(jenkins.scm.api.SCMSource) Util(hudson.Util) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Description(org.hamcrest.Description) Iterator(java.util.Iterator) BluePipelineStep(io.jenkins.blueocean.rest.model.BluePipelineStep) BlueRun(io.jenkins.blueocean.rest.model.BlueRun) Test(org.junit.Test) BranchSource(jenkins.branch.BranchSource) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) Rule(org.junit.Rule) Ignore(org.junit.Ignore) Matcher(org.hamcrest.Matcher) Assert(org.junit.Assert) Slave(hudson.model.Slave) ExtensionList(hudson.ExtensionList) GitSCMSource(jenkins.plugins.git.GitSCMSource) Slave(hudson.model.Slave) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Map(java.util.Map) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 3 with Slave

use of hudson.model.Slave in project blueocean-plugin by jenkinsci.

the class PipelineNodeTest method parallelStagesGroupsAndNestedStages.

@Test
@Issue("JENKINS-49050")
public void parallelStagesGroupsAndNestedStages() throws Exception {
    WorkflowJob p = createWorkflowJobWithJenkinsfile(getClass(), "parallelStagesGroupsAndStages.jenkinsfile");
    Slave s = j.createOnlineSlave();
    s.setLabelString("foo");
    s.setNumExecutors(2);
    // Run until completed
    WorkflowRun run = p.scheduleBuild2(0).waitForStart();
    j.waitForCompletion(run);
    PipelineNodeGraphVisitor pipelineNodeGraphVisitor = new PipelineNodeGraphVisitor(run);
    assertTrue(pipelineNodeGraphVisitor.isDeclarative());
    List<FlowNodeWrapper> wrappers = pipelineNodeGraphVisitor.getPipelineNodes();
    FlowNodeWrapper flowNodeWrapper = wrappers.get(0);
    assertEquals("top", flowNodeWrapper.getDisplayName());
    assertEquals(2, flowNodeWrapper.edges.size());
    flowNodeWrapper = wrappers.get(1);
    assertEquals("first", flowNodeWrapper.getDisplayName());
    assertEquals(1, flowNodeWrapper.edges.size());
    assertEquals(1, flowNodeWrapper.getParents().size());
    assertEquals("first-inner-first", flowNodeWrapper.edges.get(0).getDisplayName());
    assertEquals(7, wrappers.size());
    List<Map> nodes = get("/organizations/jenkins/pipelines/" + p.getName() + "/runs/1/nodes/", List.class);
    assertEquals(7, nodes.size());
}
Also used : Slave(hudson.model.Slave) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Map(java.util.Map) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 4 with Slave

use of hudson.model.Slave in project blueocean-plugin by jenkinsci.

the class PipelineNodeTest method nestedStagesGroups.

@Test
public void nestedStagesGroups() throws Exception {
    WorkflowJob p = createWorkflowJobWithJenkinsfile(getClass(), "nestedStagesGroups.jenkinsfile");
    Slave s = j.createOnlineSlave();
    s.setLabelString("foo");
    s.setNumExecutors(4);
    // Run until completed
    WorkflowRun run = p.scheduleBuild2(0).waitForStart();
    j.waitForCompletion(run);
    PipelineNodeGraphVisitor pipelineNodeGraphVisitor = new PipelineNodeGraphVisitor(run);
    assertTrue(pipelineNodeGraphVisitor.isDeclarative());
    List<FlowNodeWrapper> wrappers = pipelineNodeGraphVisitor.getPipelineNodes();
    assertEquals(7, wrappers.size());
}
Also used : Slave(hudson.model.Slave) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Test(org.junit.Test)

Example 5 with Slave

use of hudson.model.Slave in project configuration-as-code-plugin by jenkinsci.

the class BuildAgentsTest method configure_build_agents.

@Test
@ConfiguredWithReadme(value = "build_agents/README.md")
public void configure_build_agents() {
    assertThat(j.getInstance().getComputers().length, is(3));
    Slave slave = (Slave) j.getInstance().getNode("utility-node");
    assertThat(slave.getRemoteFS(), is("/home/user1"));
    JNLPLauncher jnlpLauncher = ((JNLPLauncher) slave.getLauncher());
    assertThat(jnlpLauncher.getWorkDirSettings().getWorkDirPath(), is("/tmp"));
    assertThat(jnlpLauncher.getWorkDirSettings().getInternalDir(), is("remoting"));
    assertTrue(jnlpLauncher.getWorkDirSettings().isDisabled());
    assertFalse(jnlpLauncher.getWorkDirSettings().isFailIfWorkDirIsMissing());
    assertThat(j.getInstance().getNode("utility-node-2").getNumExecutors(), is(4));
    assertThat(j.getInstance().getNode("utility-node-2").getMode(), is(Mode.NORMAL));
    slave = (Slave) j.getInstance().getNode("utility-node-2");
    assertThat(slave.getRemoteFS(), is("/home/user2"));
    SSHLauncher launcher = ((SSHLauncher) slave.getLauncher());
    assertThat(launcher.getHost(), is("192.168.1.1"));
    assertThat(launcher.getPort(), is(22));
    assertThat(launcher.getCredentialsId(), is("test"));
    assertThat(launcher.getMaxNumRetries(), is(3));
    assertThat(launcher.getRetryWaitTime(), is(30));
}
Also used : Slave(hudson.model.Slave) SSHLauncher(hudson.plugins.sshslaves.SSHLauncher) JNLPLauncher(hudson.slaves.JNLPLauncher) Test(org.junit.Test) ConfiguredWithReadme(io.jenkins.plugins.casc.misc.ConfiguredWithReadme)

Aggregations

Slave (hudson.model.Slave)8 Test (org.junit.Test)8 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)6 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)6 Map (java.util.Map)5 Issue (org.jvnet.hudson.test.Issue)5 File (java.io.File)4 Unirest (com.mashape.unirest.http.Unirest)3 ExtensionList (hudson.ExtensionList)3 FilePath (hudson.FilePath)3 Util (hudson.Util)3 FreeStyleProject (hudson.model.FreeStyleProject)3 Result (hudson.model.Result)3 Run (hudson.model.Run)3 QueueTaskFuture (hudson.model.queue.QueueTaskFuture)3 RunList (hudson.util.RunList)3 MapsHelper (io.jenkins.blueocean.commons.MapsHelper)3 NodeDownstreamBuildAction (io.jenkins.blueocean.listeners.NodeDownstreamBuildAction)3 Link (io.jenkins.blueocean.rest.hal.Link)3 PARAMETERS_ELEMENT (io.jenkins.blueocean.rest.impl.pipeline.PipelineStepImpl.PARAMETERS_ELEMENT)3