Skip to content

Commit

Permalink
[FIXED JENKINS-10006] Parameterized publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
bap2000 committed Jul 8, 2011
1 parent ed86e14 commit fbd378f
Show file tree
Hide file tree
Showing 12 changed files with 252 additions and 9 deletions.
Expand Up @@ -50,8 +50,9 @@ public class CifsBuilderPlugin extends Builder {

@DataBoundConstructor
public CifsBuilderPlugin(final ArrayList<CifsPublisher> publishers, final boolean continueOnError, final boolean failOnError,
final boolean alwaysPublishFromMaster, final String masterNodeName) {
this.delegate = new CifsPublisherPlugin(publishers, continueOnError, failOnError, alwaysPublishFromMaster, masterNodeName);
final boolean alwaysPublishFromMaster, final String masterNodeName, final CifsParamPublish paramPublish) {
this.delegate = new CifsPublisherPlugin(publishers, continueOnError, failOnError, alwaysPublishFromMaster, masterNodeName,
paramPublish);
}

@Override
Expand Down
@@ -0,0 +1,56 @@
/*
* The MIT License
*
* Copyright (C) 2010-2011 by Anthony Robinson
*
* 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 jenkins.plugins.publish_over_cifs;

import jenkins.plugins.publish_over.ParamPublish;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.kohsuke.stapler.DataBoundConstructor;

public class CifsParamPublish extends ParamPublish {

@DataBoundConstructor
public CifsParamPublish(final String parameterName) {
super(parameterName);
}

public boolean equals(final Object that) {
if (this == that) return true;
if (that == null || getClass() != that.getClass()) return false;

return addToEquals(new EqualsBuilder(), (CifsParamPublish) that).isEquals();
}

public int hashCode() {
return addToHashCode(new HashCodeBuilder()).toHashCode();
}

public String toString() {
return addToToString(new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)).toString();
}

}
Expand Up @@ -52,8 +52,10 @@ public class CifsPromotionPublisherPlugin extends Notifier {

@DataBoundConstructor
public CifsPromotionPublisherPlugin(final ArrayList<CifsPublisher> publishers, final boolean continueOnError,
final boolean failOnError, final boolean alwaysPublishFromMaster, final String masterNodeName) {
this.delegate = new CifsPublisherPlugin(publishers, continueOnError, failOnError, alwaysPublishFromMaster, masterNodeName);
final boolean failOnError, final boolean alwaysPublishFromMaster, final String masterNodeName,
final CifsParamPublish paramPublish) {
this.delegate = new CifsPublisherPlugin(publishers, continueOnError, failOnError, alwaysPublishFromMaster, masterNodeName,
paramPublish);
}

public BPInstanceConfig getInstanceConfig() {
Expand Down
Expand Up @@ -45,8 +45,9 @@ public class CifsPublisher extends BapPublisher<CifsTransfer> {

@DataBoundConstructor
public CifsPublisher(final String configName, final boolean verbose, final ArrayList<CifsTransfer> transfers,
final boolean useWorkspaceInPromotion, final boolean usePromotionTimestamp, final CifsRetry retry) {
super(configName, verbose, transfers, useWorkspaceInPromotion, usePromotionTimestamp, retry);
final boolean useWorkspaceInPromotion, final boolean usePromotionTimestamp, final CifsRetry retry,
final CifsPublisherLabel label) {
super(configName, verbose, transfers, useWorkspaceInPromotion, usePromotionTimestamp, retry, label);
}

@Override
Expand Down
@@ -0,0 +1,56 @@
/*
* The MIT License
*
* Copyright (C) 2010-2011 by Anthony Robinson
*
* 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 jenkins.plugins.publish_over_cifs;

import jenkins.plugins.publish_over.PublisherLabel;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.kohsuke.stapler.DataBoundConstructor;

public class CifsPublisherLabel extends PublisherLabel {

@DataBoundConstructor
public CifsPublisherLabel(final String label) {
super(label);
}

public boolean equals(final Object that) {
if (this == that) return true;
if (that == null || getClass() != that.getClass()) return false;

return addToEquals(new EqualsBuilder(), (CifsPublisherLabel) that).isEquals();
}

public int hashCode() {
return addToHashCode(new HashCodeBuilder()).toHashCode();
}

public String toString() {
return addToToString(new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)).toString();
}

}
Expand Up @@ -48,8 +48,9 @@ public class CifsPublisherPlugin extends BPPlugin<CifsPublisher, CifsClient, Obj

@DataBoundConstructor
public CifsPublisherPlugin(final ArrayList<CifsPublisher> publishers, final boolean continueOnError, final boolean failOnError,
final boolean alwaysPublishFromMaster, final String masterNodeName) {
super(Messages.console_message_prefix(), publishers, continueOnError, failOnError, alwaysPublishFromMaster, masterNodeName);
final boolean alwaysPublishFromMaster, final String masterNodeName, final CifsParamPublish paramPublish) {
super(Messages.console_message_prefix(), publishers, continueOnError, failOnError, alwaysPublishFromMaster, masterNodeName,
paramPublish);
}

@Override
Expand Down
Expand Up @@ -72,6 +72,11 @@
<f:textbox name="retryDelay" value="${publisher.retry.retryDelay}" default="${descriptor.publisherDescriptor.defaultRetryDelay}" checkUrl="${descriptor.publisherDescriptor.getCheckUrl('retryDelay')}"/>
</f:entry>
</f:optionalBlock>
<f:optionalBlock title="${%publisherLabel.title}" name="label" checked="${publisher.label != null}" help="${helpUrl}label.html">
<f:entry title="${%label.title}" help="${helpUrl}label.html">
<f:textbox name="label" value="${publisher.label.label}"/>
</f:entry>
</f:optionalBlock>
</f:advanced>

<f:entry title="${%transfers.section}" help="${helpUrl}transfers.html">
Expand Down Expand Up @@ -151,6 +156,11 @@
default="${descriptor.publisherDescriptor.defaultMasterNodeName}"/>
</f:entry>
</j:if>
<f:optionalBlock title="${%paramPublish.title}" name="paramPublish" checked="${instance.instanceConfig.paramPublish != null}" help="${descriptor.publisherDescriptor.getHelpFile('paramPublish')}">
<f:entry title="${%parameterName.title}" help="${helpUrl}parameterName.html">
<f:textbox name="parameterName" value="${instance.instanceConfig.paramPublish.parameterName}"/>
</f:entry>
</f:optionalBlock>
</f:advanced>

</f:entry>
Expand Down
Expand Up @@ -52,3 +52,7 @@ usePromotionTimestamp.title=Use promotion timestamp
retries.title=Retries
retryDelay.title=Delay
retry.title=Retry
publisherLabel.title=Label
label.title=Label
paramPublish.title=Parameterized publishing
parameterName.title=Parameter name
@@ -0,0 +1,56 @@
<!--
~ The MIT License
~
~ Copyright (C) 2010-2011 by Anthony Robinson
~
~ 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">
<div>
<p>Publish to shares by matching labels against a regular expression provided by a parameter or an environment variable.</p>
<br />
<p>For each share instance the label will be matched against the expression, and if matched, the publish will continue, otherwise that share will be skipped.<br />
<br />
If a label is not set for a share instance it will default to the empty string. Configured labels have whitespace removed from the start and end of them, which means that an all whitespace label will be evaluated as an empty string.<br />
<br />
The same label can be used multiple times, e.g. UAT for a database server and again for the web server.<br />
<br />
The regular expression syntax is the <a href="http://download.oracle.com/javase/1.5.0/docs/api/index.html?java/util/regex/Pattern.html" target="_blank">java syntax</a>.<br />
<br />
The labels can use the standard <a href="${rootURL}/env-vars.html" target="_blank">Jenkins environment variables</a> e.g. $NODE_NAME, or build variables such as a matrix axis.
</p>
<br />
<p>
Some simple examples follow:<br />
<br />
<strong>[AC]</strong> will match <strong>A</strong> and <strong>C</strong>, but not <strong>B</strong> or <strong>D</strong><br />
<em>There appears to be an issue with strings which begin and end with brackets which will cause the string <strong>[AC]</strong> to turn into <strong>&quot;[AC]&quot;</strong><br />
To counter this add an anchor to the start or end of the expression i.e. <strong>^[AC]</strong> or <strong>[AC]$</strong></em><br />
<br />
<strong>PERF|TEST</strong> will match <strong>PERF</strong> and <strong>TEST</strong>, but not <strong>LATEST</strong>, <strong>UAT</strong> or <strong>PROD</strong><br />
<br />
<strong>.*</strong> will match all shares including those with no labels<br />
<br />
<strong>.+</strong> will match any share that has a label - a share with no label configured will be tested with an empty (zero length) string<br />
<br />
An empty string will only match shares that do not have labels<br />
</p>
</div>
</j:jelly>
29 changes: 29 additions & 0 deletions src/main/webapp/help/config/label.html
@@ -0,0 +1,29 @@
<!--
~ The MIT License
~
~ Copyright (C) 2010-2011 by Anthony Robinson
~
~ 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.
-->

<div>
<p>Set the label for this share instance - for use with Parameterized publishing</p>

<p>Expand the help for Parameterized publishing for more details</p>
</div>
27 changes: 27 additions & 0 deletions src/main/webapp/help/config/parameterName.html
@@ -0,0 +1,27 @@
<!--
~ The MIT License
~
~ Copyright (C) 2010-2011 by Anthony Robinson
~
~ 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.
-->

<div>
The name of the parameter or environment variable that will contain the expression for matching the labels.
</div>
Expand Up @@ -98,6 +98,6 @@ public class CifsPublisherTest {
}

private CifsPublisher createPublisher() {
return new CifsPublisher("abc", false, new ArrayList<CifsTransfer>(0), false, false, null);
return new CifsPublisher("abc", false, new ArrayList<CifsTransfer>(0), false, false, null, null);
}
}

0 comments on commit fbd378f

Please sign in to comment.