use of hudson.model.ParametersAction in project hudson-2.x by hudson.
the class BuildCommand method run.
protected int run() throws Exception {
job.checkPermission(Item.BUILD);
ParametersAction a = null;
if (!parameters.isEmpty()) {
ParametersDefinitionProperty pdp = job.getProperty(ParametersDefinitionProperty.class);
if (pdp == null)
throw new AbortException(job.getFullDisplayName() + " is not parameterized but the -p option was specified");
List<ParameterValue> values = new ArrayList<ParameterValue>();
for (Entry<String, String> e : parameters.entrySet()) {
String name = e.getKey();
ParameterDefinition pd = pdp.getParameterDefinition(name);
if (pd == null)
throw new AbortException(String.format("\'%s\' is not a valid parameter. Did you mean %s?", name, EditDistance.findNearest(name, pdp.getParameterDefinitionNames())));
values.add(pd.createValue(this, e.getValue()));
}
for (ParameterDefinition pd : pdp.getParameterDefinitions()) {
if (parameters.get(pd.getName()) == null) {
values.add(pd.getDefaultParameterValue());
}
}
a = new ParametersAction(values);
}
Future<? extends AbstractBuild> f = job.scheduleBuild2(0, new CLICause(), a);
if (!sync)
return 0;
// wait for the completion
AbstractBuild b = f.get();
stdout.println("Completed " + b.getFullDisplayName() + " : " + b.getResult());
return b.getResult().ordinal;
}
use of hudson.model.ParametersAction in project blueocean-plugin by jenkinsci.
the class RunContainerImpl method create.
/**
* Schedules a build. If build already exists in the queue and the pipeline does not
* support running multiple builds at the same time, return a reference to the existing
* build.
*
* @return Queue item.
*/
@Override
public BlueQueueItem create(StaplerRequest request) {
job.checkPermission(Item.BUILD);
if (job instanceof Queue.Task) {
ScheduleResult scheduleResult;
List<ParameterValue> parameterValues = getParameterValue(request);
int expectedBuildNumber = job.getNextBuildNumber();
if (parameterValues.size() > 0) {
scheduleResult = Jenkins.getInstance().getQueue().schedule2((Queue.Task) job, 0, new ParametersAction(parameterValues), new CauseAction(new Cause.UserIdCause()));
} else {
scheduleResult = Jenkins.getInstance().getQueue().schedule2((Queue.Task) job, 0, new CauseAction(new Cause.UserIdCause()));
}
if (scheduleResult.isAccepted()) {
final Queue.Item item = scheduleResult.getItem();
return new QueueItemImpl(item, job.getName(), expectedBuildNumber, pipeline.getLink().rel("queue").rel(Long.toString(item.getId())), pipeline.getLink());
} else {
throw new ServiceException.UnexpectedErrorException("Queue item request was not accepted");
}
} else {
throw new ServiceException.NotImplementedException("This pipeline type does not support being queued.");
}
}
use of hudson.model.ParametersAction in project promoted-builds-plugin by jenkinsci.
the class Promotion method getParameterValues.
public List<ParameterValue> getParameterValues() {
List<ParameterValue> values = new ArrayList<ParameterValue>();
ParametersAction parametersAction = getParametersActions(this);
if (parametersAction != null) {
ManualCondition manualCondition = (ManualCondition) getProject().getPromotionCondition(ManualCondition.class.getName());
if (manualCondition != null) {
for (ParameterValue pvalue : parametersAction.getParameters()) {
if (manualCondition.getParameterDefinition(pvalue.getName()) != null) {
values.add(pvalue);
}
}
}
return values;
}
//fallback to badge lookup for compatibility
for (PromotionBadge badget : getStatus().getBadges()) {
if (badget instanceof ManualCondition.Badge) {
return ((ManualCondition.Badge) badget).getParameterValues();
}
}
return Collections.emptyList();
}
use of hudson.model.ParametersAction in project promoted-builds-plugin by jenkinsci.
the class SelfPromotionInheritanceTest method testPromotionEnvironmentShouldIncludeTargetParameters.
@Test
@Bug(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));
}
use of hudson.model.ParametersAction in project promoted-builds-plugin by jenkinsci.
the class SelfPromotionTest method testPromotionEnvironmentShouldIncludeTargetParameters.
@Bug(22679)
public // @Bug(34826) // Can be reproduced in Jenkins 2.3 +
void testPromotionEnvironmentShouldIncludeTargetParameters() throws Exception {
String paramName = "param";
FreeStyleProject p = createFreeStyleProject();
p.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition(paramName, "")));
// promote if the downstream passes
JobPropertyImpl promotion = new JobPropertyImpl(p);
p.addProperty(promotion);
PromotionProcess promo1 = promotion.addProcess("promo1");
promo1.conditions.add(new SelfPromotionCondition(false));
// ensure that the data survives the roundtrip
configRoundtrip(p);
// rebind
promotion = p.getProperty(JobPropertyImpl.class);
promo1 = promotion.getItem("promo1");
String paramValue = "someString";
FreeStyleBuild b = assertBuildStatusSuccess(p.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.
Thread.sleep(1000);
// 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));
}
Aggregations