Search in sources :

Example 51 with WorkflowJob

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

the class JobAnalyticsTest method createMultiBranch.

private void createMultiBranch(GitSampleRepoRule rule) throws Exception {
    WorkflowMultiBranchProject mp = j.createProject(WorkflowMultiBranchProject.class, UUID.randomUUID().toString());
    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, rule.toString(), "", "*", "", false), new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    mp.save();
    mp.scheduleBuild2(0).getFuture().get();
    mp.getIndexing().getLogText().writeLogTo(0, System.out);
    j.waitUntilNoActivity();
    WorkflowJob master = mp.getItemByBranchName("master");
    assertNotNull(master);
    WorkflowRun lastBuild = master.getLastBuild();
    assertNotNull(lastBuild);
    assertEquals(Result.SUCCESS, lastBuild.getResult());
}
Also used : WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) GitSCMSource(jenkins.plugins.git.GitSCMSource) BranchSource(jenkins.branch.BranchSource) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) DefaultBranchPropertyStrategy(jenkins.branch.DefaultBranchPropertyStrategy) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun)

Example 52 with WorkflowJob

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

the class BlueJUnitTestResultTest method createsTestResult.

@Test
public void createsTestResult() throws Exception {
    URL resource = Resources.getResource(getClass(), "BlueJUnitTestResultTest.jenkinsfile");
    String jenkinsFile = Resources.toString(resource, Charsets.UTF_8);
    WorkflowJob p = j.createProject(WorkflowJob.class, "project");
    p.setDefinition(new CpsFlowDefinition(jenkinsFile, false));
    p.save();
    Run r = p.scheduleBuild2(0).waitForStart();
    j.waitUntilNoActivity();
    BlueRun test = BlueRunFactory.getRun(r, new Reachable() {

        @Override
        public Link getLink() {
            return new Link("test");
        }
    });
    Assert.assertEquals(3, Iterators.size(test.getTests().iterator()));
    BluePipelineNode node = mock(BluePipelineNode.class);
    when(node.getId()).thenReturn("6");
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) BlueRun(io.jenkins.blueocean.rest.model.BlueRun) Reachable(io.jenkins.blueocean.rest.Reachable) BlueRun(io.jenkins.blueocean.rest.model.BlueRun) Run(hudson.model.Run) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) BluePipelineNode(io.jenkins.blueocean.rest.model.BluePipelineNode) URL(java.net.URL) Link(io.jenkins.blueocean.rest.hal.Link) Test(org.junit.Test)

Example 53 with WorkflowJob

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

the class BlueTrendsApiTest method getJUnitTrends.

@Test
public void getJUnitTrends() throws Exception {
    URL resource = Resources.getResource(getClass(), "BlueJUnitTestResultTest.jenkinsfile");
    String jenkinsFile = Resources.toString(resource, Charsets.UTF_8);
    WorkflowJob p = j.createProject(WorkflowJob.class, "project");
    p.setDefinition(new CpsFlowDefinition(jenkinsFile, false));
    p.save();
    Run run;
    for (int i = 0; i < 10; i++) {
        run = p.scheduleBuild2(0).waitForStart();
        j.waitForCompletion(run);
    }
    Map trend = new RequestBuilder(baseUrl).get("/organizations/jenkins/pipelines/" + p.getName() + "/trends/junit/").build(Map.class);
    List rows;
    Map testRow;
    Assert.assertNotNull(trend);
    Map columns = (Map) trend.get("columns");
    Assert.assertNotNull(columns);
    Assert.assertEquals(7, columns.keySet().size());
    rows = new RequestBuilder(baseUrl).get("/organizations/jenkins/pipelines/" + p.getName() + "/trends/junit/rows").build(List.class);
    Assert.assertNotNull(rows);
    Assert.assertEquals(10, rows.size());
    testRow = (Map) rows.get(0);
    Assert.assertEquals("10", testRow.get(BlueTableRow.ID));
    Assert.assertEquals(3, testRow.get(BlueJUnitTrend.TOTAL));
    Assert.assertEquals(2, testRow.get(BlueJUnitTrend.PASSED));
    Assert.assertEquals(1, testRow.get(BlueJUnitTrend.FAILED));
    Assert.assertEquals(1, testRow.get(BlueJUnitTrend.EXISTING_FAILED));
    Assert.assertEquals(0, testRow.get(BlueJUnitTrend.FIXED));
    Assert.assertEquals(0, testRow.get(BlueJUnitTrend.REGRESSIONS));
    Assert.assertEquals(0, testRow.get(BlueJUnitTrend.SKIPPED));
    rows = new RequestBuilder(baseUrl).get("/organizations/jenkins/pipelines/" + p.getName() + "/trends/junit/rows?start=5&limit=5").build(List.class);
    Assert.assertNotNull(rows);
    Assert.assertEquals(5, rows.size());
    testRow = (Map) rows.get(0);
    Assert.assertEquals("5", testRow.get(BlueTableRow.ID));
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) Run(hudson.model.Run) List(java.util.List) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Map(java.util.Map) URL(java.net.URL) Test(org.junit.Test) BaseTest(io.jenkins.blueocean.service.embedded.BaseTest)

Example 54 with WorkflowJob

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

the class MultiBranchTest method getMultiBranchPipelineRunStages.

@Test
public void getMultiBranchPipelineRunStages() throws Exception {
    WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
    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());
    }
    WorkflowJob p = scheduleAndFindBranchProject(mp, "master");
    j.waitUntilNoActivity();
    WorkflowRun b1 = p.getLastBuild();
    assertEquals(1, b1.getNumber());
    assertEquals(3, mp.getItems().size());
    j.waitForCompletion(b1);
    List<Map> nodes = get("/organizations/jenkins/pipelines/p/branches/master/runs/1/nodes", List.class);
    Assert.assertEquals(3, nodes.size());
}
Also used : WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) 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) DefaultBranchPropertyStrategy(jenkins.branch.DefaultBranchPropertyStrategy) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Test(org.junit.Test)

Example 55 with WorkflowJob

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

the class PipelineNodeTest method BlockStageNodesFailureTest1.

@Test
public void BlockStageNodesFailureTest1() throws Exception {
    WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
    job1.setDefinition(new CpsFlowDefinition("node{\n" + "    stage ('Build') {\n" + "            sh 'echo1 \"Building\"'\n" + "    }\n" + "    stage ('Test') {\n" + "            sh 'echo testing'\n" + "    }\n" + "    stage ('Deploy') {\n" + "            sh 'echo deploy'\n" + "    }\n" + "}"));
    WorkflowRun b1 = job1.scheduleBuild2(0).get();
    j.assertBuildStatus(Result.FAILURE, b1);
    List<Map> nodes = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/", List.class);
    Assert.assertEquals(1, nodes.size());
    Assert.assertEquals("FAILURE", nodes.get(0).get("result"));
    Assert.assertEquals("FINISHED", nodes.get(0).get("state"));
}
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) Test(org.junit.Test)

Aggregations

WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)100 Test (org.junit.Test)91 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)74 Map (java.util.Map)73 CpsFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition)62 ImmutableMap (com.google.common.collect.ImmutableMap)55 List (java.util.List)34 ImmutableList (com.google.common.collect.ImmutableList)28 WorkflowMultiBranchProject (org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject)26 BranchSource (jenkins.branch.BranchSource)24 GitSCMSource (jenkins.plugins.git.GitSCMSource)24 SCMSource (jenkins.scm.api.SCMSource)23 DefaultBranchPropertyStrategy (jenkins.branch.DefaultBranchPropertyStrategy)20 RunList (hudson.util.RunList)19 FlowNode (org.jenkinsci.plugins.workflow.graph.FlowNode)17 ArrayList (java.util.ArrayList)10 URL (java.net.URL)9 Run (hudson.model.Run)8 Issue (org.jvnet.hudson.test.Issue)8 CpsFlowExecution (org.jenkinsci.plugins.workflow.cps.CpsFlowExecution)7