Search in sources :

Example 16 with Item

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

the class GitPipelineUpdateRequest method update.

@CheckForNull
@Override
@SuppressWarnings("unchecked")
public BluePipeline update(BluePipeline pipeline) throws IOException {
    Item item = Jenkins.getInstance().getItemByFullName(pipeline.getFullName());
    if (item instanceof MultiBranchProject) {
        ACL acl = Jenkins.getInstance().getACL();
        Authentication a = Jenkins.getAuthentication();
        if (!acl.hasPermission(a, Item.CONFIGURE)) {
            throw new ServiceException.ForbiddenException(String.format("Failed to update Git pipeline: %s. User %s doesn't have Job configure permission", pipeline.getName(), a.getName()));
        }
        MultiBranchProject mbp = (MultiBranchProject) item;
        BranchSource branchSource = getGitScmSource(mbp);
        if (branchSource != null) {
            mbp.getSourcesList().replaceBy(Collections.singleton(branchSource));
            mbp.scheduleBuild2(0, new CauseAction(new Cause.UserIdCause()));
        }
    }
    return pipeline;
}
Also used : Item(hudson.model.Item) Authentication(org.acegisecurity.Authentication) CauseAction(hudson.model.CauseAction) MultiBranchProject(jenkins.branch.MultiBranchProject) ACL(hudson.security.ACL) BranchSource(jenkins.branch.BranchSource) CheckForNull(javax.annotation.CheckForNull)

Example 17 with Item

use of hudson.model.Item 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 18 with Item

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

the class PipelineActivityStatePreloader method getPipeline.

private BluePipeline getPipeline(BlueUrlTokenizer blueUrl) {
    if (addPipelineRuns(blueUrl)) {
        Jenkins jenkins = Jenkins.getInstance();
        String pipelineFullName = blueUrl.getPart(BlueUrlTokenizer.UrlPart.PIPELINE);
        try {
            Item pipelineJob = jenkins.getItemByFullName(pipelineFullName);
            return (BluePipeline) BluePipelineFactory.resolve(pipelineJob);
        } catch (Exception e) {
            LOGGER.log(Level.FINE, String.format("Unable to find Job named '%s'.", pipelineFullName), e);
            return null;
        }
    }
    return null;
}
Also used : Jenkins(jenkins.model.Jenkins) Item(hudson.model.Item) BluePipeline(io.jenkins.blueocean.rest.model.BluePipeline) IOException(java.io.IOException)

Example 19 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 20 with Item

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

the class ContainerFilter method filter.

/**
     * Filters the item list based on the supplied filter name
     */
@SuppressWarnings("unchecked")
public static <T extends Item> Collection<T> filter(Collection<T> items, String... filterNames) {
    if (filterNames != null && filterNames.length > 0) {
        Predicate<Item>[] filters = new Predicate[filterNames.length];
        for (int i = 0; i < filterNames.length; i++) {
            final Predicate<Item> f = getItemFilter(filterNames[i]);
            if (f == null) {
                throw new IllegalArgumentException("Invalid filter type specified.");
            }
            filters[i] = f;
        }
        Collection<T> out = new LinkedList<>();
        nextItem: for (T item : items) {
            for (int i = 0; i < filters.length; i++) {
                if (!filters[i].apply(item)) {
                    continue nextItem;
                }
            }
            out.add(item);
        }
        return out;
    }
    return items;
}
Also used : Item(hudson.model.Item) ExtensionPoint(hudson.ExtensionPoint) LinkedList(java.util.LinkedList) Predicate(com.google.common.base.Predicate)

Aggregations

Item (hudson.model.Item)22 BluePipeline (io.jenkins.blueocean.rest.model.BluePipeline)5 ItemGroup (hudson.model.ItemGroup)4 Run (hudson.model.Run)4 TopLevelItem (hudson.model.TopLevelItem)4 MultiBranchProject (jenkins.branch.MultiBranchProject)4 Jenkins (jenkins.model.Jenkins)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Nonnull (javax.annotation.Nonnull)3 StaplerRequest (org.kohsuke.stapler.StaplerRequest)3 Job (hudson.model.Job)2 ModelObject (hudson.model.ModelObject)2 ACL (hudson.security.ACL)2 CheckForNull (javax.annotation.CheckForNull)2 OrganizationFolder (jenkins.branch.OrganizationFolder)2 Authentication (org.acegisecurity.Authentication)2 JobChannelMessage (org.jenkinsci.plugins.pubsub.JobChannelMessage)2 Ancestor (org.kohsuke.stapler.Ancestor)2 AbstractFolder (com.cloudbees.hudson.plugins.folder.AbstractFolder)1