Search in sources :

Example 1 with StringParameterDefinition

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

the class SnippetizerTest method generateSnippetForBuildTriggerSingle.

@Issue("JENKINS-29739")
@Test
public void generateSnippetForBuildTriggerSingle() throws Exception {
    FreeStyleProject ds = r.jenkins.createProject(FreeStyleProject.class, "ds1");
    FreeStyleProject us = r.jenkins.createProject(FreeStyleProject.class, "us1");
    ds.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("key", "")));
    String snippet;
    if (StringParameterDefinition.DescriptorImpl.class.isAnnotationPresent(Symbol.class)) {
        snippet = "build job: 'ds1', parameters: [string(name: 'key', value: 'stuff')]";
    } else {
        // TODO 2.x delete
        snippet = "build job: 'ds1', parameters: [[$class: 'StringParameterValue', name: 'key', value: 'stuff']]";
    }
    st.assertGenerateSnippet("{'stapler-class':'" + BuildTriggerStep.class.getName() + "', 'job':'ds1', 'parameter': {'name':'key', 'value':'stuff'}}", snippet, us.getAbsoluteUrl() + "configure");
}
Also used : StringParameterDefinition(hudson.model.StringParameterDefinition) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) FreeStyleProject(hudson.model.FreeStyleProject) BuildTriggerStep(org.jenkinsci.plugins.workflow.support.steps.build.BuildTriggerStep) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 2 with StringParameterDefinition

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

the class CpsScmFlowDefinitionTest method usingParameter.

@Issue("JENKINS-28447")
@Test
public void usingParameter() throws Exception {
    sampleRepo.init();
    sampleRepo.write("flow.groovy", "echo 'version one'");
    sampleRepo.git("add", "flow.groovy");
    sampleRepo.git("commit", "--message=one");
    sampleRepo.git("tag", "one");
    sampleRepo.write("flow.groovy", "echo 'version two'");
    sampleRepo.git("commit", "--all", "--message=two");
    WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
    CpsScmFlowDefinition def = new CpsScmFlowDefinition(new GitSCM(Collections.singletonList(new UserRemoteConfig(sampleRepo.fileUrl(), null, null, null)), Collections.singletonList(new BranchSpec("${VERSION}")), false, Collections.<SubmoduleConfig>emptyList(), null, null, Collections.<GitSCMExtension>emptyList()), "flow.groovy");
    // TODO SCMFileSystem.of cannot pick up build parameters
    def.setLightweight(false);
    p.setDefinition(def);
    p.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("VERSION", "master")));
    r.assertLogContains("version two", r.assertBuildStatusSuccess(p.scheduleBuild2(0)));
    r.assertLogContains("version one", r.assertBuildStatusSuccess(p.scheduleBuild2(0, new ParametersAction(new StringParameterValue("VERSION", "one")))));
}
Also used : StringParameterDefinition(hudson.model.StringParameterDefinition) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) BranchSpec(hudson.plugins.git.BranchSpec) StringParameterValue(hudson.model.StringParameterValue) SubmoduleConfig(hudson.plugins.git.SubmoduleConfig) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) ParametersAction(hudson.model.ParametersAction) GitSCM(hudson.plugins.git.GitSCM) UserRemoteConfig(hudson.plugins.git.UserRemoteConfig) GitSCMExtension(hudson.plugins.git.extensions.GitSCMExtension) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 3 with StringParameterDefinition

use of hudson.model.StringParameterDefinition 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 4 with StringParameterDefinition

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

the class ManualConditionTest method testManualPromotionProcess.

@Test
public void testManualPromotionProcess() 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));
    // promote a build
    List<ParameterValue> paramValues = condition.createDefaultValues();
    // try to add duplicate values
    paramValues.addAll(condition.createDefaultValues());
    j.assertBuildStatusSuccess(condition.approve(b1, foo, paramValues));
    ManualApproval manualApproval = b1.getAction(ManualApproval.class);
    assertNotNull(manualApproval);
    PromotedBuildAction statuses = b1.getAction(PromotedBuildAction.class);
    assertNotNull(statuses);
    assertNotNull(statuses.getPromotions());
    assertFalse(statuses.getPromotions().isEmpty());
}
Also used : ManualApproval(hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval) StringParameterDefinition(hudson.model.StringParameterDefinition) StringParameterValue(hudson.model.StringParameterValue) ParameterValue(hudson.model.ParameterValue) FreeStyleBuild(hudson.model.FreeStyleBuild) PromotedBuildAction(hudson.plugins.promoted_builds.PromotedBuildAction) FreeStyleProject(hudson.model.FreeStyleProject) JobPropertyImpl(hudson.plugins.promoted_builds.JobPropertyImpl) PromotionProcess(hudson.plugins.promoted_builds.PromotionProcess) Descriptor(hudson.model.Descriptor) Test(org.junit.Test)

Example 5 with StringParameterDefinition

use of hudson.model.StringParameterDefinition 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)

Aggregations

StringParameterDefinition (hudson.model.StringParameterDefinition)19 Test (org.junit.Test)18 FreeStyleProject (hudson.model.FreeStyleProject)12 ParametersDefinitionProperty (hudson.model.ParametersDefinitionProperty)12 StringParameterValue (hudson.model.StringParameterValue)9 PromotionProcess (hudson.plugins.promoted_builds.PromotionProcess)9 JobPropertyImpl (hudson.plugins.promoted_builds.JobPropertyImpl)8 Issue (org.jvnet.hudson.test.Issue)8 FreeStyleBuild (hudson.model.FreeStyleBuild)6 ParametersAction (hudson.model.ParametersAction)6 Promotion (hudson.plugins.promoted_builds.Promotion)6 Descriptor (hudson.model.Descriptor)5 ParameterDefinition (hudson.model.ParameterDefinition)5 PromotedBuildAction (hudson.plugins.promoted_builds.PromotedBuildAction)5 ManualApproval (hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval)5 ParameterValue (hudson.model.ParameterValue)4 ArrayList (java.util.ArrayList)4 BooleanParameterDefinition (hudson.model.BooleanParameterDefinition)3 ManualCondition (hudson.plugins.promoted_builds.conditions.ManualCondition)3 InheritanceProjectsPair (hudson.plugins.promoted_builds.inheritance.helpers.InheritanceProjectsPair)3