Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-4949] Add ability to deploy to multiple containers
Change allows multiple deployment targets to be specified through
job configuration screen.
  • Loading branch information
Brandon Munroe committed Nov 2, 2012
1 parent df3cb7b commit 1fe03c8
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 26 deletions.
17 changes: 17 additions & 0 deletions src/main/java/hudson/plugins/deploy/ContainerAdapterWrapper.java
@@ -0,0 +1,17 @@
package hudson.plugins.deploy;

import org.kohsuke.stapler.DataBoundConstructor;

/**
* A wrapper for a single {@link ContainerAdapter}
*
* @author Brandon Munroe
*/
public class ContainerAdapterWrapper {
public final ContainerAdapter adapter;

@DataBoundConstructor
public ContainerAdapterWrapper(ContainerAdapter adapter) {
this.adapter = adapter;
}
}
36 changes: 29 additions & 7 deletions src/main/java/hudson/plugins/deploy/DeployPublisher.java
Expand Up @@ -26,15 +26,17 @@
* @author Kohsuke Kawaguchi
*/
public class DeployPublisher extends Notifier implements Serializable {
public final ContainerAdapter adapter;
private List<ContainerAdapterWrapper> adapterWrappers;
public final String contextPath;

public final String war;
public final boolean onFailure;


public final ContainerAdapter adapter = null;

@DataBoundConstructor
public DeployPublisher(ContainerAdapter adapter, String war, String contextPath, boolean onFailure) {
this.adapter = adapter;
public DeployPublisher(List<ContainerAdapterWrapper> adapterWrappers, String war, String contextPath, boolean onFailure, ContainerAdapter adapter) {
this.adapterWrappers = adapterWrappers;
this.war = war;
this.onFailure = onFailure;
this.contextPath = contextPath;
Expand All @@ -44,8 +46,9 @@ public DeployPublisher(ContainerAdapter adapter, String war, String contextPath,
public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
if (build.getResult().equals(Result.SUCCESS) || onFailure) {
for (FilePath warFile : build.getWorkspace().list(this.war)) {
if(!adapter.redeploy(warFile,contextPath,build,launcher,listener))
build.setResult(Result.FAILURE);
for(ContainerAdapterWrapper wrapper : adapterWrappers)
if(!wrapper.adapter.redeploy(warFile,contextPath,build,launcher,listener))
build.setResult(Result.FAILURE);
}
}

Expand All @@ -55,8 +58,27 @@ public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListene
public BuildStepMonitor getRequiredMonitorService() {
return BuildStepMonitor.BUILD;
}

public Object readResolve() {
if(adapter != null) {
if(adapterWrappers == null) {
adapterWrappers = new ArrayList<ContainerAdapterWrapper>();
}
adapterWrappers.add(new ContainerAdapterWrapper(adapter));
}
return this;
}

/**
* Get the value of the adapterWrappers property
*
* @return The value of adapterWrappers
*/
public List<ContainerAdapterWrapper> getAdapterWrappers() {
return adapterWrappers;
}

@Extension
@Extension
public static final class DescriptorImpl extends BuildStepDescriptor<Publisher> {
public boolean isApplicable(Class<? extends AbstractProject> jobType) {
return true;
Expand Down
Expand Up @@ -6,25 +6,34 @@
<f:entry title="${%Context path}" field="contextPath">
<f:textbox />
</f:entry>

<f:dropdownList name="adapter" title="${%Container}">
<j:forEach var="d" items="${descriptor.containerAdapters}" varStatus="loop">
<f:dropdownListBlock value="${d.clazz.name}" title="${d.displayName}" selected="${instance.adapter.descriptor==d}">
<f:nested>
<table width="100%">
<tr><td>
<input type="hidden" name="stapler-class" value="${d.clazz.name}" />
</td></tr>
<j:scope>
<j:set var="descriptor" value="${d}"/>
<j:set var="instance" value="${h.ifThenElse(instance.adapter.descriptor==descriptor, instance.adapter, null)}"/>
<st:include class="${descriptor.clazz}" page="config.jelly"/>
</j:scope>
</table>
</f:nested>
</f:dropdownListBlock>
</j:forEach>
</f:dropdownList>

<f:entry title="${%Containers}" field="adapters">
<f:repeatable var="wrapper" items="${instance.adapterWrappers}" name="adapterWrappers" miniumum="1" noAddButton="false">
<table width="100%">
<f:dropdownList name="adapter" title="${%Container}">
<j:forEach var="d" items="${descriptor.containerAdapters}" varStatus="loop">
<f:dropdownListBlock value="${d.clazz.name}" title="${d.displayName}" selected="${wrapper.adapter.descriptor==d}">
<f:nested>
<table width="100%">
<tr><td>
<input type="hidden" name="stapler-class" value="${d.clazz.name}" />
</td></tr>
<j:scope>
<j:set var="descriptor" value="${d}"/>
<j:set var="instance" value="${h.ifThenElse(wrapper.adapter.descriptor==descriptor, wrapper.adapter, null)}"/>
<st:include class="${descriptor.clazz}" page="config.jelly"/>
</j:scope>
</table>
<div align="right">
<f:repeatableDeleteButton value="${%Delete Container}"/>
</div>
</f:nested>
</f:dropdownListBlock>
</j:forEach>
</f:dropdownList>
</table>
</f:repeatable>
</f:entry>

<f:entry title="${%Deploy on failure}" field="onFailure">
<f:checkbox />
Expand Down

0 comments on commit 1fe03c8

Please sign in to comment.