Search in sources :

Example 6 with BlueQueueItem

use of io.jenkins.blueocean.rest.model.BlueQueueItem in project blueocean-plugin by jenkinsci.

the class PipelineRunImpl method replay.

@Override
public BlueRun replay() {
    ReplayAction replayAction = run.getAction(ReplayAction.class);
    if (!isReplayable(replayAction)) {
        throw new ServiceException.BadRequestException("This run does not support replay");
    }
    Queue.Item item = replayAction.run2(replayAction.getOriginalScript(), replayAction.getOriginalLoadedScripts());
    if (item == null) {
        throw new ServiceException.UnexpectedErrorException("Run was not added to queue.");
    }
    BlueQueueItem queueItem = QueueUtil.getQueuedItem(this.organization, item, run.getParent());
    WorkflowRun replayedRun = QueueUtil.getRun(run.getParent(), item.getId());
    if (queueItem != null) {
        // If the item is still queued
        return queueItem.toRun();
    } else if (replayedRun != null) {
        // If the item has left the queue and is running
        return new PipelineRunImpl(replayedRun, parent, organization);
    } else {
        // For some reason could not be added to the queue
        throw new ServiceException.UnexpectedErrorException("Run was not added to queue.");
    }
}
Also used : ServiceException(io.jenkins.blueocean.commons.ServiceException) ReplayAction(org.jenkinsci.plugins.workflow.cps.replay.ReplayAction) Queue(hudson.model.Queue) BlueQueueItem(io.jenkins.blueocean.rest.model.BlueQueueItem) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun)

Example 7 with BlueQueueItem

use of io.jenkins.blueocean.rest.model.BlueQueueItem 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)

Example 8 with BlueQueueItem

use of io.jenkins.blueocean.rest.model.BlueQueueItem in project blueocean-plugin by jenkinsci.

the class RunContainerImpl method get.

@Override
public BlueRun get(String name) {
    RunList<? extends hudson.model.Run> runList = job.getBuilds();
    if (name == null) {
        return BlueRunFactory.getRun(runList.getLastBuild(), pipeline);
    }
    for (hudson.model.Run r : runList) {
        if (r.getId().equals(name)) {
            return BlueRunFactory.getRun(r, pipeline);
        }
    }
    int number;
    try {
        number = Integer.parseInt(name);
    } catch (NumberFormatException e) {
        throw new NotFoundException(String.format("Run %s not found in organization %s and pipeline %s", name, pipeline.getOrganizationName(), job.getName()));
    }
    for (BlueQueueItem item : QueueUtil.getQueuedItems(pipeline.getOrganization(), job)) {
        if (item.getExpectedBuildNumber() == number) {
            return item.toRun();
        }
    }
    throw new NotFoundException(String.format("Run %s not found in organization %s and pipeline %s", name, pipeline.getOrganizationName(), job.getName()));
}
Also used : NotFoundException(io.jenkins.blueocean.commons.ServiceException.NotFoundException) BlueQueueItem(io.jenkins.blueocean.rest.model.BlueQueueItem)

Aggregations

BlueQueueItem (io.jenkins.blueocean.rest.model.BlueQueueItem)8 Queue (hudson.model.Queue)5 Link (io.jenkins.blueocean.rest.hal.Link)5 ServiceException (io.jenkins.blueocean.commons.ServiceException)3 BluePipeline (io.jenkins.blueocean.rest.model.BluePipeline)3 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)3 BuildableItem (hudson.model.BuildableItem)2 QueueUtil (io.jenkins.blueocean.service.embedded.rest.QueueUtil)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)2 WorkflowMultiBranchProject (org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 Action (hudson.model.Action)1 Item (hudson.model.Item)1 Job (hudson.model.Job)1 NotFoundException (io.jenkins.blueocean.commons.ServiceException.NotFoundException)1 Export (io.jenkins.blueocean.commons.stapler.Export)1 NodeDownstreamBuildAction (io.jenkins.blueocean.listeners.NodeDownstreamBuildAction)1