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