use of jenkins.scm.api.SCMSource in project blueocean-plugin by jenkinsci.
the class GitReadSaveService method makeSaveRequest.
static GitReadSaveRequest makeSaveRequest(Item item, String branch, String commitMessage, String sourceBranch, String filePath, byte[] contents) {
String defaultBranch = "master";
GitSCMSource gitSource = null;
if (item instanceof MultiBranchProject<?, ?>) {
MultiBranchProject<?, ?> mbp = (MultiBranchProject<?, ?>) item;
for (SCMSource s : mbp.getSCMSources()) {
if (s instanceof GitSCMSource) {
gitSource = (GitSCMSource) s;
}
}
}
return new GitBareRepoReadSaveRequest(gitSource, StringUtils.defaultIfEmpty(branch, defaultBranch), commitMessage, StringUtils.defaultIfEmpty(sourceBranch, defaultBranch), filePath, contents);
}
use of jenkins.scm.api.SCMSource in project blueocean-plugin by jenkinsci.
the class SseEventTest method multiBranchJobEventsWithCustomOrg.
@Test
public void multiBranchJobEventsWithCustomOrg() throws Exception {
MockFolder folder = j.createFolder("TestOrgFolderName");
assertNotNull(folder);
setupScm();
final OneShotEvent success = new OneShotEvent();
final Boolean[] pipelineNameMatched = { null };
final Boolean[] mbpPipelineNameMatched = { null };
SSEConnection con = new SSEConnection(j.getURL(), "me", new ChannelSubscriber() {
@Override
public void onMessage(@Nonnull Message message) {
System.out.println(message);
if ("job".equals(message.get(jenkins_channel))) {
if ("org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject".equals(message.get(jenkins_object_type))) {
if ("pipeline1".equals(message.get(blueocean_job_pipeline_name))) {
mbpPipelineNameMatched[0] = true;
} else {
mbpPipelineNameMatched[0] = false;
}
} else if ("org.jenkinsci.plugins.workflow.job.WorkflowJob".equals(message.get(jenkins_object_type))) {
if ("pipeline1".equals(message.get(blueocean_job_pipeline_name))) {
pipelineNameMatched[0] = true;
} else {
pipelineNameMatched[0] = false;
}
}
}
if (pipelineNameMatched[0] != null && mbpPipelineNameMatched[0] != null) {
success.signal();
}
}
});
con.subscribe("pipeline");
con.subscribe("job");
final WorkflowMultiBranchProject mp = folder.createProject(WorkflowMultiBranchProject.class, "pipeline1");
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 p = mp.getItem("master");
if (p == null) {
mp.getIndexing().writeWholeLogTo(System.out);
fail("master project not found");
}
j.waitUntilNoActivity();
WorkflowRun b1 = p.getLastBuild();
assertEquals(1, b1.getNumber());
assertEquals(2, mp.getItems().size());
success.block(5000);
con.close();
if (success.isSignaled()) {
assertTrue(pipelineNameMatched[0]);
assertTrue(mbpPipelineNameMatched[0]);
}
}
use of jenkins.scm.api.SCMSource in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method encodedStepDescription.
@Test
public void encodedStepDescription() throws Exception {
setupScm("pipeline {\n" + " agent any\n" + " stages {\n" + " stage('Build') {\n" + " steps {\n" + " sh 'echo \"\\033[32m some text \\033[0m\"' \n" + " }\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(1, stages.size());
Assert.assertEquals("Build", stages.get(0).getDisplayName());
List<Map> resp = get("/organizations/jenkins/pipelines/p/pipelines/master/runs/" + b1.getId() + "/nodes/", List.class);
Assert.assertEquals(1, resp.size());
Assert.assertEquals("Build", resp.get(0).get("displayName"));
resp = get("/organizations/jenkins/pipelines/p/pipelines/master/runs/" + b1.getId() + "/steps/", List.class);
Assert.assertEquals(2, resp.size());
assertNotNull(resp.get(0).get("displayName"));
assertEquals("Shell Script", resp.get(1).get("displayName"));
assertEquals("echo \"\u001B[32m some text \u001B[0m\"", resp.get(1).get("displayDescription"));
}
use of jenkins.scm.api.SCMSource in project blueocean-plugin by jenkinsci.
the class MultiBranchTest method testMultiBranchPipelineBranchUnsecurePermissions.
@Test
public void testMultiBranchPipelineBranchUnsecurePermissions() throws IOException, ExecutionException, InterruptedException {
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.assertTrue(permissions.get("create"));
Assert.assertTrue(permissions.get("read"));
Assert.assertTrue(permissions.get("start"));
Assert.assertTrue(permissions.get("stop"));
r = get("/organizations/jenkins/pipelines/folder1/pipelines/p/branches/master/");
permissions = (Map<String, Boolean>) r.get("permissions");
Assert.assertTrue(permissions.get("create"));
Assert.assertTrue(permissions.get("start"));
Assert.assertTrue(permissions.get("stop"));
Assert.assertTrue(permissions.get("read"));
}
use of jenkins.scm.api.SCMSource 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"));
}
Aggregations