Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #2 from rseguy/master
Implemented JENKINS-9705: Allow overriding build parameters in release build
  • Loading branch information
petehayes committed Sep 13, 2011
2 parents 1f54949 + bdc0080 commit 48576c5
Show file tree
Hide file tree
Showing 6 changed files with 222 additions and 53 deletions.
119 changes: 96 additions & 23 deletions src/main/java/hudson/plugins/release/ReleaseWrapper.java
@@ -1,3 +1,27 @@
/*
* The MIT License
*
* Copyright (c) 2009-2011, Peter Hayes, Manufacture Francaise des Pneumatiques Michelin,
* Romain Seguy
*
* 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.release;

import hudson.EnvVars;
Expand Down Expand Up @@ -57,11 +81,12 @@
* @since 1.0
*/
public class ReleaseWrapper extends BuildWrapper {
private static final String DEFAULT_RELEASE_VERSION_TEMPLATE = "Release #$RELEASE_VERSION";
private static final String DEFAULT_RELEASE_VERSION_TEMPLATE = "Release #$RELEASE_VERSION";

private String releaseVersionTemplate;
private String releaseVersionTemplate;
private boolean doNotKeepLog;
private List<ParameterDefinition> parameterDefinitions = new ArrayList<ParameterDefinition>();
private boolean overrideBuildParameters;
private List<ParameterDefinition> parameterDefinitions = new ArrayList<ParameterDefinition>();
private List<Builder> preBuildSteps = new ArrayList<Builder>();
private List<Builder> postBuildSteps = new ArrayList<Builder>();
private List<Builder> postSuccessfulBuildSteps = new ArrayList<Builder>();
Expand Down Expand Up @@ -118,12 +143,12 @@ public ReleaseWrapper() {
}

public String getReleaseVersionTemplate() {
return releaseVersionTemplate;
}
return releaseVersionTemplate;
}

public void setReleaseVersionTemplate(String releaseVersionTemplate) {
this.releaseVersionTemplate = releaseVersionTemplate;
}
this.releaseVersionTemplate = releaseVersionTemplate;
}

public boolean isDoNotKeepLog() {
return doNotKeepLog;
Expand All @@ -132,14 +157,22 @@ public boolean isDoNotKeepLog() {
public void setDoNotKeepLog(boolean doNotKeepLog) {
this.doNotKeepLog = doNotKeepLog;
}

public boolean isOverrideBuildParameters() {
return overrideBuildParameters;
}

public void setOverrideBuildParameters(boolean overrideBuildParameters) {
this.overrideBuildParameters = overrideBuildParameters;
}

public List<ParameterDefinition> getParameterDefinitions() {
return parameterDefinitions;
}
return parameterDefinitions;
}

public void setParameterDefinitions(List<ParameterDefinition> parameterDefinitions) {
this.parameterDefinitions = parameterDefinitions;
}
this.parameterDefinitions = parameterDefinitions;
}

/**
* @return Returns the preBuildSteps.
Expand Down Expand Up @@ -197,7 +230,7 @@ public Environment setUp(AbstractBuild build, final Launcher launcher, BuildList
final ReleaseBuildBadgeAction releaseBuildBadge = build.getAction(ReleaseBuildBadgeAction.class);

if (releaseBuildBadge == null) {
return new Environment() { };
return new Environment() { };
}

// Set the release version now by resolving build parameters against build and release version template
Expand Down Expand Up @@ -337,6 +370,7 @@ public BuildWrapper newInstance(StaplerRequest req, JSONObject formData) throws
ReleaseWrapper instance = new ReleaseWrapper();
instance.releaseVersionTemplate = formData.getString("releaseVersionTemplate");
instance.doNotKeepLog = formData.getBoolean("doNotKeepLog");
instance.overrideBuildParameters = formData.getBoolean("overrideBuildParameters");
instance.parameterDefinitions = Descriptor.newInstancesFromHeteroList(req, formData, "parameters", ParameterDefinition.all());
instance.preBuildSteps = Descriptor.newInstancesFromHeteroList(req, formData, "preBuildSteps", Builder.all());
instance.postBuildSteps = Descriptor.newInstancesFromHeteroList(req, formData, "postBuildSteps", Builder.all());
Expand Down Expand Up @@ -364,6 +398,14 @@ public List<ParameterDefinition> getParameterDefinitions() {
return parameterDefinitions;
}

public List<ParameterDefinition> getBuildParameterDefinitions() {
ParametersDefinitionProperty paramsDefProp = (ParametersDefinitionProperty) project.getProperty(ParametersDefinitionProperty.class);
if (paramsDefProp != null) {
return paramsDefProp.getParameterDefinitions();
}
return null;
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -444,16 +486,35 @@ public void setDevelopmentVersion(String developmentVersion) {
}

/**
* Gets the {@link ParameterDefinition} of the given name, if any.
* Gets the {@link ParameterDefinition} of the given name, including
* the ones from the build parameters, if any.
*/
public ParameterDefinition getParameterDefinition(String name) {
if (parameterDefinitions == null) {
ParametersDefinitionProperty buildParamsDefProp = (ParametersDefinitionProperty) project.getProperty(ParametersDefinitionProperty.class);
List<ParameterDefinition> buildParameterDefinitions = null;
if (buildParamsDefProp != null) {
buildParameterDefinitions = buildParamsDefProp.getParameterDefinitions();
}

if (!overrideBuildParameters && parameterDefinitions == null
|| overrideBuildParameters && parameterDefinitions == null && buildParameterDefinitions == null) {
return null;
}
for (ParameterDefinition pd : parameterDefinitions)
if (pd.getName().equals(name))

for (ParameterDefinition pd : parameterDefinitions) {
if (pd.getName().equals(name)) {
return pd;
}
}

if (overrideBuildParameters) {
for (ParameterDefinition pd : buildParameterDefinitions) {
if (pd.getName().equals(name)) {
return pd;
}
}
}

return null;
}

Expand All @@ -471,8 +532,7 @@ private List<ParameterValue> getDefaultParametersValues() {
return defValues;

/* Scan for all parameter with an associated default values */
for(ParameterDefinition paramDefinition : paramDefProp.getParameterDefinitions())
{
for(ParameterDefinition paramDefinition : paramDefProp.getParameterDefinitions()) {
ParameterValue defaultValue = paramDefinition.getDefaultParameterValue();

if(defaultValue != null)
Expand All @@ -482,6 +542,10 @@ private List<ParameterValue> getDefaultParametersValues() {
return defValues;
}

public boolean isOverrideBuildParameters() {
return overrideBuildParameters;
}

public void doSubmit(StaplerRequest req, StaplerResponse resp) throws IOException, ServletException {
// verify permission
ReleaseWrapper.checkReleasePermission(project);
Expand All @@ -490,17 +554,26 @@ public void doSubmit(StaplerRequest req, StaplerResponse resp) throws IOExceptio
req.bindParameters(this);

// create parameter list
List<ParameterValue> paramValues = getDefaultParametersValues();
List<ParameterValue> paramValues;
if (isOverrideBuildParameters()) {
// if overrideBuildParameters is set, then build params are submitted
// within the list of release params -- no need to gather default values
paramValues = new ArrayList<ParameterValue>();
}
else {
paramValues = getDefaultParametersValues();
}

if (getParameterDefinitions() != null && !getParameterDefinitions().isEmpty()) {
if (getParameterDefinitions() != null && !getParameterDefinitions().isEmpty()
|| overrideBuildParameters && getBuildParameterDefinitions() != null && !getBuildParameterDefinitions().isEmpty()) {
JSONObject formData = req.getSubmittedForm();

JSONArray a = JSONArray.fromObject(formData.get("parameter"));

for (Object o : a) {
JSONObject jo = (JSONObject) o;
String name = jo.getString("name");

ParameterDefinition d = getParameterDefinition(name);
if(d==null)
throw new IllegalArgumentException("No such parameter definition: " + name);
Expand Down
@@ -1,3 +1,28 @@
<!--
- The MIT License
-
- Copyright (c) 2009-2011, Peter Hayes, Manufacture Francaise des Pneumatiques Michelin,
- Romain Seguy
-
- 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.
-->

<!--
Displays the form to choose the tag name.
Expand All @@ -10,22 +35,29 @@
<table width="100%">
<tr><td>
<f:form method="post" action="submit">
<j:if test="${it.overrideBuildParameters and !it.buildParameterDefinitions.isEmpty()}">
<f:section title="${%Override build parameters}">
<j:forEach var="buildParameterDefinition" items="${it.buildParameterDefinitions}">
<st:include it="${buildParameterDefinition}" page="${buildParameterDefinition.descriptor.valuePage}" />
</j:forEach>
</f:section>
</j:if>
<f:section title="${%Define release}">
<j:if test="${it.parameterDefinitions == null || it.parameterDefinitions.isEmpty()}">
Please configure your specific release parameters in the project config page as these
hard coded parameters will be removed in a future release.
<f:entry title="${%Release version}" help="/plugin/release/help-releaseVersion.html">
<f:textbox name="releaseVersion" value="${it.releaseVersion}" />
</f:entry>
<f:entry title="${%Next development version}" help="/plugin/release/help-developmentVersion.html">
<f:textbox name="developmentVersion" value="${it.developmentVersion}" />
</f:entry>
</j:if>
<j:if test="${!it.parameterDefinitions.isEmpty()}">
<j:forEach var="parameterDefinition" items="${it.parameterDefinitions}">
<st:include it="${parameterDefinition}" page="${parameterDefinition.descriptor.valuePage}" />
</j:forEach>
</j:if>
<j:if test="${it.parameterDefinitions == null || it.parameterDefinitions.isEmpty()}">
Please configure your specific release parameters in the project config page as these
hard coded parameters will be removed in a future release.
<f:entry title="${%Release version}" help="/plugin/release/help-releaseVersion.html">
<f:textbox name="releaseVersion" value="${it.releaseVersion}" />
</f:entry>
<f:entry title="${%Next development version}" help="/plugin/release/help-developmentVersion.html">
<f:textbox name="developmentVersion" value="${it.developmentVersion}" />
</f:entry>
</j:if>
<j:if test="${!it.parameterDefinitions.isEmpty()}">
<j:forEach var="parameterDefinition" items="${it.parameterDefinitions}">
<st:include it="${parameterDefinition}" page="${parameterDefinition.descriptor.valuePage}" />
</j:forEach>
</j:if>
<tr><td colspan="3"><f:submit value="${%Schedule Release Build}"/></td></tr>
</f:section>
</f:form>
Expand Down
@@ -1,6 +1,7 @@
# The MIT License
#
# Copyright (c) 2004-2010, Sun Microsystems, Inc.
# Copyright (c) 2004-2011, Sun Microsystems, Inc., Manufacture Francaise des Pneumatiques Michelin,
# Romain Seguy
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand All @@ -20,6 +21,8 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

Next\ development\ version=Prochaine version de d\u00E9veloppement
Release\ version=Version de la distribution
Schedule\ Release\ Build=Programmer Build de Release
Next\ development\ version=Prochaine version de d\u00e9veloppement
Release\ version=Version de la release
Schedule\ Release\ Build=Programmer le build de la release
Override\ build\ parameters=Surcharge des param\u00e8tres du build
Define\ release=D\u00e9finition de la release
@@ -1,14 +1,43 @@
<!--
- The MIT License
-
- Copyright (c) 2009-2011, Peter Hayes, Manufacture Francaise des Pneumatiques Michelin,
- Romain Seguy
-
- 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.
-->

<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"
xmlns:p="/lib/hudson/project">
xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form"
xmlns:p="/lib/hudson/project">

<f:entry title="${%Release Version Template}" help="/plugin/release/help-releaseVersionTemplate.html">
<f:textbox field="releaseVersionTemplate" />
</f:entry>
<f:textbox field="releaseVersionTemplate" />
</f:entry>

<f:entry title="${%Do not mark build as keep forever}" help="/plugin/release/help-doNotKeepLog.html">
<f:checkbox name="doNotKeepLog" field="doNotKeepLog" />
</f:entry>
<f:checkbox name="doNotKeepLog" field="doNotKeepLog" />
</f:entry>

<f:entry title="${%Override build parameters}" help="/plugin/release/help-overrideBuildParameters.html">
<f:checkbox name="overrideBuildParameters" field="overrideBuildParameters" />
</f:entry>

<f:block>

Expand Down
@@ -1,6 +1,7 @@
# The MIT License
#
# Copyright (c) 2004-2010, Sun Microsystems, Inc.
# Copyright (c) 2004-2011, Sun Microsystems, Inc., Manufacture Francaise des Pneumatiques Michelin,
# Romain Seguy
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand All @@ -20,8 +21,9 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

Add\ Parameter=Ajouter un param\u00E8tre
Add\ release\ step=Ajouter une \u00E9tape de distribution
Add\ Parameter=Ajouter un param\u00e8tre
Add\ release\ step=Ajouter une \u00e9tape de distribution
Before\ release\ build=Avant le build de distribution
Override\ build\ parameters=Surcharger les param\u00e8tres du build
Release\ Version\ Template=Template de version de distribution
Release\ parameters=Param\u00E8tres de la distribution
Release\ parameters=Param\u00e8tres de la distribution

0 comments on commit 48576c5

Please sign in to comment.