Search in sources :

Example 11 with SCMSource

use of jenkins.scm.api.SCMSource 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 12 with SCMSource

use of jenkins.scm.api.SCMSource in project blueocean-plugin by jenkinsci.

the class MultiBranchTest method getMultiBranchPipelinesWithNonMasterBranch.

@Test
public void getMultiBranchPipelinesWithNonMasterBranch() throws Exception {
    sampleRepo.git("branch", "-D", "master");
    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());
    }
    mp.scheduleBuild2(0).getFuture().get();
    List<Map> resp = get("/organizations/jenkins/pipelines/", List.class);
    Assert.assertEquals(1, resp.size());
    validateMultiBranchPipeline(mp, resp.get(0), 2);
    assertNull(mp.getBranch("master"));
}
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) DefaultBranchPropertyStrategy(jenkins.branch.DefaultBranchPropertyStrategy) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 13 with SCMSource

use of jenkins.scm.api.SCMSource in project blueocean-plugin by jenkinsci.

the class PipelineNodeTest method declarativeSyntheticSteps.

@Test
public void declarativeSyntheticSteps() 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(\"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(2, stages.size());
    Assert.assertEquals("build", stages.get(0).getDisplayName());
    Assert.assertEquals("deploy", stages.get(1).getDisplayName());
    List<Map> resp = get("/organizations/jenkins/pipelines/p/pipelines/master/runs/" + b1.getId() + "/nodes/", List.class);
    Assert.assertEquals(2, resp.size());
    Assert.assertEquals("build", resp.get(0).get("displayName"));
    Assert.assertEquals("deploy", resp.get(1).get("displayName"));
    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(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 14 with SCMSource

use of jenkins.scm.api.SCMSource in project blueocean-plugin by jenkinsci.

the class BlueOceanWebURLBuilderTest method getMultiBranchPipelineInsideFolder.

@Test
public void getMultiBranchPipelineInsideFolder() throws Exception {
    MockFolder folder1 = jenkinsRule.createFolder("folder1");
    MockFolder folder2 = folder1.createProject(MockFolder.class, "folder two with spaces");
    WorkflowMultiBranchProject mp = folder2.createProject(WorkflowMultiBranchProject.class, "p");
    String blueOceanURL;
    blueOceanURL = BlueOceanWebURLBuilder.toBlueOceanURL(mp);
    assertURL("blue/organizations/jenkins/folder1%2Ffolder%20two%20with%20spaces%2Fp/branches", blueOceanURL);
    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();
    jenkinsRule.waitUntilNoActivity();
    // All branch jobs should just resolve back to the same top level branches
    // page for the multibranch job in Blue Ocean.
    WorkflowJob masterJob = findBranchProject(mp, "master");
    blueOceanURL = BlueOceanWebURLBuilder.toBlueOceanURL(masterJob);
    assertURL("blue/organizations/jenkins/folder1%2Ffolder%20two%20with%20spaces%2Fp/branches", blueOceanURL);
    WorkflowJob featureUx1Job = findBranchProject(mp, "feature/ux-1");
    blueOceanURL = BlueOceanWebURLBuilder.toBlueOceanURL(featureUx1Job);
    assertURL("blue/organizations/jenkins/folder1%2Ffolder%20two%20with%20spaces%2Fp/branches", blueOceanURL);
    WorkflowJob feature2Job = findBranchProject(mp, "feature2");
    blueOceanURL = BlueOceanWebURLBuilder.toBlueOceanURL(feature2Job);
    assertURL("blue/organizations/jenkins/folder1%2Ffolder%20two%20with%20spaces%2Fp/branches", blueOceanURL);
    // Runs on the jobs
    blueOceanURL = BlueOceanWebURLBuilder.toBlueOceanURL(masterJob.getFirstBuild());
    assertURL("blue/organizations/jenkins/folder1%2Ffolder%20two%20with%20spaces%2Fp/detail/master/1", blueOceanURL);
    blueOceanURL = BlueOceanWebURLBuilder.toBlueOceanURL(featureUx1Job.getFirstBuild());
    assertURL("blue/organizations/jenkins/folder1%2Ffolder%20two%20with%20spaces%2Fp/detail/feature%2Fux-1/1", blueOceanURL);
}
Also used : WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) GitSCMSource(jenkins.plugins.git.GitSCMSource) SCMSource(jenkins.scm.api.SCMSource) GitSCMSource(jenkins.plugins.git.GitSCMSource) MockFolder(org.jvnet.hudson.test.MockFolder) BranchSource(jenkins.branch.BranchSource) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) DefaultBranchPropertyStrategy(jenkins.branch.DefaultBranchPropertyStrategy) Test(org.junit.Test)

Example 15 with SCMSource

use of jenkins.scm.api.SCMSource in project blueocean-plugin by jenkinsci.

the class AbstractRunImplTest method replayRunTestMB.

// Disabled, see JENKINS-40084
// @Test
public void replayRunTestMB() throws Exception {
    j.createOnlineSlave(Label.get("remote"));
    sampleRepo.write("Jenkinsfile", "node('remote') {\n" + "    ws {\n" + "       checkout scm\n" + "       stage 'build'\n " + "node {echo 'Building'}\n" + "       stage 'test'\nnode { echo 'Testing'}\n" + "       stage 'deploy'\nnode { echo 'Deploying'}\n" + "       }\n" + "   }");
    sampleRepo.git("add", "Jenkinsfile");
    sampleRepo.git("commit", "--message=init");
    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());
    }
    mp.scheduleBuild2(0).getFuture().get();
    WorkflowJob job1 = mp.getItem("master");
    WorkflowRun b1 = job1.scheduleBuild2(0).waitForStart();
    j.waitForCompletion(b1);
    j.assertBuildStatusSuccess(b1);
    sampleRepo.write("file1", "");
    sampleRepo.git("add", "file1");
    sampleRepo.git("commit", "--message=init");
    WorkflowRun b2 = job1.scheduleBuild2(0).get();
    j.assertBuildStatusSuccess(b2);
    Assert.assertNotEquals(new PipelineRunImpl(b1, null).getCommitId(), new PipelineRunImpl(b2, null).getCommitId());
    Map replayBuild = request().post("/organizations/jenkins/pipelines/p/branches/master/runs/" + b1.getNumber() + "/replay").build(Map.class);
    Queue.Item item = j.getInstance().getQueue().getItem(Long.parseLong((String) replayBuild.get("id")));
    WorkflowRun replayedRun = (WorkflowRun) item.getFuture().get();
    Map r = request().get("/organizations/jenkins/pipelines/p/branches/master/runs/" + replayedRun.getNumber() + "/").build(Map.class);
    assertEquals(new PipelineRunImpl(b1, null).getCommitId(), r.get("commitId"));
}
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) Queue(hudson.model.Queue) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun)

Aggregations

SCMSource (jenkins.scm.api.SCMSource)26 BranchSource (jenkins.branch.BranchSource)25 GitSCMSource (jenkins.plugins.git.GitSCMSource)25 WorkflowMultiBranchProject (org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject)25 Test (org.junit.Test)23 Map (java.util.Map)22 DefaultBranchPropertyStrategy (jenkins.branch.DefaultBranchPropertyStrategy)22 ImmutableMap (com.google.common.collect.ImmutableMap)21 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)17 List (java.util.List)11 ImmutableList (com.google.common.collect.ImmutableList)10 ArrayList (java.util.ArrayList)9 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)7 MockFolder (org.jvnet.hudson.test.MockFolder)4 FreeStyleProject (hudson.model.FreeStyleProject)3 Queue (hudson.model.Queue)2 RunList (hudson.util.RunList)2 FlowNode (org.jenkinsci.plugins.workflow.graph.FlowNode)2 GitLabConnectionProperty (com.dabsquared.gitlabjenkins.connection.GitLabConnectionProperty)1 BuildData (hudson.plugins.git.util.BuildData)1