Search in sources :

Example 1 with ScheduleResult

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.");
    }
}
Also used : ScheduleResult(hudson.model.queue.ScheduleResult) ParameterValue(hudson.model.ParameterValue) ParametersAction(hudson.model.ParametersAction) Cause(hudson.model.Cause) CauseAction(hudson.model.CauseAction) Queue(hudson.model.Queue)

Aggregations

Cause (hudson.model.Cause)1 CauseAction (hudson.model.CauseAction)1 ParameterValue (hudson.model.ParameterValue)1 ParametersAction (hudson.model.ParametersAction)1 Queue (hudson.model.Queue)1 ScheduleResult (hudson.model.queue.ScheduleResult)1