use of hudson.model.Item in project blueocean-plugin by jenkinsci.
the class PipelineStatePreloader method getFetchData.
@Override
protected FetchData getFetchData(@NonNull BlueUrlTokenizer blueUrl) {
// e.g. /blue/organizations/jenkins/Pipeline (or a url on that)
if (!blueUrl.hasPart(BlueUrlTokenizer.UrlPart.PIPELINE)) {
// Not interested in it
return null;
}
Jenkins jenkins = Jenkins.get();
String pipelineFullName = blueUrl.getPart(BlueUrlTokenizer.UrlPart.PIPELINE);
try {
Item pipelineJobItem = jenkins.getItemByFullName(pipelineFullName);
if (pipelineJobItem != null) {
BluePipeline bluePipeline = (BluePipeline) BluePipelineFactory.resolve(pipelineJobItem);
if (bluePipeline != null) {
try {
return new FetchData(bluePipeline.getLink().getHref(), Export.toJson(bluePipeline));
} catch (IOException e) {
LOGGER.log(Level.FINE, String.format("Unable to preload pipeline '%s'. Serialization error.", pipelineJobItem.getUrl()), e);
return null;
}
} else {
LOGGER.log(Level.FINE, String.format("Unable to preload pipeline '%s'. Failed to convert to Blue Ocean Resource.", pipelineJobItem.getUrl()));
return null;
}
}
} catch (Exception e) {
LOGGER.log(Level.FINE, String.format("Unable to find pipeline named '%s'.", pipelineFullName), e);
return null;
}
// Don't preload any data on the page.
return null;
}
use of hudson.model.Item in project blueocean-plugin by jenkinsci.
the class LinkResolverImpl method resolve.
@Override
public Link resolve(Object modelObject) {
if (modelObject instanceof Job) {
Resource resource = resolveJob((Job) modelObject);
if (resource != null) {
return resource.getLink();
}
} else if (modelObject instanceof Item && modelObject instanceof ItemGroup) {
Resource resource = resolveFolder((Item) modelObject);
if (resource != null) {
return resource.getLink();
}
} else if (modelObject instanceof Run) {
Run run = (Run) modelObject;
Resource resource = resolveRun(run);
if (resource != null) {
return resource.getLink();
}
}
return null;
}
use of hudson.model.Item in project blueocean-plugin by jenkinsci.
the class PipelineContainerImpl method get.
@Override
public BluePipeline get(String name) {
Item item;
item = itemGroup.getItem(name);
if (item == null) {
throw new ServiceException.NotFoundException(String.format("Pipeline %s not found", name));
}
return BluePipelineFactory.getPipelineInstance(item, this);
}
use of hudson.model.Item in project hubot-steps-plugin by jenkinsci.
the class HubotSite method get.
public static HubotSite get(final Job<?, ?> job, final TaskListener listener, final String siteName) {
HubotSite hubotSite = null;
HubotSite defaultSite = null;
ItemGroup parent = job.getParent();
String folderName = null;
// Site from folder(s).
try {
while (parent != null) {
if (parent instanceof AbstractFolder) {
AbstractFolder folder = (AbstractFolder) parent;
if (folderName == null) {
folderName = folder.getName();
}
HubotFolderProperty jfp = (HubotFolderProperty) folder.getProperties().get(HubotFolderProperty.class);
if (jfp != null) {
HubotSite[] sites = jfp.getSites();
if (sites != null && sites.length > 0) {
for (HubotSite site : sites) {
HubotSite cloneSite = site.clone();
if (cloneSite.isUseFolderName()) {
cloneSite.setRoom(folder.getName());
}
if (siteName != null) {
if (cloneSite.getName().equalsIgnoreCase(siteName) && hubotSite == null) {
hubotSite = cloneSite;
}
} else {
if (cloneSite.isDefaultSite() && defaultSite == null) {
defaultSite = cloneSite;
}
}
}
}
}
}
if (parent instanceof Item) {
parent = ((Item) parent).getParent();
} else {
parent = null;
}
}
// Global Sites.
if (hubotSite == null && defaultSite == null) {
for (HubotSite site : new GlobalConfig().getSites()) {
HubotSite cloneSite = site.clone();
if (site.isUseFolderName()) {
if (folderName != null) {
cloneSite.setRoom(folderName);
}
}
if (siteName != null) {
if (cloneSite.getName().equalsIgnoreCase(siteName) && hubotSite == null) {
hubotSite = cloneSite;
}
} else {
if (cloneSite.isDefaultSite() && defaultSite == null) {
defaultSite = cloneSite;
}
}
}
}
} catch (Exception e) {
LOGGER.error("Unable to get hubot site", e);
}
return hubotSite == null ? defaultSite : hubotSite;
}
use of hudson.model.Item in project workflow-cps-plugin by jenkinsci.
the class SnippetizerLink method getDisplayUrl.
/**
* Get the actual URL to use in sidepanel.jelly. If {@link #getUrl()} is not absolute, this will try to get the
* current Job context and return a url starting with that job's {@link Job#getUrl()} appended with {@link #getUrl()}.
*/
@NonNull
public final String getDisplayUrl() {
String u = getUrl();
try {
if (new URI(u).isAbsolute()) {
return u;
}
} catch (URISyntaxException e) {
LOGGER.log(Level.WARNING, "Failed to parse URL for " + u, e);
return "";
}
StaplerRequest req = Stapler.getCurrentRequest();
if (req == null) {
return u;
}
Item i = req.findAncestorObject(Item.class);
StringBuilder toAppend = new StringBuilder();
toAppend.append(req.getContextPath());
if (!req.getContextPath().endsWith("/")) {
toAppend.append("/");
}
if (i == null) {
toAppend.append(u);
} else {
toAppend.append(i.getUrl());
if (!i.getUrl().endsWith("/")) {
toAppend.append("/");
}
toAppend.append(u);
}
return toAppend.toString();
}
Aggregations