Search in sources :

Example 31 with FreeStyleProject

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

the class MultiBranchTest method getBranchWithEncodedPath.

@Test
public void getBranchWithEncodedPath() throws IOException, ExecutionException, InterruptedException {
    Assume.assumeTrue(runAllTests());
    WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
    FreeStyleProject f = j.jenkins.createProject(FreeStyleProject.class, "f");
    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false), new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    for (SCMSource source : mp.getSCMSources()) {
        assertEquals(mp, source.getOwner());
    }
    mp.scheduleBuild2(0).getFuture().get();
    List<Map> resp = get("/organizations/jenkins/pipelines/p/branches/", List.class);
    String href = null;
    for (Map r : resp) {
        if (r.get("name").equals("feature%2Fux-1")) {
            href = (String) ((Map) ((Map) r.get("_links")).get("self")).get("href");
            href = StringUtils.substringAfter(href, "/blue/rest");
        }
    }
    Assert.assertNotNull(href);
    Map r = get(href);
    Assert.assertEquals("feature%2Fux-1", r.get("name"));
}
Also used : WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) GitSCMSource(jenkins.plugins.git.GitSCMSource) SCMSource(jenkins.scm.api.SCMSource) GitSCMSource(jenkins.plugins.git.GitSCMSource) FreeStyleProject(hudson.model.FreeStyleProject) BranchSource(jenkins.branch.BranchSource) DefaultBranchPropertyStrategy(jenkins.branch.DefaultBranchPropertyStrategy) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 32 with FreeStyleProject

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

the class PipelineApiTest method parameterizedFreestyleTest.

@Test
public void parameterizedFreestyleTest() throws Exception {
    FreeStyleProject p = j.createFreeStyleProject("pp");
    p.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("version", "1.0", "version number")));
    p.getBuildersList().add(new Shell("echo hello!"));
    Map resp = get("/organizations/jenkins/pipelines/pp/");
    List<Map<String, Object>> parameters = (List<Map<String, Object>>) resp.get("parameters");
    assertEquals(1, parameters.size());
    assertEquals("version", parameters.get(0).get("name"));
    assertEquals("StringParameterDefinition", parameters.get(0).get("type"));
    assertEquals("version number", parameters.get(0).get("description"));
    assertEquals("1.0", ((Map) parameters.get(0).get("defaultParameterValue")).get("value"));
    validatePipeline(p, resp);
    resp = post("/organizations/jenkins/pipelines/pp/runs/", ImmutableMap.of("parameters", ImmutableList.of(ImmutableMap.of("name", "version", "value", "2.0"))), 200);
    assertEquals("pp", resp.get("pipeline"));
    Thread.sleep(1000);
    resp = get("/organizations/jenkins/pipelines/pp/runs/1/");
    assertEquals("SUCCESS", resp.get("result"));
    assertEquals("FINISHED", resp.get("state"));
}
Also used : Shell(hudson.tasks.Shell) StringParameterDefinition(hudson.model.StringParameterDefinition) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) FreeStyleProject(hudson.model.FreeStyleProject) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 33 with FreeStyleProject

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

the class PipelineApiTest method getPipelineRunsTest.

@Test
public void getPipelineRunsTest() throws Exception {
    FreeStyleProject p = j.createFreeStyleProject("pipeline6");
    p.getBuildersList().add(new Shell("echo hello!\nsleep 1"));
    FreeStyleBuild b = p.scheduleBuild2(0).get();
    j.assertBuildStatusSuccess(b);
    List<Map> resp = get("/organizations/jenkins/pipelines/pipeline6/runs", List.class);
    assertEquals(1, resp.size());
    Map lr = resp.get(0);
    validateRun(b, lr);
}
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)

Example 34 with FreeStyleProject

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

the class ArtifactContainerImplTest method testArtifactsListing.

@Test
public void testArtifactsListing() throws Exception {
    FreeStyleProject p = j.createFreeStyleProject(JOB_NAME);
    p.getBuildersList().add(new Shell("#!/bin/bash\nmkdir -p test/me/out; cd test/me/out; touch {0..105}.txt"));
    p.getPublishersList().add(new ArtifactArchiver("**/*"));
    Run r = p.scheduleBuild2(0).waitForStart();
    r = j.waitForCompletion(r);
    List artifacts = request().get("/organizations/jenkins/pipelines/" + JOB_NAME + "/runs/" + r.getId() + "/artifacts").build(List.class);
    Assert.assertEquals(100, artifacts.size());
    Assert.assertEquals(0, ((Map) artifacts.get(0)).get("size"));
    Assert.assertEquals("test/me/out/0.txt", ((Map) artifacts.get(0)).get("path"));
    Assert.assertEquals("/job/artifactTest/1/artifact/test/me/out/0.txt", ((Map) artifacts.get(0)).get("url"));
}
Also used : Shell(hudson.tasks.Shell) ArtifactArchiver(hudson.tasks.ArtifactArchiver) Run(hudson.model.Run) List(java.util.List) FreeStyleProject(hudson.model.FreeStyleProject) Test(org.junit.Test)

Example 35 with FreeStyleProject

use of hudson.model.FreeStyleProject in project hudson-2.x by hudson.

the class CascadingUtilTest method testRenameCascadingParentLinks.

@Test
@PrepareForTest(Hudson.class)
public void testRenameCascadingParentLinks() throws Exception {
    String oldName = "oldCascadingProject";
    String newName = "newCascadingProject";
    List<Job> jobs = new ArrayList<Job>();
    FreeStyleProject project1 = new FreeStyleProjectMock(oldName);
    FreeStyleProjectMock project2 = new FreeStyleProjectMock("child");
    project2.setCascadingProject(project1);
    jobs.add(project1);
    jobs.add(project2);
    mockStatic(Hudson.class);
    Hudson hudson = createMock(Hudson.class);
    expect(hudson.getAllItems(Job.class)).andReturn(jobs);
    expect(Hudson.getInstance()).andReturn(hudson);
    replay(Hudson.class, hudson);
    CascadingUtil.renameCascadingParentLinks(oldName, newName);
    verify(Hudson.class, hudson);
    assertEquals(newName, project2.getCascadingProjectName());
}
Also used : FreeStyleProjectMock(hudson.model.FreeStyleProjectMock) Hudson(hudson.model.Hudson) ArrayList(java.util.ArrayList) Job(hudson.model.Job) FreeStyleProject(hudson.model.FreeStyleProject) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

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