hudson.model.StringParameterValue Java Examples

The following examples show how to use hudson.model.StringParameterValue. 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 File: PipelineApiTest.java    From blueocean-plugin with 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 File: GithubWebhook.java    From DotCi with MIT License 6 votes vote down vote up
private List<ParameterValue> getParametersValues(final Job job, final String branch) {
    final ParametersDefinitionProperty paramDefProp = (ParametersDefinitionProperty) job.getProperty(ParametersDefinitionProperty.class);
    final ArrayList<ParameterValue> defValues = new ArrayList<>();

    for (final ParameterDefinition paramDefinition : paramDefProp.getParameterDefinitions()) {
        if ("BRANCH".equals(paramDefinition.getName())) {
            final StringParameterValue branchParam = new StringParameterValue("BRANCH", branch);
            defValues.add(branchParam);
        } else {
            final ParameterValue defaultValue = paramDefinition.getDefaultParameterValue();
            if (defaultValue != null)
                defValues.add(defaultValue);
        }
    }

    return defValues;
}
 
Example #3
Source File: GithubWebhookTest.java    From DotCi with MIT License 6 votes vote down vote up
@Test
public void should_trigger_build_with_default_parameter_values() throws IOException, InterruptedException {
    final StaplerRequest request = mock(StaplerRequest.class);
    when(request.getParameter("payload")).thenReturn("payload");
    final DynamicProject project = mock(DynamicProject.class);

    final ParameterDefinition branchParameter = mock(ParameterDefinition.class);
    when(branchParameter.getName()).thenReturn("BRANCH");

    final ParameterDefinition secondParameter = mock(ParameterDefinition.class);
    when(branchParameter.getName()).thenReturn("PARAM");
    when(secondParameter.getDefaultParameterValue()).thenReturn(new StringParameterValue("PARAM", "meow"));
    final ParametersDefinitionProperty paramDefinition = mock(ParametersDefinitionProperty.class);
    when(paramDefinition.getParameterDefinitions()).thenReturn(Arrays.asList(branchParameter, secondParameter));
    when(project.getProperty(ParametersDefinitionProperty.class)).thenReturn(paramDefinition);

    kickOffBuildTrigger(request, project);

    final ArgumentCaptor<ParametersAction> parametersCaptor = ArgumentCaptor.forClass(ParametersAction.class);
    verify(project).scheduleBuild(eq(0), any(GithubPushPullWebhookCause.class), parametersCaptor.capture());

    final ParametersAction parametersAction = parametersCaptor.getValue();
    Assert.assertTrue(parametersAction.getParameter("PARAM") instanceof StringParameterValue);
    Assert.assertEquals("meow", ((StringParameterValue) parametersAction.getParameter("PARAM")).value);

}
 
Example #4
Source File: JobRunnerForCauseTest.java    From github-integration-plugin with MIT License 5 votes vote down vote up
public static QueueTaskFuture schedule(Job<?, ?> job, int number, String param, int queuetPeriod) {
    ParameterizedJobMixIn jobMixIn = JobInfoHelpers.asParameterizedJobMixIn(job);
    GitHubPRCause cause = newGitHubPRCause().withNumber(number);
    ParametersAction parametersAction = new ParametersAction(
            Collections.<ParameterValue>singletonList(new StringParameterValue("value", param))
    );
    return jobMixIn.scheduleBuild2(queuetPeriod, new CauseAction(cause), parametersAction);
}
 
Example #5
Source File: DeflakeAction.java    From flaky-test-handler-plugin with Apache License 2.0 5 votes vote down vote up
private static ParameterValue getStringParam(JSONObject formData, String paramName) {
  JSONObject paramObj = JSONObject.fromObject(formData.get(paramName));
  String name = paramObj.getString("name");
  FlakyTestResultAction.logger.log(Level.FINE,
      "Param: " + name + " with value: " + paramObj.getString("value"));
  return new StringParameterValue(name, paramObj.getString("value"));
}
 
Example #6
Source File: NoteBuildActionTest.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void build_alreadyBuiltMR_alreadyBuiltMR() throws IOException, ExecutionException, InterruptedException {
    FreeStyleProject testProject = jenkins.createFreeStyleProject();
    testProject.addTrigger(trigger);
    testProject.setScm(new GitSCM(gitRepoUrl));
    QueueTaskFuture<?> future = testProject.scheduleBuild2(0, new ParametersAction(new StringParameterValue("gitlabTargetBranch", "master")));
    future.get();

    exception.expect(HttpResponses.HttpResponseException.class);
    new NoteBuildAction(testProject, getJson("NoteEvent_alreadyBuiltMR.json"), null).execute(response);

    verify(trigger).onPost(any(NoteHook.class));
}
 
Example #7
Source File: DownstreamJobPlugin.java    From DotCi with MIT License 5 votes vote down vote up
private NoDuplicatesParameterAction getParamsAction(Map<String, String> jobParams) {
    List<ParameterValue> params = new ArrayList<ParameterValue>();
    for (Map.Entry<String, String> entry : jobParams.entrySet()) {
        params.add(new StringParameterValue(entry.getKey(), entry.getValue()));
    }

    return new NoDuplicatesParameterAction(params);
}
 
Example #8
Source File: PipelineApiTest.java    From blueocean-plugin with MIT License 4 votes vote down vote up
@Override
public StringParameterValue getDefaultParameterValue() {
    return null;
}
 
Example #9
Source File: AutoResubmitIntegrationTest.java    From ec2-spot-jenkins-plugin with Apache License 2.0 4 votes vote down vote up
@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 = {CopyOnWriteArrayList@14845}  size = 2
        0 = {ParametersAction@14853}
        safeParameters = {TreeSet@14855}  size = 0
        parameters = {ArrayList@14856}  size = 1
        0 = {StringParameterValue@14862} "(StringParameterValue) number='1'"
        value = "1"
        name = "number"
        description = ""
        parameterDefinitionNames = {ArrayList@14857}  size = 1
        0 = "number"
        build = null
        run = {FreeStyleBuild@14834} "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);
}
 
Example #10
Source File: GitHubEnv.java    From github-integration-plugin with MIT License 4 votes vote down vote up
default ParameterValue param(String value) {
    return new StringParameterValue(toString(), escapeJava(trimToEmpty(value)));
}
 
Example #11
Source File: DashboardView.java    From jenkins-deployment-dashboard-plugin with MIT License 4 votes vote down vote up
@JavaScriptMethod
public String deploy(String version, String environment) {
    LOGGER.info("Deploy version " + version + " to environment " + environment);

    // Get the environment with corresponding build-job
    Environment buildEnvironment = null;
    for (Environment env : environments) {
        if (env.getAwsInstance().equals(environment)) {
            buildEnvironment = env;
            break;
        }
    }

    final AbstractProject buildJob = Jenkins.getInstance().getItemByFullName(buildEnvironment.getBuildJob(), AbstractProject.class);
    LOGGER.info("Executing job: " + buildJob);

    if (buildJob == null) {
        return String.format(Messages.DashboardView_buildJobNotFound(), buildEnvironment.getName());
    }

    if ((!buildJob.isBuildable()) || (!buildJob.isParameterized())) {
        return Messages.DashboardView_deploymentCannotBeExecuted();
    }

    final ParametersAction versionParam = new ParametersAction(new StringParameterValue(PARAM_VERSION, version));
    final ParametersAction environmentParam = new ParametersAction(new StringParameterValue(PARAM_ENVIRONMENT, environment));
    final ParametersAction ec2RegionParam = new ParametersAction(new StringParameterValue(PARAM_EC2_REGION, environment));
    final ParametersAction awsKeyParam = new ParametersAction(new StringParameterValue(PARAM_AWS_KEY, environment));

    List<ParametersAction> actions = Arrays.asList(versionParam, environmentParam, ec2RegionParam, awsKeyParam);
    QueueTaskFuture<AbstractBuild> scheduledBuild = buildJob.scheduleBuild2(2, new Cause.UserIdCause(), actions);

    Result result = Result.FAILURE;
    try {
        AbstractBuild finishedBuild = scheduledBuild.get();
        result = finishedBuild.getResult();
        LOGGER.info("Build finished with result: " + result + " completed in: " + finishedBuild.getDurationString() + ". ");
    } catch (Exception e) {
        LOGGER.severe("Error while waiting for build " + scheduledBuild.toString() + ".");
        LOGGER.severe(e.getMessage());
        LOGGER.severe(ExceptionUtils.getFullStackTrace(e));
        return String.format(Messages.DashboardView_buildJobFailed(), buildJob.getName());
    }
    if (result == Result.SUCCESS) {
        return String.format(Messages.DashboardView_buildJobScheduledSuccessfully(), buildJob.getName());
    }
    return String.format(Messages.DashboardView_buildJobSchedulingFailed(), buildJob.getName());
}
 
Example #12
Source File: ResourceVariableNameAction.java    From lockable-resources-plugin with MIT License 4 votes vote down vote up
public ResourceVariableNameAction(StringParameterValue r) {
	this.resourceNameParameter = r;
}
 
Example #13
Source File: ResourceVariableNameAction.java    From lockable-resources-plugin with MIT License 4 votes vote down vote up
StringParameterValue getParameter() {
	return resourceNameParameter;
}
 
Example #14
Source File: LockRunListener.java    From lockable-resources-plugin with MIT License 4 votes vote down vote up
@Override
public void onStarted(Run<?, ?> build, TaskListener listener) {
	// Skip locking for multiple configuration projects,
	// only the child jobs will actually lock resources.
	if (build instanceof MatrixBuild)
		return;

	if (build instanceof AbstractBuild) {
		Job<?, ?> proj = Utils.getProject(build);
		Set<LockableResource> required = new HashSet<>();
		if (proj != null) {
			LockableResourcesStruct resources = Utils.requiredResources(proj);

			if (resources != null) {
				if (resources.requiredNumber != null || !resources.label.isEmpty() || resources.getResourceMatchScript() != null) {
					required.addAll(LockableResourcesManager.get().
							getResourcesFromProject(proj.getFullName()));
				} else {
					required.addAll(resources.required);
				}

				if (LockableResourcesManager.get().lock(required, build, null)) {
					build.addAction(LockedResourcesBuildAction
							.fromResources(required));
					listener.getLogger().printf("%s acquired lock on %s%n",
							LOG_PREFIX, required);
					LOGGER.fine(build.getFullDisplayName()
							+ " acquired lock on " + required);
					if (resources.requiredVar != null) {
						build.addAction(new ResourceVariableNameAction(new StringParameterValue(
								resources.requiredVar,
								required.toString().replaceAll("[\\]\\[]", ""))));
					}
				} else {
					listener.getLogger().printf("%s failed to lock %s%n",
							LOG_PREFIX, required);
					LOGGER.fine(build.getFullDisplayName() + " failed to lock "
							+ required);
				}
			}
		}
	}
}