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