Search in sources :

Example 1 with CauseAction

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

Example 2 with CauseAction

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;
}
Also used : Item(hudson.model.Item) Authentication(org.acegisecurity.Authentication) CauseAction(hudson.model.CauseAction) MultiBranchProject(jenkins.branch.MultiBranchProject) ACL(hudson.security.ACL) BranchSource(jenkins.branch.BranchSource) CheckForNull(javax.annotation.CheckForNull)

Example 3 with CauseAction

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"));
}
Also used : Shell(hudson.tasks.Shell) StringParameterDefinition(hudson.model.StringParameterDefinition) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) StringParameterValue(hudson.model.StringParameterValue) CauseAction(hudson.model.CauseAction) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) FreeStyleProject(hudson.model.FreeStyleProject) ParametersAction(hudson.model.ParametersAction) Test(org.junit.Test)

Aggregations

CauseAction (hudson.model.CauseAction)3 ParametersAction (hudson.model.ParametersAction)2 ImmutableList (com.google.common.collect.ImmutableList)1 Cause (hudson.model.Cause)1 FreeStyleProject (hudson.model.FreeStyleProject)1 Item (hudson.model.Item)1 ParameterValue (hudson.model.ParameterValue)1 ParametersDefinitionProperty (hudson.model.ParametersDefinitionProperty)1 Queue (hudson.model.Queue)1 StringParameterDefinition (hudson.model.StringParameterDefinition)1 StringParameterValue (hudson.model.StringParameterValue)1 ScheduleResult (hudson.model.queue.ScheduleResult)1 ACL (hudson.security.ACL)1 Shell (hudson.tasks.Shell)1 List (java.util.List)1 CheckForNull (javax.annotation.CheckForNull)1 BranchSource (jenkins.branch.BranchSource)1 MultiBranchProject (jenkins.branch.MultiBranchProject)1 Authentication (org.acegisecurity.Authentication)1 Test (org.junit.Test)1