Search in sources :

Example 6 with ItemGroup

use of hudson.model.ItemGroup in project blueocean-plugin by jenkinsci.

the class AbstractPipelineCreateRequestImpl method create.

@Nonnull
public TopLevelItem create(ModifiableTopLevelItemGroup parent, String name, String descriptorName, Class<? extends TopLevelItemDescriptor> descriptorClass) throws IOException {
    ACL acl = Jenkins.getInstance().getACL();
    Authentication a = Jenkins.getAuthentication();
    if (!acl.hasPermission(a, Item.CREATE)) {
        throw new ServiceException.ForbiddenException(String.format("Failed to create pipeline: %s. User %s doesn't have Job create permission", name, a.getName()));
    }
    TopLevelItemDescriptor descriptor = Items.all().findByName(descriptorName);
    if (descriptor == null || !(descriptorClass.isAssignableFrom(descriptor.getClass()))) {
        throw new ServiceException.BadRequestExpception(String.format("Failed to create pipeline: %s, descriptor %s is not found", name, descriptorName));
    }
    ItemGroup p = Jenkins.getInstance();
    if (!descriptor.isApplicableIn(p)) {
        throw new ServiceException.ForbiddenException(String.format("Failed to create pipeline: %s. pipeline can't be created in Jenkins root folder", name));
    }
    if (!acl.hasCreatePermission(a, p, descriptor)) {
        throw new ServiceException.ForbiddenException("Missing permission: " + Item.CREATE.group.title + "/" + Item.CREATE.name + Item.CREATE + "/" + descriptor.getDisplayName());
    }
    return parent.createProject(descriptor, name, true);
}
Also used : ItemGroup(hudson.model.ItemGroup) ModifiableTopLevelItemGroup(jenkins.model.ModifiableTopLevelItemGroup) Authentication(org.acegisecurity.Authentication) TopLevelItemDescriptor(hudson.model.TopLevelItemDescriptor) ACL(hudson.security.ACL) Nonnull(javax.annotation.Nonnull)

Example 7 with ItemGroup

use of hudson.model.ItemGroup in project blueocean-plugin by jenkinsci.

the class BlueOceanWebURLBuilder method getPipelineModelMapping.

private static BlueOceanModelMapping getPipelineModelMapping(Job job) {
    BluePipeline blueResource = (BluePipeline) BluePipelineFactory.resolve(job);
    if (blueResource instanceof BranchImpl) {
        // No abstract "Branch" type?
        ItemGroup multibranchJob = job.getParent();
        BluePipeline multibranchJobResource = (BluePipeline) BluePipelineFactory.resolve((Item) multibranchJob);
        return new BlueOceanModelMapping(multibranchJob, multibranchJobResource, getOrgPrefix() + "/" + encodeURIComponent(multibranchJobResource.getFullName()));
    } else {
        return new BlueOceanModelMapping(job, blueResource, getOrgPrefix() + "/" + encodeURIComponent(blueResource.getFullName()));
    }
}
Also used : Item(hudson.model.Item) ItemGroup(hudson.model.ItemGroup) BranchImpl(io.jenkins.blueocean.rest.impl.pipeline.BranchImpl) BluePipeline(io.jenkins.blueocean.rest.model.BluePipeline)

Example 8 with ItemGroup

use of hudson.model.ItemGroup 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 9 with ItemGroup

use of hudson.model.ItemGroup 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)

Aggregations

ItemGroup (hudson.model.ItemGroup)9 Item (hudson.model.Item)7 TopLevelItem (hudson.model.TopLevelItem)2 BluePipeline (io.jenkins.blueocean.rest.model.BluePipeline)2 ArrayList (java.util.ArrayList)2 StaplerRequest (org.kohsuke.stapler.StaplerRequest)2 AbstractFolder (com.cloudbees.hudson.plugins.folder.AbstractFolder)1 Plugin (hudson.Plugin)1 FreeStyleProject (hudson.model.FreeStyleProject)1 Job (hudson.model.Job)1 ModelObject (hudson.model.ModelObject)1 Run (hudson.model.Run)1 TopLevelItemDescriptor (hudson.model.TopLevelItemDescriptor)1 View (hudson.model.View)1 SearchableModelObject (hudson.search.SearchableModelObject)1 ACL (hudson.security.ACL)1 UnexpectedErrorException (io.jenkins.blueocean.commons.ServiceException.UnexpectedErrorException)1 BranchImpl (io.jenkins.blueocean.rest.impl.pipeline.BranchImpl)1 BlueOrganization (io.jenkins.blueocean.rest.model.BlueOrganization)1 Resource (io.jenkins.blueocean.rest.model.Resource)1