Search in sources :

Example 16 with FlowNode

use of org.jenkinsci.plugins.workflow.graph.FlowNode in project blueocean-plugin by jenkinsci.

the class PipelineNodeTest method getPipelineJobRunNodeTest.

@Test
public void getPipelineJobRunNodeTest() throws Exception {
    WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
    job1.setDefinition(new CpsFlowDefinition("stage 'build'\n" + "node{\n" + "  echo \"Building...\"\n" + "}\n" + "\n" + "stage 'test'\n" + "parallel 'unit':{\n" + "  node{\n" + "    echo \"Unit testing...\"\n" + "  }\n" + "},'integration':{\n" + "  node{\n" + "    echo \"Integration testing...\"\n" + "  }\n" + "}, 'ui':{\n" + "  node{\n" + "    echo \"UI testing...\"\n" + "  }\n" + "}\n" + "\n" + "stage 'deploy'\n" + "node{\n" + "  echo \"Deploying\"\n" + "}"));
    WorkflowRun b1 = job1.scheduleBuild2(0).get();
    j.assertBuildStatusSuccess(b1);
    FlowGraphTable nodeGraphTable = new FlowGraphTable(b1.getExecution());
    nodeGraphTable.build();
    List<FlowNode> nodes = getStages(nodeGraphTable);
    List<FlowNode> parallelNodes = getParallelNodes(nodeGraphTable);
    Assert.assertEquals(6, nodes.size());
    Assert.assertEquals(3, parallelNodes.size());
    // get all nodes for pipeline1
    List<Map> resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/", List.class);
    Assert.assertEquals(nodes.size(), resp.size());
    //Get a node detail
    FlowNode n = nodes.get(0);
    Map node = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/" + n.getId());
    List<Map> edges = (List<Map>) node.get("edges");
    Assert.assertEquals(n.getId(), node.get("id"));
    Assert.assertEquals(getNodeName(n), node.get("displayName"));
    Assert.assertEquals("SUCCESS", node.get("result"));
    Assert.assertEquals(1, edges.size());
    Assert.assertEquals(nodes.get(1).getId(), edges.get(0).get("id"));
    //Get a parllel node detail
    node = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/" + parallelNodes.get(0).getId());
    n = parallelNodes.get(0);
    edges = (List<Map>) node.get("edges");
    Assert.assertEquals(n.getId(), node.get("id"));
    Assert.assertEquals(getNodeName(n), node.get("displayName"));
    Assert.assertEquals("SUCCESS", node.get("result"));
    Assert.assertEquals(1, edges.size());
    Assert.assertEquals(nodes.get(nodes.size() - 1).getId(), edges.get(0).get("id"));
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) FlowGraphTable(org.jenkinsci.plugins.workflow.support.visualization.table.FlowGraphTable) RunList(hudson.util.RunList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode) Test(org.junit.Test)

Example 17 with FlowNode

use of org.jenkinsci.plugins.workflow.graph.FlowNode in project blueocean-plugin by jenkinsci.

the class PipelineNodeTest method declarativeSyntheticSkippedStage.

@Test
public void declarativeSyntheticSkippedStage() throws Exception {
    setupScm("pipeline {\n" + "    agent any\n" + "    stages {\n" + "        stage(\"build\") {\n" + "            steps{\n" + "              sh 'echo \"Start Build\"'\n" + "              echo 'End Build'\n" + "            }\n" + "        }\n" + "        stage(\"SkippedStage\") {\n" + "            when {\n" + "        expression {\n" + "                return false\n" + "        }\n" + "            }\n" + "            steps {\n" + "                script {\n" + "                    echo \"World\"\n" + "                    echo \"Heal it\"\n" + "                }\n" + "\n" + "            }\n" + "        }\n" + "        stage(\"deploy\") {\n" + "            steps{\n" + "              sh 'echo \"Start Deploy\"'\n" + "              sh 'echo \"Deploying...\"'\n" + "              sh 'echo \"End Deploy\"'\n" + "            }           \n" + "        }\n" + "    }\n" + "    post {\n" + "        failure {\n" + "            echo \"failed\"\n" + "        }\n" + "        success {\n" + "            echo \"success\"\n" + "        }\n" + "    }\n" + "}");
    WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false)));
    for (SCMSource source : mp.getSCMSources()) {
        assertEquals(mp, source.getOwner());
    }
    mp.scheduleBuild2(0).getFuture().get();
    j.waitUntilNoActivity();
    WorkflowJob p = scheduleAndFindBranchProject(mp, "master");
    j.waitUntilNoActivity();
    WorkflowRun b1 = p.getLastBuild();
    Assert.assertEquals(Result.SUCCESS, b1.getResult());
    List<FlowNode> stages = getStages(NodeGraphBuilder.NodeGraphBuilderFactory.getInstance(b1));
    Assert.assertEquals(3, stages.size());
    Assert.assertEquals("build", stages.get(0).getDisplayName());
    Assert.assertEquals("SkippedStage", stages.get(1).getDisplayName());
    Assert.assertEquals("deploy", stages.get(2).getDisplayName());
    List<Map> resp = get("/organizations/jenkins/pipelines/p/pipelines/master/runs/" + b1.getId() + "/nodes/", List.class);
    Assert.assertEquals(3, resp.size());
    Assert.assertEquals("build", resp.get(0).get("displayName"));
    Assert.assertEquals("SkippedStage", resp.get(1).get("displayName"));
    Assert.assertEquals("deploy", resp.get(2).get("displayName"));
    //check status
    Assert.assertEquals("SUCCESS", resp.get(0).get("result"));
    Assert.assertEquals("FINISHED", resp.get(0).get("state"));
    Assert.assertEquals("NOT_BUILT", resp.get(1).get("result"));
    Assert.assertEquals("SKIPPED", resp.get(1).get("state"));
    Assert.assertEquals("SUCCESS", resp.get(2).get("result"));
    Assert.assertEquals("FINISHED", resp.get(2).get("state"));
    resp = get("/organizations/jenkins/pipelines/p/pipelines/master/runs/" + b1.getId() + "/steps/", List.class);
    Assert.assertEquals(7, resp.size());
    resp = get("/organizations/jenkins/pipelines/p/pipelines/master/runs/" + b1.getId() + "/nodes/" + stages.get(0).getId() + "/steps/", List.class);
    Assert.assertEquals(3, resp.size());
    resp = get("/organizations/jenkins/pipelines/p/pipelines/master/runs/" + b1.getId() + "/nodes/" + stages.get(1).getId() + "/steps/", List.class);
    Assert.assertEquals(0, resp.size());
    resp = get("/organizations/jenkins/pipelines/p/pipelines/master/runs/" + b1.getId() + "/nodes/" + stages.get(2).getId() + "/steps/", List.class);
    Assert.assertEquals(4, resp.size());
}
Also used : WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) RunList(hudson.util.RunList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) GitSCMSource(jenkins.plugins.git.GitSCMSource) SCMSource(jenkins.scm.api.SCMSource) GitSCMSource(jenkins.plugins.git.GitSCMSource) BranchSource(jenkins.branch.BranchSource) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode) Test(org.junit.Test)

Example 18 with FlowNode

use of org.jenkinsci.plugins.workflow.graph.FlowNode in project blueocean-plugin by jenkinsci.

the class PipelineNodeTest method getPipelineJobRunStepLogTest.

@Test
public void getPipelineJobRunStepLogTest() throws Exception {
    WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
    job1.setDefinition(new CpsFlowDefinition("stage 'build'\n" + "node{\n" + "  echo \"Building...\"\n" + "}\n" + "\n" + "stage 'test'\n" + "parallel 'unit':{\n" + "  node{\n" + "    echo \"Unit testing...\"\n" + "  }\n" + "},'integration':{\n" + "  node{\n" + "    echo \"Integration testing...\"\n" + "  }\n" + "}, 'ui':{\n" + "  node{\n" + "    echo \"UI testing...\"\n" + "  }\n" + "}\n" + "\n" + "stage 'deploy'\n" + "node{\n" + "  echo \"Deploying\"\n" + "}"));
    WorkflowRun b1 = job1.scheduleBuild2(0).get();
    j.assertBuildStatusSuccess(b1);
    NodeGraphBuilder builder = NodeGraphBuilder.NodeGraphBuilderFactory.getInstance(b1);
    List<FlowNode> flowNodes = getAllSteps(b1);
    Map resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/steps/" + flowNodes.get(0).getId() + "/");
    String linkToLog = getActionLink(resp, "org.jenkinsci.plugins.workflow.actions.LogAction");
    assertNotNull(linkToLog);
    assertEquals("/blue/rest/organizations/jenkins/pipelines/pipeline1/runs/1/steps/6/log/", linkToLog);
    String output = get(linkToLog.substring("/blue/rest".length()), String.class);
    Assert.assertNotNull(output);
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode) Test(org.junit.Test)

Example 19 with FlowNode

use of org.jenkinsci.plugins.workflow.graph.FlowNode in project blueocean-plugin by jenkinsci.

the class PipelineNodeTest method getPipelineWihNodesAllStepsTest.

@Test
public void getPipelineWihNodesAllStepsTest() throws Exception {
    WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
    job1.setDefinition(new CpsFlowDefinition("stage 'build'\n" + "node{\n" + "  sh \"echo Building...\"\n" + "}\n" + "\n" + "stage 'test'\n" + "parallel 'unit':{\n" + "  node{\n" + "    echo \"Unit testing...\"\n" + "    sh \"echo Tests running\"\n" + "    sh \"echo Tests completed\"\n" + "  }\n" + "},'integration':{\n" + "  node{\n" + "    echo \"Integration testing...\"\n" + "  }\n" + "}, 'ui':{\n" + "  node{\n" + "    echo \"UI testing...\"\n" + "  }\n" + "}\n" + "\n" + "node{\n" + "  echo \"Done Testing\"\n" + "}" + "\n" + "stage 'deploy'\n" + "node{\n" + "  echo \"Deploying\"\n" + "}" + "\n" + "stage 'deployToProd'\n" + "node{\n" + "  echo \"Deploying to production\"\n" + "}"));
    WorkflowRun b1 = job1.scheduleBuild2(0).get();
    j.assertBuildStatusSuccess(b1);
    FlowGraphTable nodeGraphTable = new FlowGraphTable(b1.getExecution());
    nodeGraphTable.build();
    List<FlowNode> nodes = getStages(nodeGraphTable);
    List<FlowNode> parallelNodes = getParallelNodes(nodeGraphTable);
    Assert.assertEquals(7, nodes.size());
    Assert.assertEquals(3, parallelNodes.size());
    List<Map> resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/steps/", List.class);
    Assert.assertEquals(9, resp.size());
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) FlowGraphTable(org.jenkinsci.plugins.workflow.support.visualization.table.FlowGraphTable) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode) Test(org.junit.Test)

Example 20 with FlowNode

use of org.jenkinsci.plugins.workflow.graph.FlowNode in project blueocean-plugin by jenkinsci.

the class PipelineNodeTest method getPipelineJobRunNodeLogTest.

@Test
public void getPipelineJobRunNodeLogTest() throws Exception {
    WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
    job1.setDefinition(new CpsFlowDefinition("stage 'build'\n" + "node{\n" + "  echo \"Building...\"\n" + "}\n" + "\n" + "stage 'test'\n" + "parallel 'unit':{\n" + "  node{\n" + "    echo \"Unit testing...\"\n" + "  }\n" + "},'integration':{\n" + "  node{\n" + "    echo \"Integration testing...\"\n" + "  }\n" + "}, 'ui':{\n" + "  node{\n" + "    echo \"UI testing...\"\n" + "  }\n" + "}\n" + "\n" + "stage 'deploy'\n" + "node{\n" + "  echo \"Deploying\"\n" + "}"));
    WorkflowRun b1 = job1.scheduleBuild2(0).get();
    j.assertBuildStatusSuccess(b1);
    FlowGraphTable nodeGraphTable = new FlowGraphTable(b1.getExecution());
    nodeGraphTable.build();
    List<FlowNode> nodes = getStages(nodeGraphTable);
    List<FlowNode> parallelNodes = getParallelNodes(nodeGraphTable);
    Assert.assertEquals(6, nodes.size());
    Assert.assertEquals(3, parallelNodes.size());
    String output = get("/organizations/jenkins/pipelines/pipeline1/runs/1/log", String.class);
    assertNotNull(output);
    System.out.println(output);
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) FlowGraphTable(org.jenkinsci.plugins.workflow.support.visualization.table.FlowGraphTable) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode) Test(org.junit.Test)

Aggregations

FlowNode (org.jenkinsci.plugins.workflow.graph.FlowNode)22 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)14 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)13 Test (org.junit.Test)13 ImmutableMap (com.google.common.collect.ImmutableMap)12 Map (java.util.Map)12 CpsFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition)11 ImmutableList (com.google.common.collect.ImmutableList)9 RunList (hudson.util.RunList)9 List (java.util.List)9 StepAtomNode (org.jenkinsci.plugins.workflow.cps.nodes.StepAtomNode)4 TimingInfo (org.jenkinsci.plugins.workflow.pipelinegraphanalysis.TimingInfo)4 FlowGraphTable (org.jenkinsci.plugins.workflow.support.visualization.table.FlowGraphTable)4 BlueRun (io.jenkins.blueocean.rest.model.BlueRun)3 BluePipelineStep (io.jenkins.blueocean.rest.model.BluePipelineStep)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 BranchSource (jenkins.branch.BranchSource)2 GitSCMSource (jenkins.plugins.git.GitSCMSource)2 SCMSource (jenkins.scm.api.SCMSource)2