use of hudson.model.queue.ScheduleResult in project blueocean-plugin by jenkinsci.
the class RunContainerImpl method create.
/**
* Schedules a build. If build already exists in the queue and the pipeline does not
* support running multiple builds at the same time, return a reference to the existing
* build.
*
* @return Queue item.
*/
@Override
public BlueRun create(StaplerRequest request) {
job.checkPermission(Item.BUILD);
if (job instanceof Queue.Task) {
ScheduleResult scheduleResult;
List<ParameterValue> parameterValues = getParameterValue(request);
int expectedBuildNumber = job.getNextBuildNumber();
if (parameterValues.size() > 0) {
scheduleResult = Jenkins.get().getQueue().schedule2((Queue.Task) job, 0, new ParametersAction(parameterValues), new CauseAction(new Cause.UserIdCause()));
} else {
scheduleResult = Jenkins.get().getQueue().schedule2((Queue.Task) job, 0, new CauseAction(new Cause.UserIdCause()));
}
// Keep FB happy.
// scheduleResult.getItem() will always return non-null if scheduleResult.isAccepted() is true
final Queue.Item item = scheduleResult.getItem();
if (scheduleResult.isAccepted() && item != null) {
return new QueueItemImpl(pipeline.getOrganization(), item, pipeline, expectedBuildNumber, pipeline.getLink().rel("queue").rel(Long.toString(item.getId())), pipeline.getLink()).toRun();
} else {
throw new ServiceException.UnexpectedErrorException("Queue item request was not accepted");
}
} else {
throw new ServiceException.NotImplementedException("This pipeline type does not support being queued.");
}
}
Aggregations