Search in sources :

Example 1 with BuildableItem

use of hudson.model.BuildableItem in project gogs-webhook-plugin by jenkinsci.

the class GogsPayloadProcessor method triggerJobs.

public GogsResults triggerJobs(String jobName, String deliveryID) {
    SecurityContext saveCtx = ACL.impersonate(ACL.SYSTEM);
    GogsResults result = new GogsResults();
    try {
        BuildableItem project = GogsUtils.find(jobName, BuildableItem.class);
        if (project != null) {
            GogsTrigger gTrigger = null;
            Cause cause = new GogsCause(deliveryID);
            if (project instanceof ParameterizedJobMixIn.ParameterizedJob) {
                ParameterizedJobMixIn.ParameterizedJob pJob = (ParameterizedJobMixIn.ParameterizedJob) project;
                for (Trigger trigger : pJob.getTriggers().values()) {
                    if (trigger instanceof GogsTrigger) {
                        gTrigger = (GogsTrigger) trigger;
                        break;
                    }
                }
            }
            if (gTrigger != null) {
                SCMTriggerItem item = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(project);
                GogsPayload gogsPayload = new GogsPayload(this.payload);
                if (item != null) {
                    item.scheduleBuild2(0, gogsPayload);
                }
            } else {
                project.scheduleBuild(0, cause);
            }
            result.setMessage(String.format("Job '%s' is executed", jobName));
        } else {
            String msg = String.format("Job '%s' is not defined in Jenkins", jobName);
            result.setStatus(404, msg);
            LOGGER.warning(msg);
        }
    } catch (Exception e) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        LOGGER.severe(sw.toString());
    } finally {
        SecurityContextHolder.setContext(saveCtx);
    }
    return result;
}
Also used : ParameterizedJobMixIn(jenkins.model.ParameterizedJobMixIn) Trigger(hudson.triggers.Trigger) StringWriter(java.io.StringWriter) BuildableItem(hudson.model.BuildableItem) Cause(hudson.model.Cause) SecurityContext(org.acegisecurity.context.SecurityContext) SCMTriggerItem(jenkins.triggers.SCMTriggerItem) PrintWriter(java.io.PrintWriter)

Example 2 with BuildableItem

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

the class QueueContainerImpl method getQueuedItems.

/**
     * This function gets gets a list of all queued items if the job is a buildable item.
     *
     * Note the estimated build number calculation is a guess - job types need not return
     * sequential build numbers.
     *
     * @return List of items newest first
     */
public static List<BlueQueueItem> getQueuedItems(Job job) {
    Link pipelineLink = LinkResolver.resolveLink(job);
    if (job instanceof BuildableItem) {
        BuildableItem task = (BuildableItem) job;
        List<Queue.Item> items = Jenkins.getInstance().getQueue().getItems(task);
        List<BlueQueueItem> items2 = Lists.newArrayList();
        for (int i = 0; i < items.size(); i++) {
            Link self = pipelineLink.rel("queue").rel(Long.toString(items.get(i).getId()));
            items2.add(0, new QueueItemImpl(items.get(i), job.getName(), (items.size() == 1 ? job.getNextBuildNumber() : job.getNextBuildNumber() + i), self, pipelineLink));
        }
        return items2;
    } else {
        throw new ServiceException.UnexpectedErrorException("This pipeline is not buildable and therefore does not have a queue.");
    }
}
Also used : BlueQueueItem(io.jenkins.blueocean.rest.model.BlueQueueItem) BuildableItem(hudson.model.BuildableItem) BuildableItem(hudson.model.BuildableItem) BlueQueueItem(io.jenkins.blueocean.rest.model.BlueQueueItem) Link(io.jenkins.blueocean.rest.hal.Link)

Example 3 with BuildableItem

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

the class QueueUtil method getQueuedItems.

/**
 * This function gets gets a list of all queued items if the job is a buildable item.
 *
 * Note the estimated build number calculation is a guess - job types need not return
 * sequential build numbers.
 *
 * @return List of items newest first
 */
public static List<BlueQueueItem> getQueuedItems(BlueOrganization organization, Job job) {
    BluePipeline pipeline = (BluePipeline) BluePipelineFactory.resolve(job);
    if (job instanceof BuildableItem && pipeline != null) {
        BuildableItem task = (BuildableItem) job;
        List<hudson.model.Queue.Item> items = Jenkins.get().getQueue().getItems(task);
        List<BlueQueueItem> items2 = new ArrayList<>();
        for (int i = 0; i < items.size(); i++) {
            Link self = pipeline.getLink().rel("queue").rel(Long.toString(items.get(i).getId()));
            QueueItemImpl queueItem = new QueueItemImpl(organization, items.get(i), pipeline, (items.size() == 1 ? job.getNextBuildNumber() : job.getNextBuildNumber() + i), self, pipeline.getLink());
            items2.add(0, queueItem);
        }
        return items2;
    } else {
        throw new ServiceException.UnexpectedErrorException("This pipeline is not buildable and therefore does not have a queue.");
    }
}
Also used : BlueQueueItem(io.jenkins.blueocean.rest.model.BlueQueueItem) BuildableItem(hudson.model.BuildableItem) BuildableItem(hudson.model.BuildableItem) ArrayList(java.util.ArrayList) BluePipeline(io.jenkins.blueocean.rest.model.BluePipeline) BlueQueueItem(io.jenkins.blueocean.rest.model.BlueQueueItem) Link(io.jenkins.blueocean.rest.hal.Link)

Aggregations

BuildableItem (hudson.model.BuildableItem)3 Link (io.jenkins.blueocean.rest.hal.Link)2 BlueQueueItem (io.jenkins.blueocean.rest.model.BlueQueueItem)2 Cause (hudson.model.Cause)1 Trigger (hudson.triggers.Trigger)1 BluePipeline (io.jenkins.blueocean.rest.model.BluePipeline)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 ParameterizedJobMixIn (jenkins.model.ParameterizedJobMixIn)1 SCMTriggerItem (jenkins.triggers.SCMTriggerItem)1 SecurityContext (org.acegisecurity.context.SecurityContext)1