Search in sources :

Example 31 with Item

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;
}
Also used : Jenkins(jenkins.model.Jenkins) Item(hudson.model.Item) BluePipeline(io.jenkins.blueocean.rest.model.BluePipeline) IOException(java.io.IOException) IOException(java.io.IOException)

Example 32 with Item

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;
}
Also used : Item(hudson.model.Item) ItemGroup(hudson.model.ItemGroup) Resource(io.jenkins.blueocean.rest.model.Resource) Run(hudson.model.Run) Job(hudson.model.Job)

Example 33 with Item

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);
}
Also used : Item(hudson.model.Item)

Example 34 with Item

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;
}
Also used : Item(hudson.model.Item) AbstractFolder(com.cloudbees.hudson.plugins.folder.AbstractFolder) ItemGroup(hudson.model.ItemGroup) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 35 with Item

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();
}
Also used : Item(hudson.model.Item) StaplerRequest(org.kohsuke.stapler.StaplerRequest) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Aggregations

Item (hudson.model.Item)36 ItemGroup (hudson.model.ItemGroup)7 BluePipeline (io.jenkins.blueocean.rest.model.BluePipeline)7 IOException (java.io.IOException)6 Run (hudson.model.Run)5 Job (hudson.model.Job)4 BlueOrganization (io.jenkins.blueocean.rest.model.BlueOrganization)4 ArrayList (java.util.ArrayList)4 Nonnull (javax.annotation.Nonnull)4 MultiBranchProject (jenkins.branch.MultiBranchProject)4 Jenkins (jenkins.model.Jenkins)4 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)4 WorkflowMultiBranchProject (org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject)4 StaplerRequest (org.kohsuke.stapler.StaplerRequest)4 TopLevelItem (hudson.model.TopLevelItem)3 User (hudson.model.User)3 Resource (io.jenkins.blueocean.rest.model.Resource)3 CheckForNull (javax.annotation.CheckForNull)3 AbstractFolder (com.cloudbees.hudson.plugins.folder.AbstractFolder)2 StandardUsernamePasswordCredentials (com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials)2