/** * Main entry point invoked by the setup module */ public int run(Bootstrap bootstrap) throws Exception { Jenkins j = Jenkins.getInstance(); WorkflowJob w = j.createProject(WorkflowJob.class, "job"); w.addProperty(new DurabilityHintJobProperty(FlowDurabilityHint.PERFORMANCE_OPTIMIZED)); w.setDefinition(new CpsScmFlowDefinition( new FileSystemSCM(bootstrap.jenkinsfile.getParent()), bootstrap.jenkinsfile.getName())); QueueTaskFuture<WorkflowRun> f = w.scheduleBuild2(0, new SetJenkinsfileLocation(bootstrap.jenkinsfile)); b = f.getStartCondition().get(); writeLogTo(System.out); f.get(); // wait for the completion return b.getResult().ordinal; }
@Test public void durabilityHintByPropertyStep() throws Exception { sampleRepo.init(); sampleRepo.write("Jenkinsfile", "properties([durabilityHint('" + FlowDurabilityHint.SURVIVABLE_NONATOMIC.getName()+"')])\n"+ "echo 'whynot'"); sampleRepo.git("add", "Jenkinsfile"); sampleRepo.git("commit", "--all", "--message=flow"); WorkflowMultiBranchProject mp = r.jenkins.createProject(WorkflowMultiBranchProject.class, "p"); mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false))); WorkflowJob p = scheduleAndFindBranchProject(mp, "master"); r.waitUntilNoActivity(); WorkflowRun b1 = p.getLastBuild(); Assert.assertEquals(Result.SUCCESS, b1.getResult()); DurabilityHintJobProperty prop = p.getProperty(DurabilityHintJobProperty.class); Assert.assertEquals(FlowDurabilityHint.SURVIVABLE_NONATOMIC, prop.getHint()); }
/** * Main entry point invoked by the setup module */ public int run(Bootstrap bootstrap) throws Exception { Jenkins j = Jenkins.getInstance(); WorkflowJob w = j.createProject(WorkflowJob.class, "job"); w.addProperty(new DurabilityHintJobProperty(FlowDurabilityHint.PERFORMANCE_OPTIMIZED)); w.setDefinition(new CpsScmFlowDefinition( new FileSystemSCM(bootstrap.jenkinsfile.getParent()), bootstrap.jenkinsfile.getName())); QueueTaskFuture<WorkflowRun> f = w.scheduleBuild2(0, new SetJenkinsfileLocation(bootstrap.jenkinsfile)); b = f.getStartCondition().get(); writeLogTo(System.out); f.get(); // wait for the completion return b.getResult().ordinal; }
/** Sets up a running build that is waiting on input. */ private static WorkflowRun runBasicPauseOnInput(JenkinsRule j, String jobName, int[] jobIdNumber, FlowDurabilityHint durabilityHint) throws Exception { WorkflowJob job = j.jenkins.createProject(WorkflowJob.class, jobName); job.setDefinition(new CpsFlowDefinition("input 'pause'", true)); job.addProperty(new DurabilityHintJobProperty(durabilityHint)); WorkflowRun run = job.scheduleBuild2(0).getStartCondition().get(); ListenableFuture<FlowExecution> listener = run.getExecutionPromise(); FlowExecution exec = listener.get(); while(exec.getCurrentHeads().isEmpty() || (exec.getCurrentHeads().get(0) instanceof FlowStartNode)) { // Wait until input step starts System.out.println("Waiting for input step to begin"); Thread.sleep(50); } while(run.getAction(InputAction.class) == null) { // Wait until input step starts System.out.println("Waiting for input action to get attached to run"); Thread.sleep(50); } Thread.sleep(100L); // A little extra buffer for persistence etc jobIdNumber[0] = run.getNumber(); return run; }
if (job == null) { // Job may already have been created job = jenkins.createProject(WorkflowJob.class, jobName); job.addProperty(new DurabilityHintJobProperty(hint)); job.setDefinition(new CpsFlowDefinition( "echo 'first'\n" +
/** Create and run a basic build before we mangle its persisted contents. Stores job number to jobIdNumber index 0. */ private static WorkflowRun runBasicBuild(JenkinsRule j, String jobName, int[] jobIdNumber, FlowDurabilityHint hint) throws Exception { WorkflowJob job = j.jenkins.createProject(WorkflowJob.class, jobName); job.setDefinition(new CpsFlowDefinition("echo 'doSomething'", true)); job.addProperty(new DurabilityHintJobProperty(hint)); WorkflowRun run = j.buildAndAssertSuccess(job); jobIdNumber[0] = run.getNumber(); assertCompletedCleanly(run); return run; }