Search in sources :

Example 6 with ParameterValue

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

the class Promotion method getParameterDefinitionsWithValue.

/**
 * Gets parameter definitions from the {@link ManualCondition}.
 * @return List of parameter definitions to be presented.
 *         May be empty if there is no {@link ManualCondition}.
 */
@Nonnull
public List<ParameterDefinition> getParameterDefinitionsWithValue() {
    List<ParameterDefinition> definitions = new ArrayList<ParameterDefinition>();
    ManualCondition manualCondition = (ManualCondition) getProject().getPromotionCondition(ManualCondition.class.getName());
    if (manualCondition == null) {
        return definitions;
    }
    for (ParameterValue pvalue : getParameterValues()) {
        ParameterDefinition pdef = manualCondition.getParameterDefinition(pvalue.getName());
        if (pdef == null) {
            // May happen only in the case of the wrong form submission
            continue;
        }
        definitions.add(pdef.copyWithDefaultValue(pvalue));
    }
    return definitions;
}
Also used : ManualCondition(hudson.plugins.promoted_builds.conditions.ManualCondition) ParameterValue(hudson.model.ParameterValue) ArrayList(java.util.ArrayList) ParameterDefinition(hudson.model.ParameterDefinition) Nonnull(javax.annotation.Nonnull)

Example 7 with ParameterValue

use of hudson.model.ParameterValue 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 8 with ParameterValue

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

the class ManualConditionInheritanceTest method testManualPromotionProcess.

@Test
public void testManualPromotionProcess() throws Exception {
    InheritanceProjectsPair inheritanceProjectsPair = j.createInheritanceProjectDerivedWithBase();
    ExtensionList<Descriptor> list = Jenkins.get().getExtensionList(Descriptor.class);
    list.add(new JobPropertyImpl.DescriptorImpl(JobPropertyImpl.class));
    JobPropertyImpl base = new JobPropertyImpl(inheritanceProjectsPair.getBase());
    inheritanceProjectsPair.getBase().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);
    InheritanceBuild b1 = j.assertBuildStatusSuccess(inheritanceProjectsPair.getDerived().scheduleBuild2(0));
    // promote a build
    List<ParameterValue> paramValues = condition.createDefaultValues();
    // try to add duplicate values
    paramValues.addAll(condition.createDefaultValues());
    // We cannot assume that the process will contain builds because the process added to base project is different to the one in derived.
    JobPropertyImpl jobProperty = inheritanceProjectsPair.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);
    assertNotNull("derived jobProperty is null", jobProperty);
    PromotionProcess fooDerived = jobProperty.getItem("foo");
    j.assertBuildStatusSuccess(condition.approve(b1, fooDerived, 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 : InheritanceProjectsPair(hudson.plugins.promoted_builds.inheritance.helpers.InheritanceProjectsPair) ManualApproval(hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval) InheritanceBuild(hudson.plugins.project_inheritance.projects.InheritanceBuild) StringParameterDefinition(hudson.model.StringParameterDefinition) ParameterValue(hudson.model.ParameterValue) PromotedBuildAction(hudson.plugins.promoted_builds.PromotedBuildAction) JobPropertyImpl(hudson.plugins.promoted_builds.JobPropertyImpl) ManualCondition(hudson.plugins.promoted_builds.conditions.ManualCondition) PromotionProcess(hudson.plugins.promoted_builds.PromotionProcess) Descriptor(hudson.model.Descriptor) Test(org.junit.Test)

Example 9 with ParameterValue

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

the class PromotionEnvironmentVariablesTest method shouldSetJobAndJobFullNames.

@Test
public void shouldSetJobAndJobFullNames() throws Descriptor.FormException, IOException, InterruptedException, ExecutionException, Exception {
    // Assemble
    r.jenkins.setSecurityRealm(r.createDummySecurityRealm());
    User u = User.get("foo");
    u.setFullName("Foobar");
    SecurityContextHolder.getContext().setAuthentication(u.impersonate());
    MockFolder parent = r.createFolder("Folder");
    FreeStyleProject project = parent.createProject(FreeStyleProject.class, "Project");
    JobPropertyImpl promotionProperty = new JobPropertyImpl(project);
    PromotionProcess promotionProcess = promotionProperty.addProcess("promo");
    promotionProcess.conditions.clear();
    promotionProcess.conditions.add(new ManualCondition());
    Action approvalAction = new ManualCondition.ManualApproval(promotionProcess.getName(), new ArrayList<ParameterValue>());
    // Act
    FreeStyleBuild build = project.scheduleBuild2(0).get();
    build.setDisplayName("1234");
    build.addAction(approvalAction);
    build.save();
    Promotion promotion = promotionProcess.considerPromotion2(build).get();
    EnvVars env = promotion.getEnvironment(TaskListener.NULL);
    // Assert
    assertEquals("Folder/Project", env.get("PROMOTED_JOB_FULL_NAME"));
    assertEquals("Project", env.get("PROMOTED_JOB_NAME"));
    assertEquals("Foobar", env.get("PROMOTED_USER_NAME"));
    assertEquals("foo", env.get("PROMOTED_USER_ID"));
    assertEquals("1234", env.get("PROMOTED_DISPLAY_NAME"));
    project.delete();
    parent.delete();
}
Also used : Action(hudson.model.Action) User(hudson.model.User) ParameterValue(hudson.model.ParameterValue) FreeStyleBuild(hudson.model.FreeStyleBuild) MockFolder(org.jvnet.hudson.test.MockFolder) FreeStyleProject(hudson.model.FreeStyleProject) ManualCondition(hudson.plugins.promoted_builds.conditions.ManualCondition) EnvVars(hudson.EnvVars) Test(org.junit.Test)

Example 10 with ParameterValue

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

the class PromotedEnvVarTokenMacroTest method testEnvironmentVariableExpansion.

@Test
public void testEnvironmentVariableExpansion() throws Exception {
    // Assemble
    r.jenkins.setSecurityRealm(r.createDummySecurityRealm());
    User u = User.get("foo");
    u.setFullName("Foobar");
    SecurityContextHolder.getContext().setAuthentication(u.impersonate());
    MockFolder parent = r.createFolder("Folder");
    FreeStyleProject project = parent.createProject(FreeStyleProject.class, "Project");
    JobPropertyImpl promotionProperty = new JobPropertyImpl(project);
    PromotionProcess promotionProcess = promotionProperty.addProcess("promo");
    promotionProcess.conditions.clear();
    ManualCondition manualCondition = new ManualCondition();
    manualCondition.getParameterDefinitions().add(new StringParameterDefinition("PROMOTION_PARAM", "defaultValue"));
    promotionProcess.conditions.add(manualCondition);
    Action approvalAction = new ManualCondition.ManualApproval(promotionProcess.getName(), new LinkedList<ParameterValue>());
    TokenMacroExpressionRecorder recorder = new TokenMacroExpressionRecorder("${PROMOTION_ENV,var=\"PROMOTION_PARAM\"}");
    promotionProcess.getBuildSteps().add(recorder);
    // Act & promote
    FreeStyleBuild build = project.scheduleBuild2(0).get();
    build.addAction(approvalAction);
    build.save();
    Promotion promotion = promotionProcess.considerPromotion2(build, Arrays.asList((ParameterValue) new StringParameterValue("PROMOTION_PARAM", "FOO"))).get();
    // Check results
    EnvVars env = promotion.getEnvironment(TaskListener.NULL);
    assertEquals("The PROMOTION_PARAM variable has not been injected", "FOO", env.get("PROMOTION_PARAM"));
    assertEquals("The promotion variable value has not been resolved by the PROMOTION_PARAM macro", "FOO", recorder.getCaptured());
}
Also used : Action(hudson.model.Action) User(hudson.model.User) StringParameterDefinition(hudson.model.StringParameterDefinition) StringParameterValue(hudson.model.StringParameterValue) ParameterValue(hudson.model.ParameterValue) StringParameterValue(hudson.model.StringParameterValue) FreeStyleBuild(hudson.model.FreeStyleBuild) MockFolder(org.jvnet.hudson.test.MockFolder) FreeStyleProject(hudson.model.FreeStyleProject) JobPropertyImpl(hudson.plugins.promoted_builds.JobPropertyImpl) Promotion(hudson.plugins.promoted_builds.Promotion) ManualCondition(hudson.plugins.promoted_builds.conditions.ManualCondition) EnvVars(hudson.EnvVars) PromotionProcess(hudson.plugins.promoted_builds.PromotionProcess) Test(org.junit.Test)

Aggregations

ParameterValue (hudson.model.ParameterValue)20 ParameterDefinition (hudson.model.ParameterDefinition)9 ManualCondition (hudson.plugins.promoted_builds.conditions.ManualCondition)7 ArrayList (java.util.ArrayList)7 ParametersAction (hudson.model.ParametersAction)6 StringParameterValue (hudson.model.StringParameterValue)6 Test (org.junit.Test)6 FreeStyleBuild (hudson.model.FreeStyleBuild)5 FreeStyleProject (hudson.model.FreeStyleProject)5 ParametersDefinitionProperty (hudson.model.ParametersDefinitionProperty)5 ManualApproval (hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval)5 EnvVars (hudson.EnvVars)4 StringParameterDefinition (hudson.model.StringParameterDefinition)4 JobPropertyImpl (hudson.plugins.promoted_builds.JobPropertyImpl)4 PromotionProcess (hudson.plugins.promoted_builds.PromotionProcess)4 JSONObject (net.sf.json.JSONObject)4 Action (hudson.model.Action)3 Descriptor (hudson.model.Descriptor)3 PromotedBuildAction (hudson.plugins.promoted_builds.PromotedBuildAction)3 JSONArray (net.sf.json.JSONArray)3