use of jenkins.scm.api.SCMSource in project blueocean-plugin by jenkinsci.
the class MultiBranchTest method getMultiBranchPipelineActivityRuns.
@Test
public void getMultiBranchPipelineActivityRuns() 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());
}
scheduleAndFindBranchProject(mp);
j.waitUntilNoActivity();
WorkflowJob p = findBranchProject(mp, "master");
WorkflowRun b1 = p.getLastBuild();
assertEquals(1, b1.getNumber());
assertEquals(3, mp.getItems().size());
//execute feature/ux-1 branch build
p = findBranchProject(mp, "feature%2Fux-1");
WorkflowRun b2 = p.getLastBuild();
assertEquals(1, b2.getNumber());
//execute feature 2 branch build
p = findBranchProject(mp, "feature2");
WorkflowRun b3 = p.getLastBuild();
assertEquals(1, b3.getNumber());
List<Map> resp = get("/organizations/jenkins/pipelines/p/runs", List.class);
Assert.assertEquals(3, resp.size());
Date d1 = new SimpleDateFormat(DATE_FORMAT_STRING).parse((String) resp.get(0).get("startTime"));
Date d2 = new SimpleDateFormat(DATE_FORMAT_STRING).parse((String) resp.get(1).get("startTime"));
Date d3 = new SimpleDateFormat(DATE_FORMAT_STRING).parse((String) resp.get(2).get("startTime"));
Assert.assertTrue(d1.compareTo(d2) >= 0);
Assert.assertTrue(d2.compareTo(d3) >= 0);
for (Map m : resp) {
BuildData d;
WorkflowRun r;
if (m.get("pipeline").equals("master")) {
r = b1;
d = b1.getAction(BuildData.class);
} else if (m.get("pipeline").equals("feature2")) {
r = b3;
d = b3.getAction(BuildData.class);
} else {
r = b2;
d = b2.getAction(BuildData.class);
}
validateRun(r, m);
String commitId = "";
if (d != null) {
commitId = d.getLastBuiltRevision().getSha1String();
Assert.assertEquals(commitId, m.get("commitId"));
}
}
}
use of jenkins.scm.api.SCMSource in project blueocean-plugin by jenkinsci.
the class MultiBranchTest method getMultiBranchPipelineRunStages.
@Test
public void getMultiBranchPipelineRunStages() 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();
WorkflowRun b1 = p.getLastBuild();
assertEquals(1, b1.getNumber());
assertEquals(3, mp.getItems().size());
j.waitForCompletion(b1);
List<Map> nodes = get("/organizations/jenkins/pipelines/p/branches/master/runs/1/nodes", List.class);
Assert.assertEquals(3, nodes.size());
}
use of jenkins.scm.api.SCMSource in project blueocean-plugin by jenkinsci.
the class MultiBranchTest method getMultiBranchPipelineRuns.
@Test
public void getMultiBranchPipelineRuns() 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();
WorkflowRun b1 = p.getLastBuild();
assertEquals(1, b1.getNumber());
assertEquals(3, mp.getItems().size());
//execute feature/ux-1 branch build
p = scheduleAndFindBranchProject(mp, "feature%2Fux-1");
j.waitUntilNoActivity();
WorkflowRun b2 = p.getLastBuild();
assertEquals(1, b2.getNumber());
//execute feature 2 branch build
p = scheduleAndFindBranchProject(mp, "feature2");
j.waitUntilNoActivity();
WorkflowRun b3 = p.getLastBuild();
assertEquals(1, b3.getNumber());
List<Map> br = get("/organizations/jenkins/pipelines/p/branches", List.class);
List<String> branchNames = new ArrayList<>();
List<Integer> weather = new ArrayList<>();
for (Map b : br) {
branchNames.add((String) b.get("name"));
weather.add((int) b.get("weatherScore"));
}
Assert.assertTrue(branchNames.contains(((Map) (br.get(0).get("latestRun"))).get("pipeline")));
for (String n : branches) {
assertTrue(branchNames.contains(n));
}
WorkflowRun[] runs = { b1, b2, b3 };
int i = 0;
for (String n : branches) {
WorkflowRun b = runs[i];
j.waitForCompletion(b);
Map run = get("/organizations/jenkins/pipelines/p/branches/" + Util.rawEncode(n) + "/runs/" + b.getId());
validateRun(b, run);
i++;
}
Map pr = get("/organizations/jenkins/pipelines/p/");
validateMultiBranchPipeline(mp, pr, 3, 3, 0);
sampleRepo.git("checkout", "master");
sampleRepo.write("file", "subsequent content11");
sampleRepo.git("commit", "--all", "--message=tweaked11");
p = scheduleAndFindBranchProject(mp, "master");
j.waitUntilNoActivity();
WorkflowRun b4 = p.getLastBuild();
assertEquals(2, b4.getNumber());
List<Map> run = get("/organizations/jenkins/pipelines/p/branches/master/runs/", List.class);
validateRun(b4, run.get(0));
}
use of jenkins.scm.api.SCMSource in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method declarativeSyntheticSkippedStage.
@Test
public void declarativeSyntheticSkippedStage() throws Exception {
setupScm("pipeline {\n" + " agent any\n" + " stages {\n" + " stage(\"build\") {\n" + " steps{\n" + " sh 'echo \"Start Build\"'\n" + " echo 'End Build'\n" + " }\n" + " }\n" + " stage(\"SkippedStage\") {\n" + " when {\n" + " expression {\n" + " return false\n" + " }\n" + " }\n" + " steps {\n" + " script {\n" + " echo \"World\"\n" + " echo \"Heal it\"\n" + " }\n" + "\n" + " }\n" + " }\n" + " stage(\"deploy\") {\n" + " steps{\n" + " sh 'echo \"Start Deploy\"'\n" + " sh 'echo \"Deploying...\"'\n" + " sh 'echo \"End Deploy\"'\n" + " } \n" + " }\n" + " }\n" + " post {\n" + " failure {\n" + " echo \"failed\"\n" + " }\n" + " success {\n" + " echo \"success\"\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(3, stages.size());
Assert.assertEquals("build", stages.get(0).getDisplayName());
Assert.assertEquals("SkippedStage", stages.get(1).getDisplayName());
Assert.assertEquals("deploy", stages.get(2).getDisplayName());
List<Map> resp = get("/organizations/jenkins/pipelines/p/pipelines/master/runs/" + b1.getId() + "/nodes/", List.class);
Assert.assertEquals(3, resp.size());
Assert.assertEquals("build", resp.get(0).get("displayName"));
Assert.assertEquals("SkippedStage", resp.get(1).get("displayName"));
Assert.assertEquals("deploy", resp.get(2).get("displayName"));
//check status
Assert.assertEquals("SUCCESS", resp.get(0).get("result"));
Assert.assertEquals("FINISHED", resp.get(0).get("state"));
Assert.assertEquals("NOT_BUILT", resp.get(1).get("result"));
Assert.assertEquals("SKIPPED", resp.get(1).get("state"));
Assert.assertEquals("SUCCESS", resp.get(2).get("result"));
Assert.assertEquals("FINISHED", resp.get(2).get("state"));
resp = get("/organizations/jenkins/pipelines/p/pipelines/master/runs/" + b1.getId() + "/steps/", List.class);
Assert.assertEquals(7, resp.size());
resp = get("/organizations/jenkins/pipelines/p/pipelines/master/runs/" + b1.getId() + "/nodes/" + stages.get(0).getId() + "/steps/", List.class);
Assert.assertEquals(3, resp.size());
resp = get("/organizations/jenkins/pipelines/p/pipelines/master/runs/" + b1.getId() + "/nodes/" + stages.get(1).getId() + "/steps/", List.class);
Assert.assertEquals(0, resp.size());
resp = get("/organizations/jenkins/pipelines/p/pipelines/master/runs/" + b1.getId() + "/nodes/" + stages.get(2).getId() + "/steps/", List.class);
Assert.assertEquals(4, resp.size());
}
use of jenkins.scm.api.SCMSource in project blueocean-plugin by jenkinsci.
the class MultiBranchTest method getMultiBranchPipeline.
@Test
public void getMultiBranchPipeline() throws IOException, ExecutionException, InterruptedException {
Assume.assumeTrue(runAllTests());
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();
Map resp = get("/organizations/jenkins/pipelines/p/");
validateMultiBranchPipeline(mp, resp, 3);
List<String> names = (List<String>) resp.get("branchNames");
IsArrayContainingInAnyOrder.arrayContainingInAnyOrder(names, branches);
List<Map> br = get("/organizations/jenkins/pipelines/p/branches", List.class);
List<String> branchNames = new ArrayList<>();
List<Integer> weather = new ArrayList<>();
for (Map b : br) {
branchNames.add((String) b.get("name"));
weather.add((int) b.get("weatherScore"));
}
for (String n : branches) {
assertTrue(branchNames.contains(n));
}
for (int s : weather) {
assertEquals(100, s);
}
}
Aggregations