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"));
}
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"));
}
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());
}
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);
}
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"));
}
Aggregations