Search in sources :

Example 11 with WorkflowJob

use of org.jenkinsci.plugins.workflow.job.WorkflowJob in project blueocean-plugin by jenkinsci.

the class LinkResolverTest method nestedFolderJobLinkResolveTest.

@Test
public void nestedFolderJobLinkResolveTest() throws IOException {
    Project f = j.createFreeStyleProject("fstyle1");
    MockFolder folder1 = j.createFolder("folder1");
    Project p1 = folder1.createProject(FreeStyleProject.class, "test1");
    MockFolder folder2 = folder1.createProject(MockFolder.class, "folder2");
    MockFolder folder3 = folder2.createProject(MockFolder.class, "folder3");
    Project p2 = folder2.createProject(FreeStyleProject.class, "test2");
    Project p3 = folder3.createProject(FreeStyleProject.class, "test3");
    WorkflowJob pipelineJob1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
    pipelineJob1.setDefinition(new CpsFlowDefinition("stage \"Build\"\n" + "    node {\n" + "       sh \"echo here\"\n" + "    }\n" + "\n"));
    WorkflowJob pipelineJob2 = folder2.createProject(WorkflowJob.class, "pipeline2");
    pipelineJob2.setDefinition(new CpsFlowDefinition("stage \"Build\"\n" + "    node {\n" + "       sh \"echo here\"\n" + "    }\n" + "\n"));
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/pipeline1/", LinkResolver.resolveLink(pipelineJob1).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/folder2/pipelines/pipeline2/", LinkResolver.resolveLink(pipelineJob2).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/fstyle1/", LinkResolver.resolveLink(f).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/", LinkResolver.resolveLink(folder1).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/test1/", LinkResolver.resolveLink(p1).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/folder2/", LinkResolver.resolveLink(folder2).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/folder2/pipelines/test2/", LinkResolver.resolveLink(p2).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/folder2/pipelines/folder3/", LinkResolver.resolveLink(folder3).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/folder2/pipelines/folder3/pipelines/test3/", LinkResolver.resolveLink(p3).getHref());
}
Also used : Project(hudson.model.Project) FreeStyleProject(hudson.model.FreeStyleProject) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) MockFolder(org.jvnet.hudson.test.MockFolder) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Test(org.junit.Test)

Example 12 with WorkflowJob

use of org.jenkinsci.plugins.workflow.job.WorkflowJob in project blueocean-plugin by jenkinsci.

the class PipelineApiTest method getPipelineJobRunTest.

@Test
public void getPipelineJobRunTest() throws Exception {
    WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
    job1.setDefinition(new CpsFlowDefinition("" + "node {" + "   stage ('Build1'); " + "   echo ('Building'); " + "   stage ('Test1'); " + "   echo ('Testing'); " + "}"));
    WorkflowRun b1 = job1.scheduleBuild2(0).get();
    j.assertBuildStatusSuccess(b1);
    Map resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1");
    validateRun(b1, resp);
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Map(java.util.Map) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Test(org.junit.Test)

Example 13 with WorkflowJob

use of org.jenkinsci.plugins.workflow.job.WorkflowJob in project blueocean-plugin by jenkinsci.

the class PipelineApiTest method getPipelineRunblockingStopTest.

//TODO: Fix test - see JENKINS-38319
//@Test
public void getPipelineRunblockingStopTest() 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 = //default timeOutInSecs=10 sec
    request().put("/organizations/jenkins/pipelines/pipeline1/runs/1/stop/?blocking=true").build(Map.class);
    Assert.assertEquals(r.get("state"), "FINISHED");
    Assert.assertEquals(r.get("result"), "ABORTED");
    j.assertBuildStatus(Result.ABORTED, b1);
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Map(java.util.Map) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun)

Example 14 with WorkflowJob

use of org.jenkinsci.plugins.workflow.job.WorkflowJob in project blueocean-plugin by jenkinsci.

the class PipelineApiTest method getPipelineJobActivities.

@Test
public void getPipelineJobActivities() throws Exception {
    WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
    job1.setDefinition(new CpsFlowDefinition("" + "node {" + "   stage ('Build1'); " + "   echo ('Building'); " + "   stage ('Test1'); " + "   sleep 10000      " + "   echo ('Testing'); " + "}"));
    job1.setConcurrentBuild(false);
    WorkflowRun r = job1.scheduleBuild2(0).waitForStart();
    job1.scheduleBuild2(0);
    List l = request().get("/organizations/jenkins/pipelines/pipeline1/activities").build(List.class);
    Assert.assertEquals(2, l.size());
    Assert.assertEquals("io.jenkins.blueocean.service.embedded.rest.QueueItemImpl", ((Map) l.get(0)).get("_class"));
    Assert.assertEquals("io.jenkins.blueocean.rest.impl.pipeline.PipelineRunImpl", ((Map) l.get(1)).get("_class"));
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) List(java.util.List) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Test(org.junit.Test)

Example 15 with WorkflowJob

use of org.jenkinsci.plugins.workflow.job.WorkflowJob in project blueocean-plugin by jenkinsci.

the class PipelineApiTest method pipelineJobCapabilityTest.

@Test
public void pipelineJobCapabilityTest() throws Exception {
    WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
    job1.setDefinition(new CpsFlowDefinition("" + "node {" + "   stage ('Build1'); " + "   sh('sleep 60') " + "   stage ('Test1'); " + "   echo ('Testing'); " + "}"));
    Map response = get("/organizations/jenkins/pipelines/pipeline1/");
    String clazz = (String) response.get("_class");
    response = get("/classes/" + clazz + "/");
    Assert.assertNotNull(response);
    List<String> classes = (List<String>) response.get("classes");
    Assert.assertTrue(classes.contains("hudson.model.Job") && classes.contains("org.jenkinsci.plugins.workflow.job.WorkflowJob") && classes.contains("io.jenkins.blueocean.rest.model.BluePipeline") && !classes.contains("io.jenkins.blueocean.rest.model.BlueBranch"));
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) List(java.util.List) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Map(java.util.Map) Test(org.junit.Test)

Aggregations

WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)68 Test (org.junit.Test)59 Map (java.util.Map)56 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)51 ImmutableMap (com.google.common.collect.ImmutableMap)46 CpsFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition)46 List (java.util.List)26 ImmutableList (com.google.common.collect.ImmutableList)23 WorkflowMultiBranchProject (org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject)19 BranchSource (jenkins.branch.BranchSource)17 GitSCMSource (jenkins.plugins.git.GitSCMSource)17 SCMSource (jenkins.scm.api.SCMSource)17 RunList (hudson.util.RunList)16 DefaultBranchPropertyStrategy (jenkins.branch.DefaultBranchPropertyStrategy)14 FlowNode (org.jenkinsci.plugins.workflow.graph.FlowNode)13 ArrayList (java.util.ArrayList)8 FlowGraphTable (org.jenkinsci.plugins.workflow.support.visualization.table.FlowGraphTable)4 JSONObject (net.sf.json.JSONObject)3 CpsFlowExecution (org.jenkinsci.plugins.workflow.cps.CpsFlowExecution)3 InputAction (org.jenkinsci.plugins.workflow.support.steps.input.InputAction)3