use of jenkins.branch.BranchSource 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.BranchSource in project blueocean-plugin by jenkinsci.
the class MultiBranchTest method favoritedFromClassicTest.
@Test
public void favoritedFromClassicTest() 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();
Favorites.toggleFavorite(user, p);
user.save();
String token = getJwtToken(j.jenkins, "alice", "alice");
List l = new RequestBuilder(baseUrl).get("/users/" + user.getId() + "/favorites/").jwtToken(token).build(List.class);
Assert.assertEquals(1, l.size());
Map branch = (Map) ((Map) l.get(0)).get("item");
validatePipeline(p, branch);
String c = (String) branch.get("_class");
Assert.assertEquals(BranchImpl.class.getName(), c);
String href = getHrefFromLinks((Map) l.get(0), "self");
Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/p/branches/master/favorite/", href);
Map m = new RequestBuilder(baseUrl).put(getUrlFromHref(getUrlFromHref(href))).jwtToken(token).data(MapsHelper.of("favorite", false)).build(Map.class);
branch = (Map) m.get("item");
validatePipeline(p, branch);
c = (String) branch.get("_class");
Assert.assertEquals(BranchImpl.class.getName(), c);
l = new RequestBuilder(baseUrl).get("/users/" + user.getId() + "/favorites/").jwtToken(token).build(List.class);
Assert.assertEquals(0, l.size());
}
use of jenkins.branch.BranchSource in project blueocean-plugin by jenkinsci.
the class MultiBranchTest method getMultiBranchPipelineRunChangeSets.
@Test
public void getMultiBranchPipelineRunChangeSets() throws Exception {
setupScmWithChangeSet();
WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo3.toString(), "", "*", "", false)));
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(1, mp.getItems().size());
String[] messages = { "tweaked11", "tweaked12", "tweaked13", "tweaked14" };
sampleRepo3.git("checkout", "master");
sampleRepo3.write("file", "subsequent content11");
sampleRepo3.git("commit", "--all", "--message=" + messages[0]);
sampleRepo3.git("checkout", "master");
sampleRepo3.write("file", "subsequent content12");
sampleRepo3.git("commit", "--all", "--message=" + messages[1]);
sampleRepo3.git("checkout", "master");
sampleRepo3.write("file", "subsequent content13");
sampleRepo3.git("commit", "--all", "--message=" + messages[2]);
sampleRepo3.git("checkout", "master");
sampleRepo3.write("file", "subsequent content14");
sampleRepo3.git("commit", "--all", "--message=" + messages[3]);
WorkflowRun b4 = p.scheduleBuild2(0).get();
j.waitUntilNoActivity();
assertEquals(b4.getNumber(), 2);
Assert.assertEquals(1, b4.getChangeSets().size());
ChangeLogSet.Entry changeLog = b4.getChangeSets().get(0).iterator().next();
int i = 0;
for (ChangeLogSet.Entry c : b4.getChangeSets().get(0)) {
Assert.assertEquals(messages[i], c.getMsg());
i++;
}
Map run = get("/organizations/jenkins/pipelines/p/branches/master/runs/" + b4.getId() + "/");
validateRun(b4, run);
List<Map> changeSet = (List<Map>) run.get("changeSet");
Map c = changeSet.get(0);
Assert.assertEquals(changeLog.getCommitId(), c.get("commitId"));
Map a = (Map) c.get("author");
Assert.assertEquals(changeLog.getAuthor().getId(), a.get("id"));
Assert.assertEquals(changeLog.getAuthor().getFullName(), a.get("fullName"));
int j = 0;
for (ChangeLogSet.Entry cs : b4.getChangeSets().get(0)) {
Assert.assertEquals(cs.getCommitId(), changeSet.get(j).get("commitId"));
j++;
}
Assert.assertEquals(i, j);
}
use of jenkins.branch.BranchSource in project blueocean-plugin by jenkinsci.
the class MultiBranchTest method createUserFavouriteMultibranchTopLevelTest.
@Test
public void createUserFavouriteMultibranchTopLevelTest() 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");
Map m = new RequestBuilder(baseUrl).put("/organizations/jenkins/pipelines/p/favorite").jwtToken(token).data(MapsHelper.of("favorite", true)).build(Map.class);
Map branch = (Map) m.get("item");
validatePipeline(p, branch);
String c = (String) branch.get("_class");
Assert.assertEquals(BranchImpl.class.getName(), c);
List l = new RequestBuilder(baseUrl).get("/users/" + user.getId() + "/favorites/").jwtToken(token).build(List.class);
Assert.assertEquals(1, l.size());
branch = (Map) ((Map) l.get(0)).get("item");
validatePipeline(p, branch);
c = (String) branch.get("_class");
Assert.assertEquals(BranchImpl.class.getName(), c);
Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/p/branches/master/favorite/", getHrefFromLinks((Map) l.get(0), "self"));
String ref = getHrefFromLinks((Map) l.get(0), "self");
m = new RequestBuilder(baseUrl).put(getUrlFromHref(ref)).jwtToken(token).data(MapsHelper.of("favorite", false)).build(Map.class);
branch = (Map) m.get("item");
validatePipeline(p, branch);
c = (String) branch.get("_class");
Assert.assertEquals(BranchImpl.class.getName(), c);
l = new RequestBuilder(baseUrl).get("/users/" + user.getId() + "/favorites/").jwtToken(token).build(List.class);
Assert.assertEquals(0, l.size());
new RequestBuilder(baseUrl).get("/users/" + user.getId() + "/favorites/").jwtToken(getJwtToken(j.jenkins, "bob", "bob")).status(403).build(String.class);
}
use of jenkins.branch.BranchSource in project blueocean-plugin by jenkinsci.
the class MultiBranchTest method createUserFavouriteMultibranchBranchTest.
@Test
public void createUserFavouriteMultibranchBranchTest() 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();
WorkflowJob p1 = scheduleAndFindBranchProject(mp, "feature2");
String token = getJwtToken(j.jenkins, "alice", "alice");
Map map = new RequestBuilder(baseUrl).put("/organizations/jenkins/pipelines/p/branches/feature2/favorite").jwtToken(token).data(MapsHelper.of("favorite", true)).build(Map.class);
validatePipeline(p1, (Map) map.get("item"));
Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/p/branches/feature2/favorite/", getHrefFromLinks(map, "self"));
List l = new RequestBuilder(baseUrl).get("/users/" + user.getId() + "/favorites/").jwtToken(token).build(List.class);
Assert.assertEquals(1, l.size());
Map branch = (Map) ((Map) l.get(0)).get("item");
Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/p/branches/feature2/favorite/", getHrefFromLinks((Map) l.get(0), "self"));
validatePipeline(p1, branch);
String c = (String) branch.get("_class");
Assert.assertEquals(BranchImpl.class.getName(), c);
map = new RequestBuilder(baseUrl).put(getUrlFromHref(getHrefFromLinks((Map) l.get(0), "self"))).jwtToken(token).data(MapsHelper.of("favorite", false)).build(Map.class);
validatePipeline(p1, (Map) map.get("item"));
Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/p/branches/feature2/favorite/", getHrefFromLinks(map, "self"));
l = new RequestBuilder(baseUrl).get("/users/" + user.getId() + "/favorites/").jwtToken(token).build(List.class);
Assert.assertEquals(0, l.size());
new RequestBuilder(baseUrl).get("/users/" + user.getId() + "/favorites/").jwtToken(getJwtToken(j.jenkins, "bob", "bob")).status(403).build(String.class);
}
Aggregations