Search in sources :

Example 6 with ParametersDefinitionProperty

use of hudson.model.ParametersDefinitionProperty in project selenium_java by sergueik.

the class WhenSchedulingJob method testParameterisedJobShouldSaveAllParameters.

@Test
public void testParameterisedJobShouldSaveAllParameters() throws Exception {
    final FreeStyleProject project = createFreeStyleProject("ParameterisedJob");
    // set parameters
    final ParameterDefinition param1 = new StringParameterDefinition("myStringParam", "myStringValue", "My String Parameter");
    final ParameterDefinition param2 = new BooleanParameterDefinition("myBooleanParam", false, "My Boolean Parameter");
    project.addProperty(new ParametersDefinitionProperty(param1, param2));
    // enable audit2db plugin
    final DbAuditPublisher plugin = getPlugin();
    project.getPublishersList().add((Publisher) plugin);
    // build now
    final Future<FreeStyleBuild> futureBuild = project.scheduleBuild2(0);
    final FreeStyleBuild build = futureBuild.get();
    Assert.assertNotNull(build);
    Assert.assertEquals("Unexpected build result", Result.SUCCESS, build.getResult());
    // check data persistence
    final BuildDetailsRepository repository = plugin.getRepository();
    final BuildDetails actual = repository.getBuildDetailsForBuild(build);
    final BuildDetails expected = new BuildDetailsImpl(build);
    Assert.assertEquals("Unexpected build details", expected, actual);
    Assert.assertNotNull("Unexpected null end date", actual.getEndDate());
    Assert.assertTrue("Unexpected duration", actual.getDuration() > 0L);
    Assert.assertEquals("Unexpected number of params", 2, actual.getParameters().size());
}
Also used : BuildDetailsImpl(org.jenkins.plugins.audit2db.internal.model.BuildDetailsImpl) StringParameterDefinition(hudson.model.StringParameterDefinition) BooleanParameterDefinition(hudson.model.BooleanParameterDefinition) BuildDetails(org.jenkins.plugins.audit2db.model.BuildDetails) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) BuildDetailsRepository(org.jenkins.plugins.audit2db.data.BuildDetailsRepository) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject) BooleanParameterDefinition(hudson.model.BooleanParameterDefinition) StringParameterDefinition(hudson.model.StringParameterDefinition) ParameterDefinition(hudson.model.ParameterDefinition) DbAuditPublisher(org.jenkins.plugins.audit2db.DbAuditPublisher) Test(org.junit.Test)

Example 7 with ParametersDefinitionProperty

use of hudson.model.ParametersDefinitionProperty in project generic-webhook-trigger-plugin by jenkinsci.

the class GenericTrigger method addAllParametersFromParameterizedJob.

/**
 * To keep any default values set there.
 */
private void addAllParametersFromParameterizedJob(final Job<?, ?> job, final List<StringParameterValue> parameterList) {
    final ParametersDefinitionProperty parametersDefinitionProperty = job.getProperty(ParametersDefinitionProperty.class);
    if (parametersDefinitionProperty != null) {
        for (final ParameterDefinition parameterDefinition : parametersDefinitionProperty.getParameterDefinitions()) {
            final String param = parameterDefinition.getName();
            final ParameterValue defaultParameterValue = parameterDefinition.getDefaultParameterValue();
            if (defaultParameterValue != null) {
                final String value = defaultParameterValue.getValue().toString();
                if (!isNullOrEmpty(value)) {
                    final StringParameterValue parameter = new StringParameterValue(param, value);
                    parameterList.add(parameter);
                }
            }
        }
    }
}
Also used : ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) StringParameterValue(hudson.model.StringParameterValue) ParameterValue(hudson.model.ParameterValue) StringParameterValue(hudson.model.StringParameterValue) ParameterDefinition(hudson.model.ParameterDefinition)

Example 8 with ParametersDefinitionProperty

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

the class SelfPromotionInheritanceTest method testPromotionEnvironmentShouldIncludeTargetParameters.

@Test
@Issue("JENKINS-22679")
public void testPromotionEnvironmentShouldIncludeTargetParameters() throws Exception {
    String paramName = "param";
    InheritanceProjectsPair inheritanceProjectPair = j.createInheritanceProjectDerivedWithBase();
    // promote if the downstream passes
    JobPropertyImpl promotion = new JobPropertyImpl(inheritanceProjectPair.getBase());
    inheritanceProjectPair.getBase().addProperty(promotion);
    // TODO review this property asignment after https://issues.jenkins-ci.org/browse/JENKINS-34831 is fixed
    inheritanceProjectPair.getBase().addProperty(new ParametersDefinitionProperty(new StringParameterDefinition(paramName, "")));
    inheritanceProjectPair.getDerived().addProperty(new ParametersDefinitionProperty(new StringParameterDefinition(paramName, "")));
    PromotionProcess promo1 = promotion.addProcess("promo1");
    promo1.conditions.add(new SelfPromotionCondition(false));
    // fire ItemListeners, this includes ArtifactArchiver,Migrator to make this test compatible with jenkins 1.575+
    fireItemListeners();
    String paramValue = "someString";
    j.assertBuildStatusSuccess(inheritanceProjectPair.getDerived().scheduleBuild2(0, new Cause.UserCause(), new ParametersAction(new StringParameterValue(paramName, paramValue))));
    // internally, the promotion is still an asynchronous process. It just happens
    // right away after the build is complete.
    j.waitUntilNoActivity();
    // rebind
    promotion = inheritanceProjectPair.getDerived().getProperty(JobPropertyImpl.class, /*Forcing inheritance as temporary hack for inheritance plugin 1.53 
                because that version of the plugin uses inheritance only for certain predefined cases: 
                -specific methods on the call stack
                -url paths.
                This has been changed as pull request https://github.com/i-m-c/jenkins-inheritance-plugin/pull/40
               */
    IMode.INHERIT_FORCED);
    promo1 = promotion.getItem("promo1");
    // verify that the promotion's environment contains the parameter from the target build.
    Promotion pb = promo1.getBuildByNumber(1);
    assertEquals(paramValue, pb.getEnvironment(TaskListener.NULL).get(paramName, null));
}
Also used : InheritanceProjectsPair(hudson.plugins.promoted_builds.inheritance.helpers.InheritanceProjectsPair) StringParameterDefinition(hudson.model.StringParameterDefinition) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) PromotionProcess(hudson.plugins.promoted_builds.PromotionProcess) StringParameterValue(hudson.model.StringParameterValue) SelfPromotionCondition(hudson.plugins.promoted_builds.conditions.SelfPromotionCondition) JobPropertyImpl(hudson.plugins.promoted_builds.JobPropertyImpl) Promotion(hudson.plugins.promoted_builds.Promotion) ParametersAction(hudson.model.ParametersAction) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 9 with ParametersDefinitionProperty

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

the class PromotionProcessTest method testIsVisibleResolvesDefaultParameterValueIndirectly.

@Test
public void testIsVisibleResolvesDefaultParameterValueIndirectly() throws Exception {
    FreeStyleProject project = j.createFreeStyleProject("project");
    final List<ParameterDefinition> parameters = new ArrayList<ParameterDefinition>();
    ParametersDefinitionProperty parametersProperty = new ParametersDefinitionProperty(parameters);
    parameters.add(new StringParameterDefinition("IndirectVisibility", "false"));
    parameters.add(new StringParameterDefinition("Visibility", "${IndirectVisibility}"));
    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)

Example 10 with ParametersDefinitionProperty

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

the class AbstractPipelineImpl method getParameterDefinitions.

public static List<Object> getParameterDefinitions(Job job) {
    ParametersDefinitionProperty pp = (ParametersDefinitionProperty) job.getProperty(ParametersDefinitionProperty.class);
    List<Object> pds = new ArrayList<>();
    if (pp != null) {
        for (ParameterDefinition pd : pp.getParameterDefinitions()) {
            pds.add(pd);
        }
    }
    return pds;
}
Also used : ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) ArrayList(java.util.ArrayList) ParameterDefinition(hudson.model.ParameterDefinition)

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