use of hudson.model.StringParameterDefinition in project wavefront-plugin-for-jenkins by vmware.
the class WavefrontBuildListenerTest method testSendingSpecificJobParametersToWavefront.
@Test
public void testSendingSpecificJobParametersToWavefront() throws Exception {
List<String> expected = new ArrayList<>(Arrays.asList("p_branch=master", "p_isDevMode=true"));
WorkflowJob job = jenkinsRule.createProject(WorkflowJob.class, "Test Job");
ParameterDefinition paramDef0 = new StringParameterDefinition("dummyParam", "dummyValue", "");
ParameterDefinition paramDef1 = new StringParameterDefinition("branch", "master", "");
ParameterDefinition paramDef2 = new BooleanParameterDefinition("isDevMode", true, "");
ParametersDefinitionProperty prop = new ParametersDefinitionProperty(paramDef0, paramDef1, paramDef2);
job.addProperty(prop);
WavefrontJobProperty wavefrontJobProperty = mock(WavefrontJobProperty.class);
String jobParametersToSend = "branch\nisDevMode";
when(wavefrontJobProperty.isEnableSendingJobParameters()).thenReturn(true);
when(wavefrontJobProperty.getJobParameters()).thenReturn(jobParametersToSend);
job.addProperty(wavefrontJobProperty);
job.setDefinition(new CpsFlowDefinition("node {\n" + "}", true));
jenkinsRule.buildAndAssertSuccess(job);
List<String> messages = proxy.terminate();
String actual = messages.get(0).replaceAll("[\"]", "");
String message = "The expected point tags are not present";
for (String e : expected) {
if (!actual.contains(e)) {
Assert.fail(message);
}
}
}
use of hudson.model.StringParameterDefinition in project maven-plugin by jenkinsci.
the class AbstractMaven3xBuildTest method testMavenWithDependencyVersionInEnvVar.
@Test
@Email("https://groups.google.com/d/msg/hudson-users/Xhw00UopVN0/FA9YqDAIsSYJ")
public void testMavenWithDependencyVersionInEnvVar() throws Exception {
MavenModuleSet m = j.jenkins.createProject(MavenModuleSet.class, "p");
MavenInstallation mavenInstallation = configureMaven3x();
ParametersDefinitionProperty parametersDefinitionProperty = new ParametersDefinitionProperty(new StringParameterDefinition("JUNITVERSION", "3.8.2"));
m.addProperty(parametersDefinitionProperty);
m.setMaven(mavenInstallation.getName());
m.getReporters().add(new TestReporter());
m.setScm(new ExtractResourceSCM(getClass().getResource("envars-maven-project.zip")));
m.setGoals("clean test-compile -Dmaven.compiler.target=1.8 -Dmaven.compiler.source=1.8");
MavenModuleSetBuild mmsb = j.buildAndAssertSuccess(m);
assertFalse(mmsb.getProject().getModules().isEmpty());
}
use of hudson.model.StringParameterDefinition 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.get().getQueue().schedule(p1, 0, new ParametersAction(new StringParameterValue("test", "test1")), new CauseAction(new Cause.UserIdCause()));
Jenkins.get().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"));
Run r = QueueUtil.getRun(p1, Long.parseLong((String) ((Map) queue.get(0)).get("id")));
// its not moved out of queue yet
assertNull(r);
}
use of hudson.model.StringParameterDefinition in project promoted-builds-plugin by jenkinsci.
the class ManualConditionTest method testManualPromotionProcessWithInvalidParam.
@Issue("SECURITY-170")
@Test
public /**
* Verify that the plugin is tolerant against SECURITY-170 in Manual conditions
*/
void testManualPromotionProcessWithInvalidParam() throws Exception {
FreeStyleProject p = j.createFreeStyleProject();
ExtensionList<Descriptor> list = j.jenkins.getExtensionList(Descriptor.class);
list.add(new JobPropertyImpl.DescriptorImpl(JobPropertyImpl.class));
JobPropertyImpl base = new JobPropertyImpl(p);
p.addProperty(base);
PromotionProcess foo = base.addProcess("foo");
ManualCondition condition = new ManualCondition();
condition.getParameterDefinitions().add(new StringParameterDefinition("FOO", "BAR", "Test parameter"));
foo.conditions.add(condition);
FreeStyleBuild b1 = j.assertBuildStatusSuccess(p.scheduleBuild2(0));
// Promote a build. Also add one invalid parameter
List<ParameterValue> paramValues = condition.createDefaultValues();
paramValues.add(new StringParameterValue("INVALID_PARAM", "hacked!"));
j.assertBuildStatusSuccess(condition.approve(b1, foo, paramValues));
ManualApproval manualApproval = b1.getAction(ManualApproval.class);
assertNotNull(manualApproval);
List<ParameterValue> parameterValues = manualApproval.badge.getParameterValues();
// Verify that the build succeeds && has no INVALID_PARAM
PromotedBuildAction statuses = b1.getAction(PromotedBuildAction.class);
assertNotNull(statuses);
assertNotNull(statuses.getPromotions());
assertFalse(statuses.getPromotions().isEmpty());
Promotion pb = base.getItem("foo").getBuildByNumber(1);
assertNotNull("INVALID_PARAM should not be injected into the environment", pb.getEnvironment(TaskListener.NULL).get("INVALID_PARAM", null));
}
use of hudson.model.StringParameterDefinition in project promoted-builds-plugin by jenkinsci.
the class ManualConditionTest method testManualPromotionProcessViaWebClient.
@Test
public void testManualPromotionProcessViaWebClient() throws Exception {
FreeStyleProject p = j.createFreeStyleProject();
ExtensionList<Descriptor> list = j.jenkins.getExtensionList(Descriptor.class);
list.add(new JobPropertyImpl.DescriptorImpl(JobPropertyImpl.class));
JobPropertyImpl base = new JobPropertyImpl(p);
p.addProperty(base);
PromotionProcess foo = base.addProcess("foo");
ManualCondition condition = new ManualCondition();
condition.getParameterDefinitions().add(new StringParameterDefinition("bogus_string_param_1", "bogus_value_1", "Bog parameter"));
condition.getParameterDefinitions().add(new StringParameterDefinition("bogus_string_param_2", "bogus_value_2", "Bog parameter"));
foo.conditions.add(condition);
FreeStyleBuild b1 = j.assertBuildStatusSuccess(p.scheduleBuild2(0));
assertNull(b1.getAction(ManualApproval.class));
HtmlPage page = j.createWebClient().getPage(b1, "promotion");
// Approve Promotion
List<HtmlForm> forms = getFormsByName(page, "approve");
assertFalse(forms.isEmpty());
assertEquals(1, forms.size());
HtmlForm form = forms.get(0);
List<HtmlElement> parameters = getFormParameters(form);
assertEquals(parameters.size(), condition.getParameterDefinitions().size());
for (HtmlElement param : parameters) {
HtmlElement v = param.getElementsByAttribute("input", "name", "value").get(0);
v.setAttribute("value", v.getAttribute("value") + "1");
}
submit(forms.get(0));
ManualApproval approval = b1.getAction(ManualApproval.class);
assertNotNull(approval);
SortedMap<Integer, Promotion> builds = foo.getBuildsAsMap();
assertNotNull(builds);
assertEquals(1, builds.size());
// Re-Execute approved promotion
page = j.createWebClient().getPage(b1, "promotion");
forms = getFormsByName(page, "build");
assertFalse(forms.isEmpty());
assertEquals(1, forms.size());
form = forms.get(0);
parameters = getFormParameters(form);
assertEquals(parameters.size(), condition.getParameterDefinitions().size());
for (HtmlElement param : parameters) {
HtmlElement v = param.getElementsByAttribute("input", "name", "value").get(0);
v.setAttribute("value", v.getAttribute("value") + "2");
}
submit(form);
builds = foo.getBuildsAsMap();
assertEquals(2, builds.size());
List<ManualApproval> actions = b1.getActions(ManualApproval.class);
assertEquals(1, actions.size());
PromotedBuildAction buildActions = b1.getAction(PromotedBuildAction.class);
int buildIndex = 1;
String valueSufix = "1";
List<Promotion> promotions = new ArrayList<Promotion>();
promotions.addAll(builds.values());
Collections.reverse(promotions);
for (Promotion build : promotions) {
List<ParameterDefinition> values = build.getParameterDefinitionsWithValue();
assertEquals(values.size(), condition.getParameterDefinitions().size());
for (ParameterDefinition v : values) {
assertTrue(v instanceof StringParameterDefinition);
String pvalue = ((StringParameterDefinition) v).getDefaultValue();
assertTrue(pvalue.endsWith(valueSufix));
}
buildIndex++;
valueSufix += buildIndex;
}
for (Status status : buildActions.getPromotions()) {
assertNotNull(status.getLast() != null);
List<ParameterDefinition> values = status.getLast().getParameterDefinitionsWithValue();
assertEquals(values.size(), condition.getParameterDefinitions().size());
}
}
Aggregations