use of jenkins.branch.BranchSource in project blueocean-plugin by jenkinsci.
the class MultiBranchTest method parameterizedBranchTest.
@Test
public void parameterizedBranchTest() throws Exception {
setupParameterizedScm();
WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo2.toString(), "", "*", "", false)));
for (SCMSource source : mp.getSCMSources()) {
assertEquals(mp, source.getOwner());
}
WorkflowJob p = scheduleAndFindBranchProject(mp, branches[1]);
j.waitUntilNoActivity();
Map resp = get("/organizations/jenkins/pipelines/p/branches/" + Util.rawEncode(branches[1]) + "/", Map.class);
List<Map<String, Object>> parameters = (List<Map<String, Object>>) resp.get("parameters");
Assert.assertEquals(1, parameters.size());
Assert.assertEquals("param1", parameters.get(0).get("name"));
Assert.assertEquals("StringParameterDefinition", parameters.get(0).get("type"));
Assert.assertEquals("string param", parameters.get(0).get("description"));
Assert.assertEquals("xyz", ((Map) parameters.get(0).get("defaultParameterValue")).get("value"));
resp = post("/organizations/jenkins/pipelines/p/branches/" + Util.rawEncode(branches[1]) + "/runs/", MapsHelper.of("parameters", Arrays.asList(MapsHelper.of("name", "param1", "value", "abc"))), 200);
Assert.assertEquals(branches[1], resp.get("pipeline"));
Thread.sleep(5000);
resp = get("/organizations/jenkins/pipelines/p/branches/" + Util.rawEncode(branches[1]) + "/runs/2/");
Assert.assertEquals("Response should be SUCCESS: " + resp.toString(), "SUCCESS", resp.get("result"));
Assert.assertEquals("Response should be FINISHED: " + resp.toString(), "FINISHED", resp.get("state"));
}
use of jenkins.branch.BranchSource 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.branch.BranchSource in project blueocean-plugin by jenkinsci.
the class MultiBranchTest method multiBranchPipelineIndex.
@Test
public void multiBranchPipelineIndex() throws Exception {
User user = login();
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());
}
Map map = new RequestBuilder(baseUrl).post("/organizations/jenkins/pipelines/p/runs/").jwtToken(getJwtToken(j.jenkins, user.getId(), user.getId())).crumb(getCrumb(j.jenkins)).data(Collections.emptyMap()).status(200).build(Map.class);
assertNotNull(map);
}
use of jenkins.branch.BranchSource in project blueocean-plugin by jenkinsci.
the class MultiBranchTest method getPipelinesTest.
@Test
public void getPipelinesTest() 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();
List<Map> responses = get("/search/?q=type:pipeline;excludedFromFlattening:jenkins.branch.MultiBranchProject", List.class);
Assert.assertEquals(1, responses.size());
}
use of jenkins.branch.BranchSource in project blueocean-plugin by jenkinsci.
the class MultiBranchTest method testMbpPagination.
@Test
public void testMbpPagination() 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());
}
mp.scheduleBuild2(0).getFuture().get();
this.j.waitUntilNoActivity();
// create 6 runs
List<WorkflowRun> launchedItems = new ArrayList<>();
for (String branch : branches) {
WorkflowJob job = findBranchProject(mp, branch);
launchedItems.addAll(job.getBuilds());
for (int j = 0; j < 2; j++) {
launchedItems.add(job.scheduleBuild2(0).waitForStart());
this.j.waitUntilNoActivity();
}
}
// total 9. 3 triggered from indexing and 6 we launched
assertEquals(9, launchedItems.size());
// sort runs
Collections.sort(launchedItems, new Comparator<WorkflowRun>() {
@Override
public int compare(WorkflowRun o1, WorkflowRun o2) {
return new Date(o2.getStartTimeInMillis()).compareTo(new Date(o1.getStartTimeInMillis()));
}
});
// request 10 runs, but should not return 9 runs.
List<Map> resp = get("/organizations/jenkins/pipelines/p/runs?start=0&limit=10", List.class);
// max number of runs are 9
assertEquals(9, resp.size());
for (int i = 0; i < 9; i++) {
Assert.assertEquals(launchedItems.get(i).getId(), (resp.get(i).get("id")));
}
// now call 3 out of 9 runs and see pagination returns only 3 and in right sort order
resp = get("/organizations/jenkins/pipelines/p/runs?start=0&limit=3", List.class);
assertEquals(3, resp.size());
for (int i = 0; i < 3; i++) {
Assert.assertEquals(launchedItems.get(i).getId(), (resp.get(i).get("id")));
}
}
Aggregations