Search in sources :

Example 11 with Item

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

the class ItemPathResolverTest method assertsPath.

private <T extends Item> void assertsPath(@Nonnull String path, @CheckForNull Item base, Item expected, @Nonnull Class<T> clazz) throws Exception {
    final Item res = ItemPathResolver.getByPath(path, base, clazz);
    if (expected != res) {
        StringBuilder errorDetails = new StringBuilder("Wrong result for clase='").append(clazz).append("', path='").append(path).append("'");
        if (base != null) {
            errorDetails.append(" with base element '").append(base.getFullName()).append("'");
        } else {
            errorDetails.append(" with NULL base element");
        }
        assertEquals(errorDetails.toString(), expected, res);
    }
}
Also used : Item(hudson.model.Item)

Example 12 with Item

use of hudson.model.Item in project hudson-2.x by hudson.

the class GroovyCommand method run.

protected int run() throws Exception {
    // this allows the caller to manipulate the JVM state, so require the admin privilege.
    Hudson.getInstance().checkPermission(Hudson.ADMINISTER);
    Binding binding = new Binding();
    binding.setProperty("out", new PrintWriter(stdout, true));
    String j = getClientEnvironmentVariable("JOB_NAME");
    if (j != null) {
        Item job = Hudson.getInstance().getItemByFullName(j);
        binding.setProperty("currentJob", job);
        String b = getClientEnvironmentVariable("BUILD_NUMBER");
        if (b != null && job instanceof AbstractProject) {
            Run r = ((AbstractProject) job).getBuildByNumber(Integer.parseInt(b));
            binding.setProperty("currentBuild", r);
        }
    }
    GroovyShell groovy = new GroovyShell(binding);
    groovy.run(loadScript(), "RemoteClass", remaining.toArray(new String[remaining.size()]));
    return 0;
}
Also used : Binding(groovy.lang.Binding) Item(hudson.model.Item) Run(hudson.model.Run) AbstractProject(hudson.model.AbstractProject) GroovyShell(groovy.lang.GroovyShell) PrintWriter(java.io.PrintWriter)

Example 13 with Item

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

the class GithubPipelineUpdateRequest method update.

@Nonnull
@Override
public BluePipeline update(BluePipeline pipeline) throws IOException {
    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()));
    }
    User user = User.current();
    if (user == null) {
        throw new ServiceException.UnauthorizedException("User is not authenticated");
    }
    Item item = Jenkins.getInstance().getItemByFullName(pipeline.getFullName());
    if (item instanceof OrganizationFolder) {
        OrganizationFolder folder = (OrganizationFolder) item;
        GitHubSCMNavigator gitHubSCMNavigator = getNavigator(folder);
        if (gitHubSCMNavigator != null) {
            folder.getNavigators().replace(gitHubSCMNavigator);
            if (repos.size() == 1) {
                SCMSourceEvent.fireNow(new GithubPipelineCreateRequest.SCMSourceEventImpl(repos.get(0), item, gitHubSCMNavigator.getApiUri(), gitHubSCMNavigator));
            } else {
                folder.scheduleBuild(new Cause.UserIdCause());
            }
        }
    }
    return pipeline;
}
Also used : Item(hudson.model.Item) User(hudson.model.User) OrganizationFolder(jenkins.branch.OrganizationFolder) Authentication(org.acegisecurity.Authentication) Cause(hudson.model.Cause) ACL(hudson.security.ACL) GitHubSCMNavigator(org.jenkinsci.plugins.github_branch_source.GitHubSCMNavigator) Nonnull(javax.annotation.Nonnull)

Example 14 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.getInstance();
    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(), ModelObjectSerializer.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 15 with Item

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

the class JobIndexingMessageEnricher method enrich.

@Override
public void enrich(@Nonnull Message message) {
    if (message instanceof JobChannelMessage) {
        JobChannelMessage jobChannelMessage = (JobChannelMessage) message;
        Item jobChannelItem = jobChannelMessage.getJobChannelItem();
        Enum indexingStatus;
        Enum indexingResult;
        if (jobChannelItem instanceof OrganizationFolder) {
            indexingStatus = JobIndexing.EventProps.job_orgfolder_indexing_status;
            indexingResult = JobIndexing.EventProps.job_orgfolder_indexing_result;
        } else if (jobChannelItem instanceof MultiBranchProject) {
            jobChannelMessage.set(EventProps.Job.job_ismultibranch, "true");
            indexingStatus = EventProps.Job.job_multibranch_indexing_status;
            indexingResult = EventProps.Job.job_multibranch_indexing_result;
        } else {
            // don't enrich if not org folder or multibranch
            return;
        }
        if (message instanceof QueueTaskMessage) {
            QueueTaskMessage queueTaskMessage = (QueueTaskMessage) message;
            Queue.Item queueItem = queueTaskMessage.getQueueItem();
            if (queueItem instanceof Queue.LeftItem) {
                Queue.LeftItem leftItem = (Queue.LeftItem) queueItem;
                if (leftItem.isCancelled()) {
                    jobChannelMessage.set(indexingStatus, "COMPLETE");
                    jobChannelMessage.set(indexingResult, "CANCELLED");
                } else {
                    if (message.getEventName().equals(Events.JobChannel.job_run_queue_task_complete.name())) {
                        jobChannelMessage.set(indexingStatus, "COMPLETE");
                        Queue.Executable executable = ((Queue.LeftItem) queueItem).getExecutable();
                        if (executable instanceof BranchIndexing) {
                            BranchIndexing branchIndexing = (BranchIndexing) executable;
                            jobChannelMessage.set(indexingResult, branchIndexing.getResult().toString());
                        } else if (executable instanceof OrganizationFolder.OrganizationScan) {
                            OrganizationFolder.OrganizationScan orgScan = (OrganizationFolder.OrganizationScan) executable;
                            jobChannelMessage.set(indexingResult, orgScan.getResult().toString());
                        }
                    } else {
                        jobChannelMessage.set(indexingStatus, "INDEXING");
                    }
                }
            } else {
                jobChannelMessage.set(indexingStatus, "INDEXING");
            }
        }
    }
}
Also used : JobChannelMessage(org.jenkinsci.plugins.pubsub.JobChannelMessage) OrganizationFolder(jenkins.branch.OrganizationFolder) BranchIndexing(jenkins.branch.MultiBranchProject.BranchIndexing) Item(hudson.model.Item) QueueTaskMessage(org.jenkinsci.plugins.pubsub.QueueTaskMessage) MultiBranchProject(jenkins.branch.MultiBranchProject) Queue(hudson.model.Queue)

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