Search in sources :

Example 36 with Item

use of hudson.model.Item in project workflow-cps-plugin by jenkinsci.

the class FlowDurabilityTest method createAndRunSleeperJob.

private WorkflowRun createAndRunSleeperJob(Jenkins jenkins, String jobName, FlowDurabilityHint durabilityHint, boolean resumeBlocked) throws Exception {
    Item prev = jenkins.getItemByFullName(jobName);
    if (prev != null) {
        prev.delete();
    }
    WorkflowJob job = jenkins.createProject(WorkflowJob.class, jobName);
    job.setResumeBlocked(resumeBlocked);
    CpsFlowDefinition def = new CpsFlowDefinition("node {\n " + "sleep 30 \n" + "} \n" + "echo 'I like cheese'\n", false);
    TestDurabilityHintProvider provider = Jenkins.get().getExtensionList(TestDurabilityHintProvider.class).get(0);
    provider.registerHint(jobName, durabilityHint);
    job.setDefinition(def);
    WorkflowRun run = job.scheduleBuild2(0).getStartCondition().get();
    story.j.waitForMessage("Sleeping for", run);
    Assert.assertFalse(run.getExecution().isComplete());
    Assert.assertFalse(((CpsFlowExecution) (run.getExecution())).done);
    Assert.assertEquals(durabilityHint, run.getExecution().getDurabilityHint());
    Assert.assertEquals("sleep", run.getExecution().getCurrentHeads().get(0).getDisplayFunctionName());
    return run;
}
Also used : Item(hudson.model.Item) TestDurabilityHintProvider(org.jenkinsci.plugins.workflow.TestDurabilityHintProvider) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun)

Aggregations

Item (hudson.model.Item)36 ItemGroup (hudson.model.ItemGroup)7 BluePipeline (io.jenkins.blueocean.rest.model.BluePipeline)7 IOException (java.io.IOException)6 Run (hudson.model.Run)5 Job (hudson.model.Job)4 BlueOrganization (io.jenkins.blueocean.rest.model.BlueOrganization)4 ArrayList (java.util.ArrayList)4 Nonnull (javax.annotation.Nonnull)4 MultiBranchProject (jenkins.branch.MultiBranchProject)4 Jenkins (jenkins.model.Jenkins)4 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)4 WorkflowMultiBranchProject (org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject)4 StaplerRequest (org.kohsuke.stapler.StaplerRequest)4 TopLevelItem (hudson.model.TopLevelItem)3 User (hudson.model.User)3 Resource (io.jenkins.blueocean.rest.model.Resource)3 CheckForNull (javax.annotation.CheckForNull)3 AbstractFolder (com.cloudbees.hudson.plugins.folder.AbstractFolder)2 StandardUsernamePasswordCredentials (com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials)2