use of jenkins.scm.api.SCMSource in project blueocean-plugin by jenkinsci.
the class MultiBranchTest method startMultiBranchPipelineRuns.
@Test
public void startMultiBranchPipelineRuns() 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, "feature%2Fux-1");
j.waitUntilNoActivity();
Map resp = post("/organizations/jenkins/pipelines/p/branches/" + Util.rawEncode("feature%2Fux-1") + "/runs/", Collections.EMPTY_MAP);
String id = (String) resp.get("id");
String link = getHrefFromLinks(resp, "self");
Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/p/branches/feature%252Fux-1/queue/" + id + "/", link);
}
use of jenkins.scm.api.SCMSource in project blueocean-plugin by jenkinsci.
the class MultiBranchTest method branchCapabilityTest.
@Test
public void branchCapabilityTest() 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();
Map response = get("/organizations/jenkins/pipelines/p/branches/master/", Map.class);
String clazz = (String) response.get("_class");
response = get("/classes/" + clazz + "/");
Assert.assertNotNull(response);
List<String> classes = (List<String>) response.get("classes");
Assert.assertTrue(classes.contains(JENKINS_JOB) && classes.contains(JENKINS_WORKFLOW_JOB) && classes.contains(BLUE_BRANCH) && classes.contains(BLUE_PIPELINE) && classes.contains(PULL_REQUEST));
}
use of jenkins.scm.api.SCMSource in project blueocean-plugin by jenkinsci.
the class MultiBranchTest method getPipelineJobActivities.
//Disabled test for now as I can't get it to work. Tested manually.
//@Test
public void getPipelineJobActivities() 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.scm.api.SCMSource in project blueocean-plugin by jenkinsci.
the class MultiBranchTest method getMultiBranchPipelineInsideFolder.
@Test
public void getMultiBranchPipelineInsideFolder() throws IOException, ExecutionException, InterruptedException {
MockFolder folder1 = j.createFolder("folder1");
WorkflowMultiBranchProject mp = folder1.createProject(WorkflowMultiBranchProject.class, "p");
mp.setDisplayName("My MBP");
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();
Map r = get("/organizations/jenkins/pipelines/folder1/pipelines/p/");
validateMultiBranchPipeline(mp, r, 3);
Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/p/", ((Map) ((Map) r.get("_links")).get("self")).get("href"));
Assert.assertEquals("folder1/My%20MBP", r.get("fullDisplayName"));
r = get("/organizations/jenkins/pipelines/folder1/pipelines/p/master/");
Assert.assertEquals("folder1/My%20MBP/master", r.get("fullDisplayName"));
}
use of jenkins.scm.api.SCMSource in project blueocean-plugin by jenkinsci.
the class MultiBranchTest method testMultiBranchPipelineBranchSecurePermissions.
@Test
public void testMultiBranchPipelineBranchSecurePermissions() throws IOException, ExecutionException, InterruptedException {
j.jenkins.setSecurityRealm(new HudsonPrivateSecurityRealm(false));
j.jenkins.setAuthorizationStrategy(new LegacyAuthorizationStrategy());
MockFolder folder1 = j.createFolder("folder1");
WorkflowMultiBranchProject mp = folder1.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();
Map r = get("/organizations/jenkins/pipelines/folder1/pipelines/p/");
Map<String, Boolean> permissions = (Map<String, Boolean>) r.get("permissions");
Assert.assertFalse(permissions.get("create"));
Assert.assertTrue(permissions.get("read"));
Assert.assertFalse(permissions.get("start"));
Assert.assertFalse(permissions.get("stop"));
r = get("/organizations/jenkins/pipelines/folder1/pipelines/p/branches/master/");
permissions = (Map<String, Boolean>) r.get("permissions");
Assert.assertFalse(permissions.get("create"));
Assert.assertFalse(permissions.get("start"));
Assert.assertFalse(permissions.get("stop"));
Assert.assertTrue(permissions.get("read"));
}
Aggregations