use of io.jenkins.blueocean.rest.model.Resource in project blueocean-plugin by jenkinsci.
the class LinkResolverImpl method resolveRun.
private Resource resolveRun(Run run) {
Resource resource = resolveJob(run.getParent());
if (resource instanceof BluePipeline) {
BluePipeline pipeline = (BluePipeline) resource;
BlueRunContainer blueRunContainer = pipeline.getRuns();
return blueRunContainer == null ? null : blueRunContainer.get(run.getId());
}
return null;
}
use of io.jenkins.blueocean.rest.model.Resource in project blueocean-plugin by jenkinsci.
the class BluePipelineFactory method resolve.
/**
* Given a Job in Jenkins, map that to corresponding blue ocean API object,
* for example so that you can get its URL.
*/
public static Resource resolve(Item item) {
BlueOrganization org = OrganizationFactory.getInstance().getContainingOrg(item);
if (org == null) {
return null;
}
Item nextStep = findNextStep(Jenkins.get(), item);
for (BluePipelineFactory f : all()) {
Resource r = f.resolve(nextStep, org.getPipelines(), item, org);
if (r != null)
return r;
}
return null;
}
use of io.jenkins.blueocean.rest.model.Resource in project blueocean-plugin by jenkinsci.
the class MultiBranchTest method testMultiBranchPipelineQueueContainer.
@Test
public void testMultiBranchPipelineQueueContainer() throws Exception {
j.jenkins.setQuietPeriod(0);
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);
Resource r = BluePipelineFactory.resolve(mp);
assertTrue(r instanceof MultiBranchPipelineImpl);
for (WorkflowJob job : mp.getItems()) {
Queue.Item item = job.getQueueItem();
job.setConcurrentBuild(false);
job.scheduleBuild2(0);
job.scheduleBuild2(0);
}
Queue.Item[] queueItems = Jenkins.get().getQueue().getItems();
MultiBranchPipelineQueueContainer mbpQueueContainer = new MultiBranchPipelineQueueContainer((MultiBranchPipelineImpl) r);
Iterator<BlueQueueItem> blueQueueItems = mbpQueueContainer.iterator(0, 100);
if (queueItems.length > 0) {
assertTrue(mbpQueueContainer.iterator().hasNext());
assertEquals("/blue/rest/organizations/jenkins/pipelines/p/queue/", mbpQueueContainer.getLink().getHref());
BlueQueueItem blueQueueItem = mbpQueueContainer.get(String.valueOf(queueItems[0].getId()));
assertNotNull(blueQueueItem);
assertTrue(blueQueueItems.hasNext());
}
}
use of io.jenkins.blueocean.rest.model.Resource in project blueocean-plugin by jenkinsci.
the class BlueOceanUrlMapperImpl method getUrl.
@Override
public String getUrl(@Nonnull ModelObject modelObject) {
BlueOrganization organization = getOrganization(modelObject);
if (organization == null) {
// no organization, best we can do is to land user on landing page
return getLandingPagePath();
}
String organizationName = organization.getName();
String baseUrl = getOrgPrefix(organizationName);
if (modelObject instanceof ModifiableTopLevelItemGroup) {
return baseUrl;
} else if (modelObject instanceof Job) {
BluePipeline blueResource = getJobResource(modelObject);
if (blueResource != null) {
return getPipelineUrl(baseUrl, blueResource);
}
} else if (modelObject instanceof Run) {
Run run = (Run) modelObject;
Job job = run.getParent();
BluePipeline blueResource = getJobResource(job);
if (blueResource != null) {
// encoded and re-encode to do the full monty. Nasty :)
return baseUrl + "/" + encodeURIComponent(blueResource.getFullName()) + "/detail/" + encodeURIComponent(decodeURIComponent(job.getName())) + "/" + encodeURIComponent(run.getId()) + "/";
}
} else if (modelObject instanceof Item) {
Resource bluePipeline = BluePipelineFactory.resolve((Item) modelObject);
if (bluePipeline instanceof BlueMultiBranchPipeline) {
return getPipelineUrl(baseUrl, (BluePipeline) bluePipeline);
}
}
return null;
}
use of io.jenkins.blueocean.rest.model.Resource in project blueocean-plugin by jenkinsci.
the class PipelineActivityStatePreloader method getFetchData.
@Override
protected FetchData getFetchData(@Nonnull BlueUrlTokenizer blueUrl) {
BluePipeline pipeline = getPipeline(blueUrl);
if (pipeline != null) {
// It's a pipeline page. Let's prefetch the pipeline activity and add them to the page,
// saving the frontend the overhead of requesting them.
Container<BlueRun> activitiesContainer = pipeline.getRuns();
if (activitiesContainer == null) {
return null;
}
Iterator<BlueRun> activitiesIterator = activitiesContainer.iterator(0, DEFAULT_LIMIT);
JSONArray activities = new JSONArray();
while (activitiesIterator.hasNext()) {
Resource blueActivity = activitiesIterator.next();
try {
activities.add(JSONObject.fromObject(Export.toJson(blueActivity)));
} catch (IOException e) {
LOGGER.log(Level.FINE, String.format("Unable to preload runs for Job '%s'. Activity serialization error.", pipeline.getFullName()), e);
return null;
}
}
return new FetchData(activitiesContainer.getLink().getHref() + "?start=0&limit=" + DEFAULT_LIMIT, activities.toString());
}
// Don't preload any data on the page.
return null;
}
Aggregations