Search in sources :

Example 41 with FreeStyleProject

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

the class PipelineNodeTest method downstreamBuildLinks.

@Test
@Issue("JENKINS-38339")
public void downstreamBuildLinks() throws Exception {
    FreeStyleProject downstream1 = j.createFreeStyleProject("downstream1");
    FreeStyleProject downstream2 = j.createFreeStyleProject("downstream2");
    WorkflowJob upstream = j.createProject(WorkflowJob.class, "upstream");
    URL resource = Resources.getResource(getClass(), "downstreamBuildLinks.jenkinsfile");
    String jenkinsFile = Resources.toString(resource, Charsets.UTF_8);
    upstream.setDefinition(new CpsFlowDefinition(jenkinsFile, true));
    j.assertBuildStatus(Result.SUCCESS, upstream.scheduleBuild2(0));
    WorkflowRun r = upstream.getLastBuild();
    List<Map> resp = get("/organizations/jenkins/pipelines/upstream/runs/" + r.getId() + "/nodes/", List.class);
    assertEquals("number of nodes", 5, resp.size());
    Matcher actionMatcher1 = new NodeDownstreamBuildActionMatcher("downstream1");
    Matcher actionMatcher2 = new NodeDownstreamBuildActionMatcher("downstream2");
    List<Map> actions = (List<Map>) resp.get(2).get("actions");
    assertThat("node #2 contains a link to downstream1", actions, hasItem(actionMatcher1));
    actions = (List<Map>) resp.get(3).get("actions");
    assertThat("node #3 contains a link to downstream2", actions, hasItem(actionMatcher2));
    actions = (List<Map>) resp.get(4).get("actions");
    assertThat("node #4 contains a link to downstream1", actions, hasItem(actionMatcher1));
    assertThat("node #4 contains a link to downstream1", actions, hasItem(actionMatcher2));
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Matcher(org.hamcrest.Matcher) RunList(hudson.util.RunList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) FreeStyleProject(hudson.model.FreeStyleProject) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) URL(java.net.URL) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 42 with FreeStyleProject

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

the class ArtifactContainerImplTest method testArtifact.

// TODO: needs viveks input
@Test
@Ignore
public void testArtifact() throws Exception {
    FreeStyleProject p = j.createFreeStyleProject(JOB_NAME);
    p.getBuildersList().add(new Shell("mkdir -p test/me/out; touch test/me/out/{{a..z},{A..Z},{0..99}}.txt"));
    p.getPublishersList().add(new ArtifactArchiver("**/*"));
    Run r = p.scheduleBuild2(0).waitForStart();
    r = j.waitForCompletion(r);
    Map artifact = request().get("/organizations/jenkins/pipelines/" + JOB_NAME + "/runs/" + r.getId() + "/artifacts/test%252Fme%252Fout%252F0.txt").build(Map.class);
    Assert.assertEquals(100, artifact.size());
}
Also used : Shell(hudson.tasks.Shell) ArtifactArchiver(hudson.tasks.ArtifactArchiver) Run(hudson.model.Run) FreeStyleProject(hudson.model.FreeStyleProject) Map(java.util.Map) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 43 with FreeStyleProject

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

the class ContainerFilterTest method testPagedFilter.

@Test
public void testPagedFilter() throws IOException {
    StaplerRequest request = mock(StaplerRequest.class);
    when(request.getParameter("filter")).thenReturn("itemgroup-only");
    mockStatic(Stapler.class);
    when(Stapler.getCurrentRequest()).thenReturn(request);
    List<Item> items = new ArrayList<>();
    MockFolder folder = j.createFolder("folder");
    for (int i = 0; i < 50; i++) {
        FreeStyleProject job = folder.createProject(FreeStyleProject.class, "job" + i);
        items.add(folder.createProject(MockFolder.class, "subFolder" + i));
        items.add(job);
    }
    assertEquals(100, items.size());
    // there are total 50 folders in items, we want 25 of them starting 25th ending at 49th.
    Collection<Item> jobs = ContainerFilter.filter(items, 25, 25);
    assertEquals(25, jobs.size());
    int i = 25;
    for (Item item : jobs) {
        assertTrue(item instanceof ItemGroup);
        assertEquals("subFolder" + i++, item.getName());
    }
}
Also used : Item(hudson.model.Item) ItemGroup(hudson.model.ItemGroup) StaplerRequest(org.kohsuke.stapler.StaplerRequest) ArrayList(java.util.ArrayList) MockFolder(org.jvnet.hudson.test.MockFolder) FreeStyleProject(hudson.model.FreeStyleProject) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 44 with FreeStyleProject

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

the class PipelineApiTest method shouldFailToGetRunForInvalidRunId2.

@Test
public void shouldFailToGetRunForInvalidRunId2() throws Exception {
    FreeStyleProject p = j.createFreeStyleProject("pipeline6");
    p.getBuildersList().add(new Shell("echo hello!\nsleep 1"));
    get("/organizations/jenkins/pipelines/pipeline6/runs/xyz", 404, Map.class);
}
Also used : Shell(hudson.tasks.Shell) FreeStyleProject(hudson.model.FreeStyleProject) Test(org.junit.Test)

Example 45 with FreeStyleProject

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

the class PipelineApiTest method getPipelineRunTest.

@Test
public void getPipelineRunTest() throws Exception {
    FreeStyleProject p = j.createFreeStyleProject("pipeline4");
    p.getBuildersList().add(new Shell("echo hello!\nsleep 1"));
    FreeStyleBuild b = p.scheduleBuild2(0).get();
    j.assertBuildStatusSuccess(b);
    Map resp = get("/organizations/jenkins/pipelines/pipeline4/runs/" + b.getId());
    validateRun(b, resp);
    String log = get("/organizations/jenkins/pipelines/pipeline4/runs/" + b.getId() + "/log", String.class);
    System.out.println(log);
    assertNotNull(log);
}
Also used : Shell(hudson.tasks.Shell) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Aggregations

FreeStyleProject (hudson.model.FreeStyleProject)88 Test (org.junit.Test)61 FreeStyleBuild (hudson.model.FreeStyleBuild)42 Shell (hudson.tasks.Shell)21 Map (java.util.Map)20 ImmutableMap (com.google.common.collect.ImmutableMap)17 JobPropertyImpl (hudson.plugins.promoted_builds.JobPropertyImpl)14 PromotionProcess (hudson.plugins.promoted_builds.PromotionProcess)13 ArrayList (java.util.ArrayList)12 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)11 StringParameterDefinition (hudson.model.StringParameterDefinition)10 MockFolder (org.jvnet.hudson.test.MockFolder)10 List (java.util.List)9 PromotedBuildAction (hudson.plugins.promoted_builds.PromotedBuildAction)8 ImmutableList (com.google.common.collect.ImmutableList)7 FreeStyleProjectMock (hudson.model.FreeStyleProjectMock)7 Promotion (hudson.plugins.promoted_builds.Promotion)7 ParametersDefinitionProperty (hudson.model.ParametersDefinitionProperty)6 Run (hudson.model.Run)6 ManualCondition (hudson.plugins.promoted_builds.conditions.ManualCondition)6