Search in sources :

Example 16 with ParametersDefinitionProperty

use of hudson.model.ParametersDefinitionProperty in project workflow-cps-plugin by jenkinsci.

the class ParamsVariableTest method smokes.

@Issue("JENKINS-27295")
@Test
public void smokes() throws Exception {
    WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
    p.setDefinition(new CpsFlowDefinition("echo(/TEXT=${params.TEXT} FLAG=${params.FLAG ? 'yes' : 'no'} PASS=${params.PASS}/)", true));
    p.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("TEXT", ""), new BooleanParameterDefinition("FLAG", false, null), new PasswordParameterDefinition("PASS", "", null)));
    WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0, new ParametersAction(new StringParameterValue("TEXT", "hello"), new BooleanParameterValue("FLAG", true), new PasswordParameterValue("PASS", "s3cr3t"))));
    r.assertLogContains("TEXT=hello", b);
    r.assertLogContains("FLAG=yes", b);
    r.assertLogContains("PASS=s3cr3t", b);
}
Also used : StringParameterDefinition(hudson.model.StringParameterDefinition) BooleanParameterDefinition(hudson.model.BooleanParameterDefinition) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) BooleanParameterValue(hudson.model.BooleanParameterValue) PasswordParameterDefinition(hudson.model.PasswordParameterDefinition) StringParameterValue(hudson.model.StringParameterValue) PasswordParameterValue(hudson.model.PasswordParameterValue) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) ParametersAction(hudson.model.ParametersAction) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 17 with ParametersDefinitionProperty

use of hudson.model.ParametersDefinitionProperty in project workflow-cps-plugin by jenkinsci.

the class ParamsVariableTest method nullValue.

@Issue("JENKINS-42367")
@Test
public void nullValue() throws Exception {
    WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
    p.setDefinition(new CpsFlowDefinition("echo(/TEXT=${params.TEXT}/)", true));
    p.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("TEXT", "")));
    r.assertLogContains("TEXT=null", r.assertBuildStatusSuccess(p.scheduleBuild2(0, new ParametersAction(new StringParameterValue("TEXT", /* not possible via UI, but to simulate other ParameterValue impls */
    null)))));
}
Also used : StringParameterDefinition(hudson.model.StringParameterDefinition) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) StringParameterValue(hudson.model.StringParameterValue) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) ParametersAction(hudson.model.ParametersAction) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 18 with ParametersDefinitionProperty

use of hudson.model.ParametersDefinitionProperty in project workflow-cps-plugin by jenkinsci.

the class SnippetizerTest method generateSnippetForBuildTrigger.

@Issue("JENKINS-26093")
@Test
public void generateSnippetForBuildTrigger() throws Exception {
    MockFolder d1 = r.createFolder("d1");
    FreeStyleProject ds = d1.createProject(FreeStyleProject.class, "ds");
    MockFolder d2 = r.createFolder("d2");
    // Really this would be a WorkflowJob, but we cannot depend on that here, and it should not matter since we are just looking for Job:
    FreeStyleProject us = d2.createProject(FreeStyleProject.class, "us");
    ds.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("key", ""), new BooleanParameterDefinition("flag", false, "")));
    String snippet;
    if (StringParameterDefinition.DescriptorImpl.class.isAnnotationPresent(Symbol.class)) {
        snippet = "build job: '../d1/ds', parameters: [string(name: 'key', value: 'stuff'), booleanParam(name: 'flag', value: true)]";
    } else {
        // TODO 2.x delete
        snippet = "build job: '../d1/ds', parameters: [[$class: 'StringParameterValue', name: 'key', value: 'stuff'], [$class: 'BooleanParameterValue', name: 'flag', value: true]]";
    }
    st.assertGenerateSnippet("{'stapler-class':'" + BuildTriggerStep.class.getName() + "', 'job':'../d1/ds', 'parameter': [{'name':'key', 'value':'stuff'}, {'name':'flag', 'value':true}]}", snippet, us.getAbsoluteUrl() + "configure");
}
Also used : StringParameterDefinition(hudson.model.StringParameterDefinition) BooleanParameterDefinition(hudson.model.BooleanParameterDefinition) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) MockFolder(org.jvnet.hudson.test.MockFolder) FreeStyleProject(hudson.model.FreeStyleProject) BuildTriggerStep(org.jenkinsci.plugins.workflow.support.steps.build.BuildTriggerStep) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 19 with ParametersDefinitionProperty

use of hudson.model.ParametersDefinitionProperty in project promoted-builds-plugin by jenkinsci.

the class PromotionProcess method getDefaultParameterValuesAsEnvVars.

private static EnvVars getDefaultParameterValuesAsEnvVars(AbstractProject owner) {
    EnvVars envVars = null;
    ParametersDefinitionProperty parametersDefinitionProperty = (ParametersDefinitionProperty) owner.getProperty(ParametersDefinitionProperty.class);
    if (parametersDefinitionProperty != null) {
        envVars = new EnvVars();
        for (ParameterDefinition parameterDefinition : parametersDefinitionProperty.getParameterDefinitions()) {
            ParameterValue defaultParameterValue = parameterDefinition.getDefaultParameterValue();
            if (defaultParameterValue != null) {
                if (defaultParameterValue instanceof StringParameterValue) {
                    envVars.put(parameterDefinition.getName(), (String) defaultParameterValue.getValue());
                }
            }
        }
        EnvVars.resolve(envVars);
    }
    return envVars;
}
Also used : EnvVars(hudson.EnvVars) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) StringParameterValue(hudson.model.StringParameterValue) ParameterValue(hudson.model.ParameterValue) StringParameterValue(hudson.model.StringParameterValue) ParameterDefinition(hudson.model.ParameterDefinition)

Example 20 with ParametersDefinitionProperty

use of hudson.model.ParametersDefinitionProperty in project promoted-builds-plugin by jenkinsci.

the class PromotionProcessTest method testIsVisibleResolvesDefaultParameterValue.

@Test
public void testIsVisibleResolvesDefaultParameterValue() throws Exception {
    FreeStyleProject project = j.createFreeStyleProject("project");
    final List<ParameterDefinition> parameters = new ArrayList<ParameterDefinition>();
    ParametersDefinitionProperty parametersProperty = new ParametersDefinitionProperty(parameters);
    parameters.add(new StringParameterDefinition("Visibility", "false"));
    project.addProperty(parametersProperty);
    JobPropertyImpl jobProperty = new JobPropertyImpl(project);
    project.addProperty(jobProperty);
    PromotionProcess promotionProcess = jobProperty.addProcess("Promotion");
    promotionProcess.isVisible = "${Visibility}";
    assertFalse(promotionProcess.isVisible());
}
Also used : StringParameterDefinition(hudson.model.StringParameterDefinition) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) ArrayList(java.util.ArrayList) FreeStyleProject(hudson.model.FreeStyleProject) ParameterDefinition(hudson.model.ParameterDefinition) StringParameterDefinition(hudson.model.StringParameterDefinition) Test(org.junit.Test)

Aggregations

ParametersDefinitionProperty (hudson.model.ParametersDefinitionProperty)21 Test (org.junit.Test)13 StringParameterDefinition (hudson.model.StringParameterDefinition)12 ParameterDefinition (hudson.model.ParameterDefinition)11 FreeStyleProject (hudson.model.FreeStyleProject)9 ParametersAction (hudson.model.ParametersAction)8 StringParameterValue (hudson.model.StringParameterValue)8 Issue (org.jvnet.hudson.test.Issue)7 ArrayList (java.util.ArrayList)6 ParameterValue (hudson.model.ParameterValue)5 BooleanParameterDefinition (hudson.model.BooleanParameterDefinition)4 ImmutableList (com.google.common.collect.ImmutableList)3 Shell (hudson.tasks.Shell)3 List (java.util.List)3 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 FreeStyleBuild (hudson.model.FreeStyleBuild)2 JobPropertyImpl (hudson.plugins.promoted_builds.JobPropertyImpl)2 Promotion (hudson.plugins.promoted_builds.Promotion)2 PromotionProcess (hudson.plugins.promoted_builds.PromotionProcess)2