use of org.jenkinsci.plugins.workflow.job.WorkflowJob in project blueocean-plugin by jenkinsci.
the class BlueOceanWebURLBuilderTest method getMultiBranchPipelineInsideFolder.
@Test
public void getMultiBranchPipelineInsideFolder() throws Exception {
MockFolder folder1 = jenkinsRule.createFolder("folder1");
MockFolder folder2 = folder1.createProject(MockFolder.class, "folder two with spaces");
WorkflowMultiBranchProject mp = folder2.createProject(WorkflowMultiBranchProject.class, "p");
String blueOceanURL;
blueOceanURL = urlMapper.getUrl(mp);
assertURL("blue/organizations/jenkins/folder1%2Ffolder%20two%20with%20spaces%2Fp/branches", blueOceanURL);
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();
jenkinsRule.waitUntilNoActivity();
// All branch jobs should just resolve back to the same top level branches
// page for the multibranch job in Blue Ocean.
WorkflowJob masterJob = findBranchProject(mp, "master");
blueOceanURL = urlMapper.getUrl(masterJob);
assertURL("blue/organizations/jenkins/folder1%2Ffolder%20two%20with%20spaces%2Fp/branches", blueOceanURL);
WorkflowJob featureUx1Job = findBranchProject(mp, "feature/ux-1");
blueOceanURL = urlMapper.getUrl(featureUx1Job);
assertURL("blue/organizations/jenkins/folder1%2Ffolder%20two%20with%20spaces%2Fp/branches", blueOceanURL);
WorkflowJob feature2Job = findBranchProject(mp, "feature2");
blueOceanURL = urlMapper.getUrl(feature2Job);
assertURL("blue/organizations/jenkins/folder1%2Ffolder%20two%20with%20spaces%2Fp/branches", blueOceanURL);
// Runs on the jobs
blueOceanURL = urlMapper.getUrl(masterJob.getFirstBuild());
assertURL("blue/organizations/jenkins/folder1%2Ffolder%20two%20with%20spaces%2Fp/detail/master/1", blueOceanURL);
blueOceanURL = urlMapper.getUrl(featureUx1Job.getFirstBuild());
assertURL("blue/organizations/jenkins/folder1%2Ffolder%20two%20with%20spaces%2Fp/detail/feature%2Fux-1/1", blueOceanURL);
}
use of org.jenkinsci.plugins.workflow.job.WorkflowJob in project blueocean-plugin by jenkinsci.
the class AbstractRunImplTest method replayRunTestMB.
// Disabled, see JENKINS-40084
@Test
@Ignore
public void replayRunTestMB() throws Exception {
j.createOnlineSlave(Label.get("remote"));
sampleRepo.write("Jenkinsfile", "node('remote') {\n" + " ws {\n" + " checkout scm\n" + " stage 'build'\n " + "node {echo 'Building'}\n" + " stage 'test'\nnode { echo 'Testing'}\n" + " stage 'deploy'\nnode { echo 'Deploying'}\n" + " }\n" + " }");
sampleRepo.git("add", "Jenkinsfile");
sampleRepo.git("commit", "--message=init");
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();
WorkflowJob job1 = mp.getItem("master");
WorkflowRun b1 = job1.scheduleBuild2(0).waitForStart();
j.waitForCompletion(b1);
j.assertBuildStatusSuccess(b1);
sampleRepo.write("file1", "");
sampleRepo.git("add", "file1");
sampleRepo.git("commit", "--message=init");
WorkflowRun b2 = job1.scheduleBuild2(0).get();
j.assertBuildStatusSuccess(b2);
Assert.assertNotEquals(new PipelineRunImpl(b1, null, null).getCommitId(), new PipelineRunImpl(b2, null, null).getCommitId());
Map replayBuild = request().post("/organizations/jenkins/pipelines/p/branches/master/runs/" + b1.getNumber() + "/replay").build(Map.class);
Queue.Item item = j.getInstance().getQueue().getItem(Long.parseLong((String) replayBuild.get("id")));
WorkflowRun replayedRun = (WorkflowRun) item.getFuture().get();
Map r = request().get("/organizations/jenkins/pipelines/p/branches/master/runs/" + replayedRun.getNumber() + "/").build(Map.class);
assertEquals(new PipelineRunImpl(b1, null, null).getCommitId(), r.get("commitId"));
}
use of org.jenkinsci.plugins.workflow.job.WorkflowJob in project blueocean-plugin by jenkinsci.
the class AbstractRunImplTest method disableDescription.
@Test
public void disableDescription() throws Exception {
WorkflowJob p = createWorkflowJobWithJenkinsfile(getClass(), "disableDescription.jenkinsfile");
WorkflowRun r = p.scheduleBuild2(0).waitForStart();
j.waitForCompletion(r);
// Description should be available to the pipeline
Map run = request().get(String.format("/organizations/jenkins/pipelines/%s/runs/1/", p.getName())).build(Map.class);
Assert.assertEquals("A cool pipeline", run.get("description"));
// Disable descriptions
System.setProperty(AbstractRunImpl.BLUEOCEAN_FEATURE_RUN_DESCRIPTION_ENABLED, "false");
run = request().get(String.format("/organizations/jenkins/pipelines/%s/runs/1/", p.getName())).build(Map.class);
Assert.assertEquals(null, run.get("description"));
}
use of org.jenkinsci.plugins.workflow.job.WorkflowJob in project blueocean-plugin by jenkinsci.
the class AbstractRunImplTest method pipelineLatestRunIncludesRunning.
@Test
public void pipelineLatestRunIncludesRunning() throws Exception {
WorkflowJob p = createWorkflowJobWithJenkinsfile(getClass(), "latestRunIncludesQueued.jenkinsfile");
// Ensure null before first run
Map pipeline = request().get(String.format("/organizations/jenkins/pipelines/%s/", p.getName())).build(Map.class);
Assert.assertNull(pipeline.get("latestRun"));
// Run until completed
Run r = p.scheduleBuild2(0).waitForStart();
j.waitForCompletion(r);
// Make the next runs queue
j.jenkins.setNumExecutors(0);
// Schedule another run so it goes in the queue
WorkflowRun r2 = p.scheduleBuild2(0).waitForStart();
j.waitForMessage("Still waiting to schedule task", r2);
// Get latest run for this pipeline
pipeline = request().get(String.format("/organizations/jenkins/pipelines/%s/", p.getName())).build(Map.class);
Map latestRun = (Map) pipeline.get("latestRun");
Assert.assertEquals("QUEUED", latestRun.get("state"));
Assert.assertEquals("2", latestRun.get("id"));
Assert.assertEquals("Waiting for next available executor", latestRun.get("causeOfBlockage"));
String idOfSecondRun = (String) latestRun.get("id");
// Replay this - with limited retry
String replayURL = String.format("/organizations/jenkins/pipelines/%s/runs/%s/replay/", p.getName(), idOfSecondRun);
try {
Thread.sleep(200);
request().post(replayURL).build(String.class);
} catch (Exception e) {
Thread.sleep(200);
request().post(replayURL).build(String.class);
}
// Sleep to make sure the build actually gets launched.
Thread.sleep(1000);
WorkflowRun r3 = p.getLastBuild();
j.waitForMessage("Still waiting to schedule task", r3);
// Get latest run for this pipeline
pipeline = request().get(String.format("/organizations/jenkins/pipelines/%s/", p.getName())).build(Map.class);
latestRun = (Map) pipeline.get("latestRun");
// It should be running
Assert.assertEquals("QUEUED", latestRun.get("state"));
Assert.assertEquals("3", latestRun.get("id"));
Assert.assertEquals("Waiting for next available executor", latestRun.get("causeOfBlockage"));
}
use of org.jenkinsci.plugins.workflow.job.WorkflowJob 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();
// check MBP capabilities
Map<String, Object> response = get("/organizations/jenkins/pipelines/p/");
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(BLUE_SCM) && classes.contains(JENKINS_MULTI_BRANCH_PROJECT) && classes.contains(BLUE_MULTI_BRANCH_PIPELINE) && classes.contains(BLUE_PIPELINE_FOLDER) && classes.contains(JENKINS_ABSTRACT_FOLDER) && classes.contains(BLUE_PIPELINE));
response = get("/organizations/jenkins/pipelines/p/branches/master/", Map.class);
clazz = (String) response.get("_class");
response = get("/classes/" + clazz + "/");
Assert.assertNotNull(response);
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));
}
Aggregations