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;
}
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()));
}
}
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;
}
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 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;
}
Aggregations