Java Code Examples for hudson.model.StringParameterDefinition

The following examples show how to use hudson.model.StringParameterDefinition. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: blueocean-plugin   Source File: PipelineApiTest.java    License: MIT License 6 votes vote down vote up
@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.getInstance().getQueue().schedule(p1, 0, new ParametersAction(new StringParameterValue("test","test1")), new CauseAction(new Cause.UserIdCause()));
    Jenkins.getInstance().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")));
    assertNull(r); //its not moved out of queue yet
}
 
Example 2
Source Project: blueocean-plugin   Source File: PipelineApiTest.java    License: MIT License 6 votes vote down vote up
@Test
public void parameterizedFreestyleTest() throws Exception {
    FreeStyleProject p = j.createFreeStyleProject("pp");
    p.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("version", "1.0", "version number")));
    p.getBuildersList().add(new Shell("echo hello!"));

    Map resp = get("/organizations/jenkins/pipelines/pp/");

    List<Map<String,Object>> parameters = (List<Map<String, Object>>) resp.get("parameters");
    assertEquals(1, parameters.size());
    assertEquals("version", parameters.get(0).get("name"));
    assertEquals("StringParameterDefinition", parameters.get(0).get("type"));
    assertEquals("version number", parameters.get(0).get("description"));
    assertEquals("1.0", ((Map)parameters.get(0).get("defaultParameterValue")).get("value"));
    validatePipeline(p, resp);

    resp = post("/organizations/jenkins/pipelines/pp/runs/",
            ImmutableMap.of("parameters",
                    ImmutableList.of(ImmutableMap.of("name", "version", "value", "2.0"))
            ), 200);
    assertEquals("pp", resp.get("pipeline"));
    Thread.sleep(1000);
    resp = get("/organizations/jenkins/pipelines/pp/runs/1/");
    assertEquals("SUCCESS", resp.get("result"));
    assertEquals("FINISHED", resp.get("state"));
}
 
Example 3
@Test
public void should_successfully_resubmit_parametrized_task() throws Exception {
    EC2FleetCloud cloud = new EC2FleetCloud(null, null, "credId", null, "region",
            null, "fId", "momo", null, new LocalComputerConnector(j), false, false,
            0, 0, 10, 1, false, false,
            false, 0, 0, false,
            10, false);
    j.jenkins.clouds.add(cloud);

    List<QueueTaskFuture> rs = new ArrayList<>();
    final FreeStyleProject project = j.createFreeStyleProject();
    project.setAssignedLabel(new LabelAtom("momo"));
    project.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("number", "opa")));
    /*
    example of actions for project

    actions = {[email protected]}  size = 2
        0 = {[email protected]}
        safeParameters = {[email protected]}  size = 0
        parameters = {[email protected]}  size = 1
        0 = {[email protected]} "(StringParameterValue) number='1'"
        value = "1"
        name = "number"
        description = ""
        parameterDefinitionNames = {[email protected]}  size = 1
        0 = "number"
        build = null
        run = {[email protected]} "parameter #14"
     */
    project.getBuildersList().add(Functions.isWindows() ? new BatchFile("Ping -n %number% 127.0.0.1 > nul") : new Shell("sleep ${number}"));

    rs.add(project.scheduleBuild2(0, new ParametersAction(new StringParameterValue("number", "30"))));

    System.out.println("check if zero nodes!");
    Assert.assertEquals(0, j.jenkins.getNodes().size());

    assertAtLeastOneNode();

    final Node node = j.jenkins.getNodes().get(0);
    assertQueueIsEmpty();

    System.out.println("disconnect node");
    node.toComputer().disconnect(new OfflineCause.ChannelTermination(new UnsupportedOperationException("Test")));

    assertLastBuildResult(Result.FAILURE, Result.ABORTED);

    node.toComputer().connect(true);
    assertNodeIsOnline(node);
    assertQueueAndNodesIdle(node);

    Assert.assertEquals(1, j.jenkins.getProjects().size());
    Assert.assertEquals(Result.SUCCESS, j.jenkins.getProjects().get(0).getLastBuild().getResult());
    Assert.assertEquals(2, j.jenkins.getProjects().get(0).getBuilds().size());

    cancelTasks(rs);
}