use of jenkins.branch.DefaultBranchPropertyStrategy 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.DefaultBranchPropertyStrategy in project blueocean-plugin by jenkinsci.
the class BranchContainerImplTest method testBranchOrdering.
@Test
public void testBranchOrdering() throws Exception {
j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
hudson.model.User user = User.get("alice");
user.setFullName("Alice Cooper");
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();
String token = getJwtToken(j.jenkins, "alice", "alice");
new RequestBuilder(baseUrl).put("/organizations/jenkins/pipelines/p/branches/feature2/favorite").jwtToken(token).data(ImmutableMap.of("favorite", true)).build(Map.class);
new RequestBuilder(baseUrl).put("/organizations/jenkins/pipelines/p/branches/feature4/favorite").jwtToken(token).data(ImmutableMap.of("favorite", true)).build(Map.class);
List l = request().get("/organizations/jenkins/pipelines/p/branches/").jwtToken(token).build(List.class);
Assert.assertEquals(4, l.size());
Map o = (Map) l.get(1);
Map o2 = (Map) l.get(0);
WorkflowJob j1 = findBranchProject(mp, (String) o.get("name"));
j.waitForCompletion(j1.getLastBuild());
j.waitForCompletion(j1.scheduleBuild2(0).waitForStart());
WorkflowJob j2 = findBranchProject(mp, (String) o2.get("name"));
j.waitForCompletion(j2.getLastBuild());
List l2 = request().get("/organizations/jenkins/pipelines/p/branches/").jwtToken(token).build(List.class);
Assert.assertEquals(4, l.size());
Map o1 = (Map) l2.get(0);
Map o3 = (Map) l2.get(1);
Assert.assertEquals(o2.get("name"), o1.get("name"));
}
use of jenkins.branch.DefaultBranchPropertyStrategy in project blueocean-plugin by jenkinsci.
the class MultiBranchTest method getMultiBranchPipelinesWithNonMasterBranch.
@Test
public void getMultiBranchPipelinesWithNonMasterBranch() throws Exception {
sampleRepo.git("checkout", "feature2");
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.branch.DefaultBranchPropertyStrategy in project blueocean-plugin by jenkinsci.
the class MultiBranchTest method getPipelineJobrRuns.
// Disabled test for now as I can't get it to work. Tested manually.
@Test
@Ignore
public void getPipelineJobrRuns() throws Exception {
WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
sampleRepo1.init();
sampleRepo1.write("Jenkinsfile", "stage 'build'\n " + "node {echo 'Building'}\n" + "stage 'test'\nnode { echo 'Testing'}\n" + "sleep 10000 \n" + "stage 'deploy'\nnode { echo 'Deploying'}\n");
sampleRepo1.write("file", "initial content");
sampleRepo1.git("add", "Jenkinsfile");
sampleRepo1.git("commit", "--all", "--message=flow");
// create feature branch
sampleRepo1.git("checkout", "-b", "abc");
sampleRepo1.write("Jenkinsfile", "echo \"branch=${env.BRANCH_NAME}\"; " + "node {" + " stage ('Build'); " + " echo ('Building'); " + " stage ('Test'); sleep 10000; " + " echo ('Testing'); " + " stage ('Deploy'); " + " echo ('Deploying'); " + "}");
ScriptApproval.get().approveSignature("method java.lang.String toUpperCase");
sampleRepo1.write("file", "subsequent content1");
sampleRepo1.git("commit", "--all", "--message=tweaked1");
mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo1.toString(), "", "*", "", false), new DefaultBranchPropertyStrategy(new BranchProperty[0])));
for (SCMSource source : mp.getSCMSources()) {
assertEquals(mp, source.getOwner());
}
scheduleAndFindBranchProject(mp);
for (WorkflowJob job : mp.getItems()) {
Queue.Item item = job.getQueueItem();
if (item != null) {
item.getFuture().waitForStart();
}
job.setConcurrentBuild(false);
job.scheduleBuild2(0);
job.scheduleBuild2(0);
}
List l = request().get("/organizations/jenkins/pipelines/p/activities").build(List.class);
Assert.assertEquals(4, l.size());
Assert.assertEquals("io.jenkins.blueocean.service.embedded.rest.QueueItemImpl", ((Map) l.get(0)).get("_class"));
Assert.assertEquals("io.jenkins.blueocean.rest.impl.pipeline.PipelineRunImpl", ((Map) l.get(2)).get("_class"));
}
use of jenkins.branch.DefaultBranchPropertyStrategy 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