private FreeStyleProject createJob(Builder builder) throws IOException { FreeStyleProject p = createFreeStyleProject(); p.setAssignedLabel( null); // let it roam free, or else it ties itself to the master since we have no slaves p.getBuildersList().add(builder); return p; }
public void testSelfExcludingJobs() throws Exception { BuildBlockerProperty theProperty = new BuildBlockerProperty(); theProperty.setBlockingJobs("SelfExcluding_.*"); FreeStyleProject theJob1 = createFreeStyleProject("SelfExcluding_Job1"); theJob1.addProperty(theProperty); assertTrue(theJob1.getBuilds().isEmpty()); FreeStyleProject theJob2 = createFreeStyleProject("SelfExcluding_Job2"); theJob2.addProperty(theProperty); assertTrue(theJob1.getBuilds().isEmpty()); // allow executing two simultanious jobs int theOldNumExecutors = Hudson.getInstance().getNumExecutors(); Hudson.getInstance().setNumExecutors(2); Future<FreeStyleBuild> theFuture1 = theJob1.scheduleBuild2(0); Future<FreeStyleBuild> theFuture2 = theJob2.scheduleBuild2(0); long theStartTime = System.currentTimeMillis(); long theEndTime = theStartTime; while ((!theFuture1.isDone() || !theFuture2.isDone()) && theEndTime < theStartTime + 5000) { theEndTime = System.currentTimeMillis(); } // if more then five seconds have passed, we assume its a deadlock. assertTrue(theEndTime < theStartTime + 5000); // restore changed settings Hudson.getInstance().setNumExecutors(theOldNumExecutors); theJob2.delete(); theJob1.delete(); }
/** Scenario: loads on one label shouldn't translate to load on another label. */ public void testLabels() throws Exception { BulkChange bc = new BulkChange(hudson); try { DummyCloudImpl cloud = initHudson(0); Label blue = hudson.getLabel("blue"); Label red = hudson.getLabel("red"); cloud.label = red; // red jobs List<FreeStyleProject> redJobs = create5SlowJobs(new Latch(5)); for (FreeStyleProject p : redJobs) p.setAssignedLabel(red); // blue jobs List<FreeStyleProject> blueJobs = create5SlowJobs(new Latch(5)); for (FreeStyleProject p : blueJobs) p.setAssignedLabel(blue); // build all List<Future<FreeStyleBuild>> blueBuilds = buildAll(blueJobs); verifySuccessfulCompletion(buildAll(redJobs)); // cloud should only give us 5 nodes for 5 red jobs assertEquals(5, cloud.numProvisioned); // and all blue jobs should be still stuck in the queue for (Future<FreeStyleBuild> bb : blueBuilds) assertFalse(bb.isDone()); } finally { bc.abort(); } }
@Test public void testGetItem() throws Exception{ ListView view = listView("foo"); FreeStyleProject job1 = j.createFreeStyleProject("free"); MatrixProject job2 = j.createMatrixProject("matrix"); FreeStyleProject job3 = j.createFreeStyleProject("not-included"); view.jobNames.add(job2.getDisplayName()); view.jobNames.add(job1.getDisplayName()); assertEquals("View should return job " + job1.getDisplayName(),job1, view.getItem("free")); assertNotNull("View should return null.", view.getItem("not-included")); }
/** * Returns the future object for a newly created project. * * @param blockingJobName the name for the project * @param shell the shell command task to add * @param label the label to bind to master or slave * @return the future object for a newly created project * @throws IOException */ private Future<FreeStyleBuild> createBlockingProject( String blockingJobName, Shell shell, Label label) throws IOException { FreeStyleProject blockingProject = this.createFreeStyleProject(blockingJobName); blockingProject.setAssignedLabel(label); blockingProject.getBuildersList().add(shell); Future<FreeStyleBuild> future = blockingProject.scheduleBuild2(0); while (!blockingProject.isBuilding()) { // wait until job is started } return future; }
/** * One test for all for faster execution. * * @throws Exception */ public void testCanRun() throws Exception { // init slave LabelAtom slaveLabel = new LabelAtom("slave"); LabelAtom masterLabel = new LabelAtom("master"); DumbSlave slave = this.createSlave(slaveLabel); SlaveComputer c = slave.getComputer(); c.connect(false).get(); // wait until it's connected if (c.isOffline()) { fail("Slave failed to go online: " + c.getLog()); } BuildBlockerQueueTaskDispatcher dispatcher = new BuildBlockerQueueTaskDispatcher(); String blockingJobName = "blockingJob"; Shell shell = new Shell("sleep 1"); Future<FreeStyleBuild> future1 = createBlockingProject("xxx", shell, masterLabel); Future<FreeStyleBuild> future2 = createBlockingProject(blockingJobName, shell, masterLabel); Future<FreeStyleBuild> future3 = createBlockingProject("yyy", shell, slaveLabel); // add project to slave FreeStyleProject project = this.createFreeStyleProject(); project.setAssignedLabel(slaveLabel); Queue.BuildableItem item = new Queue.BuildableItem( new Queue.WaitingItem(Calendar.getInstance(), project, new ArrayList<Action>())); CauseOfBlockage causeOfBlockage = dispatcher.canRun(item); assertNull(causeOfBlockage); BuildBlockerProperty property = new BuildBlockerProperty(); property.setBlockingJobs(".*ocki.*"); project.addProperty(property); causeOfBlockage = dispatcher.canRun(item); assertNotNull(causeOfBlockage); assertEquals( "Blocking job " + blockingJobName + " is running.", causeOfBlockage.getShortDescription()); while (!(future1.isDone() && future2.isDone() && future3.isDone())) { // wait until jobs are done. } }
/** Scenario: schedule a build and see if one slave is provisioned. */ public void testAutoProvision() throws Exception { BulkChange bc = new BulkChange(hudson); try { DummyCloudImpl cloud = initHudson(10); FreeStyleProject p = createJob(new SleepBuilder(10)); Future<FreeStyleBuild> f = p.scheduleBuild2(0); f.get(30, TimeUnit.SECONDS); // if it's taking too long, abort. // since there's only one job, we expect there to be just one slave assertEquals(1, cloud.numProvisioned); } finally { bc.abort(); } }
@Test public void nonSensitiveParameters() throws Exception { FreeStyleProject project = j.createFreeStyleProject(); ParametersDefinitionProperty pdb = new ParametersDefinitionProperty( new StringParameterDefinition("string", "defaultValue", "string description")); project.addProperty(pdb); CaptureEnvironmentBuilder builder = new CaptureEnvironmentBuilder(); project.getBuildersList().add(builder); FreeStyleBuild build = project.scheduleBuild2(0).get(); Set<String> sensitiveVars = build.getSensitiveBuildVariables(); assertNotNull(sensitiveVars); assertFalse(sensitiveVars.contains("string")); }
@Test public void testRebuild() throws Exception { // job with promotion process FreeStyleProject p1 = j.createFreeStyleProject("promojob"); // setup promotion process JobPropertyImpl promotion = new JobPropertyImpl(p1); p1.addProperty(promotion); PromotionProcess proc = promotion.addProcess("promo"); proc.conditions.add(new SelfPromotionCondition(false)); // build it FreeStyleBuild b1 = j.assertBuildStatusSuccess(p1.scheduleBuild2(0)); j.waitUntilNoActivity(); // verify that promotion happened Assert.assertSame(proc.getBuilds().getLastBuild().getTarget(), b1); // job with parameter FreeStyleProject p2 = j.createFreeStyleProject("paramjob"); // add promoted build param p2.addProperty( new ParametersDefinitionProperty( new PromotedBuildParameterDefinition( "var", "promojob", "promo", "promoted build param to test rebuild"))); // build with parameter FreeStyleBuild b2 = j.assertBuildStatusSuccess(p2.scheduleBuild2(0)); // validate presence of parameter ParametersAction a1 = b2.getAction(ParametersAction.class); Assert.assertNotNull(a1); Assert.assertFalse(a1.getParameters().isEmpty()); ParameterValue v1 = a1.getParameter("var"); Assert.assertTrue(v1 instanceof PromotedBuildParameterValue); PromotedBuildParameterValue pbpv1 = (PromotedBuildParameterValue) v1; Assert.assertEquals(b1.getNumber(), pbpv1.getRun().getNumber()); // rebuild it JenkinsRule.WebClient wc = j.createWebClient(); HtmlPage page = wc.getPage(b2, "rebuild"); HtmlForm form = page.getFormByName("config"); j.submit(form); j.waitUntilNoActivity(); // validate presence of parameter FreeStyleBuild rebuild = p2.getLastBuild(); j.assertBuildStatusSuccess(rebuild); Assert.assertNotEquals(b2.getNumber(), rebuild.getNumber()); ParametersAction a2 = rebuild.getAction(ParametersAction.class); Assert.assertNotNull(a2); Assert.assertFalse(a2.getParameters().isEmpty()); ParameterValue v2 = a2.getParameter("var"); Assert.assertTrue(v2 instanceof PromotedBuildParameterValue); PromotedBuildParameterValue pbpv2 = (PromotedBuildParameterValue) v2; Assert.assertEquals(b1.getNumber(), pbpv2.getRun().getNumber()); }
@Test @Issue("JENKINS-11543") public void unicodeParametersArePresetCorrectly() throws Exception { final FreeStyleProject p = j.createFreeStyleProject(); ParametersDefinitionProperty pdb = new ParametersDefinitionProperty( new StringParameterDefinition("sname:a¶‱ﻷ", "svalue:a¶‱ﻷ", "sdesc:a¶‱ﻷ"), new FileParameterDefinition("fname:a¶‱ﻷ", "fdesc:a¶‱ﻷ")); p.addProperty(pdb); WebClient wc = j.createWebClient(); wc.setThrowExceptionOnFailingStatusCode(false); // Ignore 405 HtmlPage page = wc.getPage(p, "build"); // java.lang.IllegalArgumentException: No such parameter definition: <gibberish>. wc.setThrowExceptionOnFailingStatusCode(true); final HtmlForm form = page.getFormByName("parameters"); form.submit(form.getButtonByCaption("Build")); }
@Test public void choiceWithLTGT() throws Exception { FreeStyleProject project = j.createFreeStyleProject(); ParametersDefinitionProperty pdp = new ParametersDefinitionProperty( new ChoiceParameterDefinition("choice", "Choice 1\nChoice <2>", "choice description")); project.addProperty(pdp); CaptureEnvironmentBuilder builder = new CaptureEnvironmentBuilder(); project.getBuildersList().add(builder); WebClient wc = j.createWebClient(); wc.setThrowExceptionOnFailingStatusCode(false); HtmlPage page = wc.goTo("job/" + project.getName() + "/build?delay=0sec"); HtmlForm form = page.getFormByName("parameters"); HtmlElement element = (HtmlElement) form.selectSingleNode(".//tr[td/div/input/@value='choice']"); assertNotNull(element); assertEquals( "choice description", ((HtmlElement) element .getNextSibling() .getNextSibling() .selectSingleNode("td[@class='setting-description']")) .getTextContent()); assertEquals( "choice", ((HtmlElement) element.selectSingleNode("td[@class='setting-name']")).getTextContent()); HtmlOption opt = (HtmlOption) element.selectSingleNode("td/div/select/option[@value='Choice <2>']"); assertNotNull(opt); assertEquals("Choice <2>", opt.asText()); opt.setSelected(true); j.submit(form); Queue.Item q = j.jenkins.getQueue().getItem(project); if (q != null) q.getFuture().get(); else Thread.sleep(1000); assertNotNull(builder.getEnvVars()); assertEquals("Choice <2>", builder.getEnvVars().get("CHOICE")); }
@Test @Issue("JENKINS-3539") public void fileParameterNotSet() throws Exception { FreeStyleProject project = j.createFreeStyleProject(); ParametersDefinitionProperty pdp = new ParametersDefinitionProperty(new FileParameterDefinition("filename", "description")); project.addProperty(pdp); WebClient wc = j.createWebClient(); wc.setThrowExceptionOnFailingStatusCode(false); HtmlPage page = wc.goTo("job/" + project.getName() + "/build?delay=0sec"); HtmlForm form = page.getFormByName("parameters"); j.submit(form); Queue.Item q = j.jenkins.getQueue().getItem(project); if (q != null) q.getFuture().get(); else Thread.sleep(1000); assertFalse("file must not exist", project.getSomeWorkspace().child("filename").exists()); }
@Test @Issue("JENKINS-21474") public void testGetComputersNPE() throws Exception { ListView view = listView("aView"); view.filterExecutors = true; DumbSlave dedicatedSlave = j.createOnlineSlave(); dedicatedSlave.setMode(Mode.EXCLUSIVE); view.add(j.createFreeStyleProject()); FreeStyleProject tiedJob = j.createFreeStyleProject(); tiedJob.setAssignedNode(dedicatedSlave); view.add(tiedJob); DumbSlave notIncludedSlave = j.createOnlineSlave(); notIncludedSlave.setMode(Mode.EXCLUSIVE); assertContainsNodes(view, j.jenkins, dedicatedSlave); assertNotContainsNodes(view, notIncludedSlave); }
public void setUp() throws Exception { super.setUp(); EnvVars env = new EnvVars(); // we don't want Maven, Ant, etc. to be discovered in the path for this test to work, // but on Unix these tools rely on other basic Unix tools (like env) for its operation, // so empty path breaks the test. env.put("PATH", "/bin:/usr/bin"); env.put("M2_HOME", "empty"); slave = createSlave(new LabelAtom("slave"), env); project = createFreeStyleProject(); project.setAssignedLabel(slave.getSelfLabel()); }
@Test public void testGetQueueItems() throws IOException, Exception{ ListView view1 = listView("view1"); view1.filterQueue = true; ListView view2 = listView("view2"); view2.filterQueue = true; FreeStyleProject inView1 = j.createFreeStyleProject("in-view1"); inView1.setAssignedLabel(j.jenkins.getLabelAtom("without-any-slave")); view1.add(inView1); MatrixProject inView2 = j.createMatrixProject("in-view2"); inView2.setAssignedLabel(j.jenkins.getLabelAtom("without-any-slave")); view2.add(inView2); FreeStyleProject notInView = j.createFreeStyleProject("not-in-view"); notInView.setAssignedLabel(j.jenkins.getLabelAtom("without-any-slave")); FreeStyleProject inBothViews = j.createFreeStyleProject("in-both-views"); inBothViews.setAssignedLabel(j.jenkins.getLabelAtom("without-any-slave")); view1.add(inBothViews); view2.add(inBothViews); Queue.getInstance().schedule(notInView, 0); Queue.getInstance().schedule(inView1, 0); Queue.getInstance().schedule(inView2, 0); Queue.getInstance().schedule(inBothViews, 0); Thread.sleep(1000); assertContainsItems(view1, inView1, inBothViews); assertNotContainsItems(view1, notInView, inView2); assertContainsItems(view2, inView2, inBothViews); assertNotContainsItems(view2, notInView, inView1); }
@Test public void testSave() throws Exception{ ListView view = listView("foo"); FreeStyleProject job = j.createFreeStyleProject("free"); view.jobNames.add("free"); view.save(); j.jenkins.doReload(); //wait until all configuration are reloaded if(j.jenkins.servletContext.getAttribute("app") instanceof HudsonIsLoading){ Thread.sleep(500); } assertTrue("View does not contains job free after load.", j.jenkins.getView(view.getDisplayName()).contains(j.jenkins.getItem(job.getName()))); }
/** Can {@link Queue} successfully recover removal? */ public void testPersistence2() throws Exception { Queue q = hudson.getQueue(); // prevent execution to push stuff into the queue hudson.setNumExecutors(0); hudson.setNodes(hudson.getNodes()); FreeStyleProject testProject = createFreeStyleProject("test"); testProject.scheduleBuild(new UserCause()); q.save(); System.out.println(FileUtils.readFileToString(new File(hudson.getRootDir(), "queue.xml"))); assertEquals(1, q.getItems().length); q.clear(); assertEquals(0, q.getItems().length); // delete the project before loading the queue back testProject.delete(); q.load(); assertEquals(0, q.getItems().length); }
/** Checks the persistence of queue. */ public void testPersistence() throws Exception { Queue q = hudson.getQueue(); // prevent execution to push stuff into the queue hudson.setNumExecutors(0); hudson.setNodes(hudson.getNodes()); FreeStyleProject testProject = createFreeStyleProject("test"); testProject.scheduleBuild(new UserCause()); q.save(); System.out.println(FileUtils.readFileToString(new File(hudson.getRootDir(), "queue.xml"))); assertEquals(1, q.getItems().length); q.clear(); assertEquals(0, q.getItems().length); // load the contents back q.load(); assertEquals(1, q.getItems().length); // did it bind back to the same object? assertSame(q.getItems()[0].task, testProject); }
public void testAnt() throws Exception { Ant.AntInstallation ant = configureDefaultAnt(); String antPath = ant.getHome(); Jenkins.getInstance() .getDescriptorByType(Ant.DescriptorImpl.class) .setInstallations(new AntInstallation("ant", "THIS IS WRONG")); project.setScm(new SingleFileSCM("build.xml", "<project name='foo'/>")); project.getBuildersList().add(new Ant("-version", "ant", null, null, null)); configureDumpEnvBuilder(); Build build = project.scheduleBuild2(0).get(); assertBuildStatus(Result.FAILURE, build); ToolLocationNodeProperty property = new ToolLocationNodeProperty( new ToolLocationNodeProperty.ToolLocation( jenkins.getDescriptorByType(AntInstallation.DescriptorImpl.class), "ant", antPath)); slave.getNodeProperties().add(property); build = project.scheduleBuild2(0).get(); System.out.println(build.getLog()); assertBuildStatus(Result.SUCCESS, build); }
public void testMaven() throws Exception { MavenInstallation maven = configureDefaultMaven(); String mavenPath = maven.getHome(); Jenkins.getInstance() .getDescriptorByType(Maven.DescriptorImpl.class) .setInstallations(new MavenInstallation("maven", "THIS IS WRONG", NO_PROPERTIES)); project.getBuildersList().add(new Maven("--version", "maven")); configureDumpEnvBuilder(); Build build = project.scheduleBuild2(0).get(); assertBuildStatus(Result.FAILURE, build); ToolLocationNodeProperty property = new ToolLocationNodeProperty( new ToolLocationNodeProperty.ToolLocation( jenkins.getDescriptorByType(MavenInstallation.DescriptorImpl.class), "maven", mavenPath)); slave.getNodeProperties().add(property); build = project.scheduleBuild2(0).get(); assertBuildStatus(Result.SUCCESS, build); }
@Test public void testGetComputers() throws IOException, Exception{ ListView view1 = listView("view1"); ListView view2 = listView("view2"); ListView view3 = listView("view3"); view1.filterExecutors=true; view2.filterExecutors=true; view3.filterExecutors=true; Slave slave0 = j.createOnlineSlave(j.jenkins.getLabel("label0")); Slave slave1 = j.createOnlineSlave(j.jenkins.getLabel("label1")); Slave slave2 = j.createOnlineSlave(j.jenkins.getLabel("label2")); Slave slave3 = j.createOnlineSlave(j.jenkins.getLabel("label0")); Slave slave4 = j.createOnlineSlave(j.jenkins.getLabel("label4")); FreeStyleProject freestyleJob = j.createFreeStyleProject("free"); view1.add(freestyleJob); freestyleJob.setAssignedLabel(j.jenkins.getLabel("label0||label2")); MatrixProject matrixJob = j.createMatrixProject("matrix"); view1.add(matrixJob); matrixJob.setAxes(new AxisList( new LabelAxis("label", Arrays.asList("label1")) )); FreeStyleProject noLabelJob = j.createFreeStyleProject("not-assigned-label"); view3.add(noLabelJob); noLabelJob.setAssignedLabel(null); FreeStyleProject foreignJob = j.createFreeStyleProject("in-other-view"); view2.add(foreignJob); foreignJob.setAssignedLabel(j.jenkins.getLabel("label0||label1")); // contains all slaves having labels associated with freestyleJob or matrixJob assertContainsNodes(view1, slave0, slave1, slave2, slave3); assertNotContainsNodes(view1, slave4); // contains all slaves having labels associated with foreignJob assertContainsNodes(view2, slave0, slave1, slave3); assertNotContainsNodes(view2, slave2, slave4); // contains all slaves as it contains noLabelJob that can run everywhere assertContainsNodes(view3, slave0, slave1, slave2, slave3, slave4); }
public void testMultipleExecutors() throws Exception { // Job1 runs for 1 second, no dependencies FreeStyleProject theJob1 = createFreeStyleProject("MultipleExecutor_Job1"); theJob1.getBuildersList().add(new Shell("sleep 1; exit 0")); assertTrue(theJob1.getBuilds().isEmpty()); // Job2 returns immediatly but can't run while Job1 is running. FreeStyleProject theJob2 = createFreeStyleProject("MultipleExecutor_Job2"); { BuildBlockerProperty theProperty = new BuildBlockerProperty(); theProperty.setBlockingJobs("MultipleExecutor_Job1"); theJob2.addProperty(theProperty); } assertTrue(theJob1.getBuilds().isEmpty()); // allow executing two simultanious jobs int theOldNumExecutors = Hudson.getInstance().getNumExecutors(); Hudson.getInstance().setNumExecutors(2); Future<FreeStyleBuild> theFuture1 = theJob1.scheduleBuild2(0); Future<FreeStyleBuild> theFuture2 = theJob2.scheduleBuild2(0); while (!theFuture1.isDone() || !theFuture2.isDone()) { // let the jobs process } // check if job2 was not started before job1 was finished Run theRun1 = theJob1.getLastBuild(); Run theRun2 = theJob2.getLastBuild(); assertTrue(theRun1.getTimeInMillis() + theRun1.getDuration() <= theRun2.getTimeInMillis()); // restore changed settings Hudson.getInstance().setNumExecutors(theOldNumExecutors); theJob2.delete(); theJob1.delete(); }
public void testFoldableCauseAction() throws Exception { final OneShotEvent buildStarted = new OneShotEvent(); final OneShotEvent buildShouldComplete = new OneShotEvent(); hudson.quietPeriod = 0; FreeStyleProject project = createFreeStyleProject(); // Make build sleep a while so it blocks new builds project .getBuildersList() .add( new TestBuilder() { public boolean perform( AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { buildStarted.signal(); buildShouldComplete.block(); return true; } }); // Start one build to block others assertTrue(project.scheduleBuild(new UserCause())); buildStarted.block(); // wait for the build to really start // Schedule a new build, and trigger it many ways while it sits in queue Future<FreeStyleBuild> fb = project.scheduleBuild2(0, new UserCause()); assertNotNull(fb); assertFalse(project.scheduleBuild(new SCMTriggerCause())); assertFalse(project.scheduleBuild(new UserCause())); assertFalse(project.scheduleBuild(new TimerTriggerCause())); assertFalse(project.scheduleBuild(new RemoteCause("1.2.3.4", "test"))); assertFalse(project.scheduleBuild(new RemoteCause("4.3.2.1", "test"))); assertFalse(project.scheduleBuild(new SCMTriggerCause())); assertFalse(project.scheduleBuild(new RemoteCause("1.2.3.4", "test"))); assertFalse(project.scheduleBuild(new RemoteCause("1.2.3.4", "foo"))); assertFalse(project.scheduleBuild(new SCMTriggerCause())); assertFalse(project.scheduleBuild(new TimerTriggerCause())); // Wait for 2nd build to finish buildShouldComplete.signal(); FreeStyleBuild build = fb.get(); // Make sure proper folding happened. CauseAction ca = build.getAction(CauseAction.class); assertNotNull(ca); StringBuilder causes = new StringBuilder(); for (Cause c : ca.getCauses()) causes.append(c.getShortDescription() + "\n"); assertEquals( "Build causes should have all items, even duplicates", "Started by user anonymous\nStarted by an SCM change\n" + "Started by user anonymous\nStarted by timer\n" + "Started by remote host 1.2.3.4 with note: test\n" + "Started by remote host 4.3.2.1 with note: test\n" + "Started by an SCM change\n" + "Started by remote host 1.2.3.4 with note: test\n" + "Started by remote host 1.2.3.4 with note: foo\n" + "Started by an SCM change\nStarted by timer\n", causes.toString()); // View for build should group duplicates WebClient wc = new WebClient(); String buildPage = wc.getPage(build, "").asText().replace('\n', ' '); assertTrue( "Build page should combine duplicates and show counts: " + buildPage, buildPage.contains( "Started by user anonymous (2 times) " + "Started by an SCM change (3 times) " + "Started by timer (2 times) " + "Started by remote host 1.2.3.4 with note: test (2 times) " + "Started by remote host 4.3.2.1 with note: test " + "Started by remote host 1.2.3.4 with note: foo")); }
@Test public void parameterTypes() throws Exception { FreeStyleProject otherProject = j.createFreeStyleProject(); otherProject.scheduleBuild2(0).get(); FreeStyleProject project = j.createFreeStyleProject(); ParametersDefinitionProperty pdp = new ParametersDefinitionProperty( new StringParameterDefinition("string", "defaultValue", "string description"), new BooleanParameterDefinition("boolean", true, "boolean description"), new ChoiceParameterDefinition("choice", "Choice 1\nChoice 2", "choice description"), new RunParameterDefinition("run", otherProject.getName(), "run description", null)); project.addProperty(pdp); CaptureEnvironmentBuilder builder = new CaptureEnvironmentBuilder(); project.getBuildersList().add(builder); WebClient wc = j.createWebClient(); wc.setThrowExceptionOnFailingStatusCode(false); HtmlPage page = wc.goTo("job/" + project.getName() + "/build?delay=0sec"); HtmlForm form = page.getFormByName("parameters"); HtmlElement element = (HtmlElement) form.selectSingleNode("//tr[td/div/input/@value='string']"); assertNotNull(element); assertEquals( "string description", ((HtmlElement) element .getNextSibling() .getNextSibling() .selectSingleNode("td[@class='setting-description']")) .getTextContent()); HtmlTextInput stringParameterInput = (HtmlTextInput) element.selectSingleNode(".//input[@name='value']"); assertEquals("defaultValue", stringParameterInput.getAttribute("value")); assertEquals( "string", ((HtmlElement) element.selectSingleNode("td[@class='setting-name']")).getTextContent()); stringParameterInput.setAttribute("value", "newValue"); element = (HtmlElement) form.selectSingleNode("//tr[td/div/input/@value='boolean']"); assertNotNull(element); assertEquals( "boolean description", ((HtmlElement) element .getNextSibling() .getNextSibling() .selectSingleNode("td[@class='setting-description']")) .getTextContent()); Object o = element.selectSingleNode(".//input[@name='value']"); System.out.println(o); HtmlCheckBoxInput booleanParameterInput = (HtmlCheckBoxInput) o; assertEquals(true, booleanParameterInput.isChecked()); assertEquals( "boolean", ((HtmlElement) element.selectSingleNode("td[@class='setting-name']")).getTextContent()); element = (HtmlElement) form.selectSingleNode(".//tr[td/div/input/@value='choice']"); assertNotNull(element); assertEquals( "choice description", ((HtmlElement) element .getNextSibling() .getNextSibling() .selectSingleNode("td[@class='setting-description']")) .getTextContent()); assertEquals( "choice", ((HtmlElement) element.selectSingleNode("td[@class='setting-name']")).getTextContent()); element = (HtmlElement) form.selectSingleNode(".//tr[td/div/input/@value='run']"); assertNotNull(element); assertEquals( "run description", ((HtmlElement) element .getNextSibling() .getNextSibling() .selectSingleNode("td[@class='setting-description']")) .getTextContent()); assertEquals( "run", ((HtmlElement) element.selectSingleNode("td[@class='setting-name']")).getTextContent()); j.submit(form); Queue.Item q = j.jenkins.getQueue().getItem(project); if (q != null) q.getFuture().get(); else Thread.sleep(1000); assertEquals("newValue", builder.getEnvVars().get("STRING")); assertEquals("true", builder.getEnvVars().get("BOOLEAN")); assertEquals("Choice 1", builder.getEnvVars().get("CHOICE")); assertEquals( j.jenkins.getRootUrl() + otherProject.getLastBuild().getUrl(), builder.getEnvVars().get("RUN")); }
private void configureDumpEnvBuilder() throws IOException { if (Functions.isWindows()) project.getBuildersList().add(new BatchFile("set")); else project.getBuildersList().add(new Shell("export")); }
/** Builds all the given projects at once. */ private List<Future<FreeStyleBuild>> buildAll(List<FreeStyleProject> jobs) { System.out.println("Scheduling builds for " + jobs.size() + " jobs"); List<Future<FreeStyleBuild>> builds = new ArrayList<Future<FreeStyleBuild>>(); for (FreeStyleProject job : jobs) builds.add(job.scheduleBuild2(0)); return builds; }