Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-15920] Add boolean parameter option
Add a parameter item to allow boolean parameters
to be passed to down stream jobs
  • Loading branch information
cjo9900 committed Jan 16, 2013
1 parent 70aa20b commit 0a66eca
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 0 deletions.
@@ -0,0 +1,66 @@
/*
* The MIT License
*
* Copyright (c) 2013, Chris Johnson
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package hudson.plugins.parameterizedtrigger;

import hudson.Extension;
import hudson.model.Describable;
import hudson.model.Descriptor;
import hudson.model.Hudson;
import org.kohsuke.stapler.DataBoundConstructor;

/**
*
* @author Chris Johnson
*/
public class BooleanParameterConfig implements Describable<BooleanParameterConfig>{

private final String name;
private final boolean value;

@DataBoundConstructor
public BooleanParameterConfig(String name, boolean value) {
this.name = name;
this.value = value;
}
public boolean getValue() {
return value;
}

public String getName() {
return name;
}

public Descriptor<BooleanParameterConfig> getDescriptor() {
return Hudson.getInstance().getDescriptorOrDie(getClass());
}


@Extension
public static class DescriptorImpl extends Descriptor<BooleanParameterConfig> {
@Override
public String getDisplayName() {
return ""; // unused
}
}
}
@@ -0,0 +1,74 @@
/*
* The MIT License
*
* Copyright (c) 2013, Chris Johnson
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package hudson.plugins.parameterizedtrigger;

import hudson.Extension;
import hudson.model.AbstractBuild;
import hudson.model.Action;
import hudson.model.BooleanParameterValue;
import hudson.model.Descriptor;
import hudson.model.ParameterValue;
import hudson.model.ParametersAction;
import hudson.model.TaskListener;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.kohsuke.stapler.DataBoundConstructor;

/**
*
* @author Chris Johnson
*/
public class BooleanParameters extends AbstractBuildParameters {

private List<BooleanParameterConfig> configs;

@DataBoundConstructor
public BooleanParameters(List <BooleanParameterConfig> configs ){
this.configs = configs;
}

@Override
public Action getAction(AbstractBuild<?, ?> build, TaskListener listener) throws IOException, InterruptedException, DontTriggerException {

List<ParameterValue> values = new ArrayList<ParameterValue>();
for (BooleanParameterConfig config : configs) {
values.add(new BooleanParameterValue(config.getName(), config.getValue()));
}
return new ParametersAction(values);
}

public List<BooleanParameterConfig> getConfigs() {
return configs;
}

@Extension
public static class DescriptorImpl extends Descriptor<AbstractBuildParameters> {
@Override
public String getDisplayName() {
return "Boolean parameters";
}

}
}
@@ -0,0 +1,8 @@
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<f:entry field="name" title="${%Name}">
<f:textbox />
</f:entry>
<f:entry field="value">
<f:booleanRadio true="${%True}" false="${%False}"/>
</f:entry>
</j:jelly>
@@ -0,0 +1,16 @@
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<f:entry title="" field="configs">
<f:repeatable field="configs" noAddButton="true" minimum="1">
<j:set var="instance" value="${instance.descriptor!=descriptor?null:instance}"/><!-- work around until 1.382 -->
<table width="100%">
<st:include class="${descriptor.clazz}" page="config.jelly" />
<f:entry>
<div align="right">
<input type="button" value="${%Add parameter...}" class="repeatable-add show-if-last" />
<input type="button" value="${%Delete}" class="repeatable-delete show-if-not-only" style="margin-left: 1em;" />
</div>
</f:entry>
</table>
</f:repeatable>
</f:entry>
</j:jelly>
@@ -0,0 +1,3 @@
<div>
This passes Boolean parameters to the downstream jobs
</div>

0 comments on commit 0a66eca

Please sign in to comment.