Search in sources :

Example 46 with StringParameterDefinition

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);
        }
    }
}
Also used : StringParameterDefinition(hudson.model.StringParameterDefinition) BooleanParameterDefinition(hudson.model.BooleanParameterDefinition) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) ArrayList(java.util.ArrayList) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) ParameterDefinition(hudson.model.ParameterDefinition) BooleanParameterDefinition(hudson.model.BooleanParameterDefinition) StringParameterDefinition(hudson.model.StringParameterDefinition) Test(org.junit.Test)

Example 47 with StringParameterDefinition

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());
}
Also used : MavenInstallation(hudson.tasks.Maven.MavenInstallation) StringParameterDefinition(hudson.model.StringParameterDefinition) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) ExtractResourceSCM(org.jvnet.hudson.test.ExtractResourceSCM) Email(org.jvnet.hudson.test.Email) Test(org.junit.Test)

Example 48 with StringParameterDefinition

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);
}
Also used : Shell(hudson.tasks.Shell) StringParameterDefinition(hudson.model.StringParameterDefinition) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) StringParameterValue(hudson.model.StringParameterValue) CauseAction(hudson.model.CauseAction) List(java.util.List) Run(hudson.model.Run) FreeStyleProject(hudson.model.FreeStyleProject) ParametersAction(hudson.model.ParametersAction) Test(org.junit.Test)

Example 49 with StringParameterDefinition

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));
}
Also used : ManualApproval(hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval) StringParameterDefinition(hudson.model.StringParameterDefinition) StringParameterValue(hudson.model.StringParameterValue) ParameterValue(hudson.model.ParameterValue) StringParameterValue(hudson.model.StringParameterValue) FreeStyleBuild(hudson.model.FreeStyleBuild) PromotedBuildAction(hudson.plugins.promoted_builds.PromotedBuildAction) FreeStyleProject(hudson.model.FreeStyleProject) JobPropertyImpl(hudson.plugins.promoted_builds.JobPropertyImpl) Promotion(hudson.plugins.promoted_builds.Promotion) PromotionProcess(hudson.plugins.promoted_builds.PromotionProcess) Descriptor(hudson.model.Descriptor) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 50 with StringParameterDefinition

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());
    }
}
Also used : StringParameterDefinition(hudson.model.StringParameterDefinition) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) ArrayList(java.util.ArrayList) FreeStyleBuild(hudson.model.FreeStyleBuild) Promotion(hudson.plugins.promoted_builds.Promotion) HtmlForm(com.gargoylesoftware.htmlunit.html.HtmlForm) PromotionProcess(hudson.plugins.promoted_builds.PromotionProcess) Status(hudson.plugins.promoted_builds.Status) ManualApproval(hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval) HtmlElement(com.gargoylesoftware.htmlunit.html.HtmlElement) PromotedBuildAction(hudson.plugins.promoted_builds.PromotedBuildAction) FreeStyleProject(hudson.model.FreeStyleProject) JobPropertyImpl(hudson.plugins.promoted_builds.JobPropertyImpl) Descriptor(hudson.model.Descriptor) ParameterDefinition(hudson.model.ParameterDefinition) StringParameterDefinition(hudson.model.StringParameterDefinition) Test(org.junit.Test)

Aggregations

StringParameterDefinition (hudson.model.StringParameterDefinition)95 ParametersDefinitionProperty (hudson.model.ParametersDefinitionProperty)82 Test (org.junit.Test)77 FreeStyleProject (hudson.model.FreeStyleProject)69 ParametersAction (hudson.model.ParametersAction)45 StringParameterValue (hudson.model.StringParameterValue)44 FreeStyleBuild (hudson.model.FreeStyleBuild)43 Issue (org.jvnet.hudson.test.Issue)26 ParameterDefinition (hudson.model.ParameterDefinition)24 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)16 FileWriteBuilder (hudson.plugins.copyartifact.testutils.FileWriteBuilder)15 ArtifactArchiver (hudson.tasks.ArtifactArchiver)15 Shell (hudson.tasks.Shell)15 Cause (hudson.model.Cause)12 ArrayList (java.util.ArrayList)11 CIMessageNotifier (com.redhat.jenkins.plugins.ci.CIMessageNotifier)10 CpsFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition)10 BooleanParameterDefinition (hudson.model.BooleanParameterDefinition)9 PromotionProcess (hudson.plugins.promoted_builds.PromotionProcess)9 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)9