use of hudson.model.CauseAction 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 BlueQueueItem 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.getInstance().getQueue().schedule2((Queue.Task) job, 0, new ParametersAction(parameterValues), new CauseAction(new Cause.UserIdCause()));
} else {
scheduleResult = Jenkins.getInstance().getQueue().schedule2((Queue.Task) job, 0, new CauseAction(new Cause.UserIdCause()));
}
if (scheduleResult.isAccepted()) {
final Queue.Item item = scheduleResult.getItem();
return new QueueItemImpl(item, job.getName(), expectedBuildNumber, pipeline.getLink().rel("queue").rel(Long.toString(item.getId())), pipeline.getLink());
} else {
throw new ServiceException.UnexpectedErrorException("Queue item request was not accepted");
}
} else {
throw new ServiceException.NotImplementedException("This pipeline type does not support being queued.");
}
}
use of hudson.model.CauseAction in project blueocean-plugin by jenkinsci.
the class GitPipelineUpdateRequest method update.
@CheckForNull
@Override
@SuppressWarnings("unchecked")
public BluePipeline update(BluePipeline pipeline) throws IOException {
Item item = Jenkins.getInstance().getItemByFullName(pipeline.getFullName());
if (item instanceof MultiBranchProject) {
ACL acl = Jenkins.getInstance().getACL();
Authentication a = Jenkins.getAuthentication();
if (!acl.hasPermission(a, Item.CONFIGURE)) {
throw new ServiceException.ForbiddenException(String.format("Failed to update Git pipeline: %s. User %s doesn't have Job configure permission", pipeline.getName(), a.getName()));
}
MultiBranchProject mbp = (MultiBranchProject) item;
BranchSource branchSource = getGitScmSource(mbp);
if (branchSource != null) {
mbp.getSourcesList().replaceBy(Collections.singleton(branchSource));
mbp.scheduleBuild2(0, new CauseAction(new Cause.UserIdCause()));
}
}
return pipeline;
}
use of hudson.model.CauseAction in project blueocean-plugin by jenkinsci.
the class PipelineApiTest method testPipelineQueue.
@Test
public void testPipelineQueue() throws Exception {
FreeStyleProject p1 = j.createFreeStyleProject("pipeline1");
p1.setConcurrentBuild(true);
p1.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("test", "test")));
p1.getBuildersList().add(new Shell("echo hello!\nsleep 300"));
p1.scheduleBuild2(0).waitForStart();
p1.scheduleBuild2(0).waitForStart();
Jenkins.getInstance().getQueue().schedule(p1, 0, new ParametersAction(new StringParameterValue("test", "test1")), new CauseAction(new Cause.UserIdCause()));
Jenkins.getInstance().getQueue().schedule(p1, 0, new ParametersAction(new StringParameterValue("test", "test2")), new CauseAction(new Cause.UserIdCause()));
List queue = request().get("/organizations/jenkins/pipelines/pipeline1/queue").build(List.class);
Assert.assertEquals(2, queue.size());
Assert.assertEquals(4, ((Map) queue.get(0)).get("expectedBuildNumber"));
Assert.assertEquals(3, ((Map) queue.get(1)).get("expectedBuildNumber"));
Assert.assertEquals("Waiting for next available executor", ((Map) queue.get(0)).get("causeOfBlockage"));
Assert.assertEquals("Waiting for next available executor", ((Map) queue.get(1)).get("causeOfBlockage"));
}
Aggregations