Search in sources :

Example 6 with FreeStyleProject

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

the class PipelineApiTest method getPipelineRunStopTest.

@Test
public void getPipelineRunStopTest() throws Exception {
    WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
    job1.setDefinition(new CpsFlowDefinition("" + "node {" + "   stage ('Build1'); " + "   sh('sleep 60') " + "   stage ('Test1'); " + "   echo ('Testing'); " + "}"));
    WorkflowRun b1 = job1.scheduleBuild2(0).waitForStart();
    Map r = null;
    for (int i = 0; i < 10; i++) {
        r = request().put("/organizations/jenkins/pipelines/pipeline1/runs/1/stop").build(Map.class);
        if (((String) r.get("state")).equalsIgnoreCase("FINISHED"))
            continue;
        Thread.sleep(1000);
    }
    Assert.assertEquals(r.get("state"), "FINISHED");
    Assert.assertEquals(r.get("result"), "ABORTED");
    j.assertBuildStatus(Result.ABORTED, b1);
    FreeStyleProject p = j.createFreeStyleProject("pipeline5");
    p.getBuildersList().add(new Shell("echo hello!\nsleep 69"));
    FreeStyleBuild b2 = p.scheduleBuild2(0).waitForStart();
    for (int i = 0; i < 10; i++) {
        r = put("/organizations/jenkins/pipelines/pipeline5/runs/1/stop", null);
        if (((String) r.get("state")).equalsIgnoreCase("finished"))
            continue;
        Thread.sleep(1000);
    }
    Assert.assertEquals(r.get("state"), "FINISHED");
    Assert.assertEquals(r.get("result"), "ABORTED");
    j.assertBuildStatus(Result.ABORTED, b2);
}
Also used : Shell(hudson.tasks.Shell) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) FreeStyleBuild(hudson.model.FreeStyleBuild) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) FreeStyleProject(hudson.model.FreeStyleProject) Map(java.util.Map) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Test(org.junit.Test)

Example 7 with FreeStyleProject

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

the class MultiBranchTest method getMultiBranchPipelines.

@Test
public void getMultiBranchPipelines() 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/", List.class);
    Assert.assertEquals(2, resp.size());
    validatePipeline(f, resp.get(0));
    validateMultiBranchPipeline(mp, resp.get(1), 3);
    Assert.assertEquals(mp.getBranch("master").getBuildHealth().getScore(), resp.get(0).get("weatherScore"));
}
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 8 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 9 with FreeStyleProject

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

the class PipelineApiTest method getPipelineRunsStopTest.

@Test
public void getPipelineRunsStopTest() throws Exception {
    FreeStyleProject p = j.createFreeStyleProject("p1");
    p.getBuildersList().add(new Shell("sleep 60"));
    FreeStyleBuild b = p.scheduleBuild2(0).waitForStart();
    //wait till its running
    do {
        //sleep for 10ms
        Thread.sleep(10);
    } while (b.hasntStartedYet());
    Map resp = put("/organizations/jenkins/pipelines/p1/runs/" + b.getId() + "/stop/?blocking=true&timeOutInSecs=2", Map.class);
    assertEquals("ABORTED", resp.get("result"));
}
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 10 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)

Aggregations

FreeStyleProject (hudson.model.FreeStyleProject)77 Test (org.junit.Test)49 FreeStyleBuild (hudson.model.FreeStyleBuild)39 Shell (hudson.tasks.Shell)17 Map (java.util.Map)16 JobPropertyImpl (hudson.plugins.promoted_builds.JobPropertyImpl)14 ImmutableMap (com.google.common.collect.ImmutableMap)13 PromotionProcess (hudson.plugins.promoted_builds.PromotionProcess)13 ArrayList (java.util.ArrayList)11 StringParameterDefinition (hudson.model.StringParameterDefinition)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)10 PromotedBuildAction (hudson.plugins.promoted_builds.PromotedBuildAction)8 FreeStyleProjectMock (hudson.model.FreeStyleProjectMock)7 Promotion (hudson.plugins.promoted_builds.Promotion)7 MockFolder (org.jvnet.hudson.test.MockFolder)7 ManualCondition (hudson.plugins.promoted_builds.conditions.ManualCondition)6 ManualApproval (hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval)6 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)5 Descriptor (hudson.model.Descriptor)5 Hudson (hudson.model.Hudson)5