Skip to content

Commit

Permalink
Merge pull request #8 from frendos/master
Browse files Browse the repository at this point in the history
[JENKINS-28047] Added waitBeforeTagging configuration parameter
  • Loading branch information
recena committed Jul 19, 2015
2 parents d802821 + aad4867 commit fb68b73
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 4 deletions.
10 changes: 9 additions & 1 deletion src/main/java/hudson/plugins/svn_tag/SvnTagPlugin.java
Expand Up @@ -51,6 +51,8 @@ private SvnTagPlugin() {
* @param buildListener build listener
* @param tagBaseURLStr tag base URL string
* @param tagComment tag comment
* @param tagDeleteComment tag delete comment
* @param waitBeforeTagging wait time before tagging in seconds
* @return true if the operation was successful
* @throws InterruptedException
* @throws IOException
Expand All @@ -61,7 +63,8 @@ public static boolean perform(AbstractBuild<?,?> abstractBuild,
Launcher launcher,
BuildListener buildListener,
String tagBaseURLStr, String tagComment,
String tagDeleteComment) throws IOException, InterruptedException {
String tagDeleteComment, int waitBeforeTagging)
throws IOException, InterruptedException {
PrintStream logger = buildListener.getLogger();
logger.println("Starting to tag");

Expand Down Expand Up @@ -171,6 +174,11 @@ public static boolean perform(AbstractBuild<?,?> abstractBuild,
logger.println(Messages.NoOldTag(evaledTagBaseURLStr));
}

if(waitBeforeTagging > 0 ) {
logger.println(Messages.WaitBeforeTagging(waitBeforeTagging));
Thread.sleep(waitBeforeTagging*1000);
}

SVNCopyClient copyClient = new SVNCopyClient(sam, null);

try {
Expand Down
61 changes: 59 additions & 2 deletions src/main/java/hudson/plugins/svn_tag/SvnTagPublisher.java
@@ -1,6 +1,7 @@
package hudson.plugins.svn_tag;

import hudson.tasks.BuildStepMonitor;

import java.io.IOException;
import java.util.HashMap;

Expand All @@ -15,6 +16,7 @@
import hudson.tasks.Publisher;
import hudson.util.FormValidation;
import net.sf.json.JSONObject;

import org.codehaus.groovy.control.CompilationFailedException;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
Expand Down Expand Up @@ -43,11 +45,18 @@ public class SvnTagPublisher extends Notifier {

private String tagDeleteComment = null;

private int waitBeforeTagging = 0;

@DataBoundConstructor
public SvnTagPublisher(String tagBaseURL, String tagComment, String tagDeleteComment) {
public SvnTagPublisher(String tagBaseURL, String tagComment, String tagDeleteComment, int waitBeforeTagging) {
this.tagBaseURL = tagBaseURL;
this.tagComment = tagComment;
this.tagDeleteComment = tagDeleteComment;
this.waitBeforeTagging = waitBeforeTagging;
}

public SvnTagPublisher(String tagBaseURL, String tagComment, String tagDeleteComment) {
this(tagBaseURL, tagComment, tagDeleteComment, 0);
}

/**
Expand All @@ -67,6 +76,15 @@ public String getTagDeleteComment() {
return this.tagDeleteComment;
}

/**
* Returns how many seconds to wait before tagging
*
* @return how many seconds to wait before tagging
*/
public int getWaitBeforeTagging() {
return this.waitBeforeTagging;
}

public BuildStepMonitor getRequiredMonitorService() {
return BuildStepMonitor.BUILD;
}
Expand All @@ -78,7 +96,7 @@ public boolean perform(AbstractBuild<?, ?> abstractBuild,
throws InterruptedException, IOException {
return SvnTagPlugin.perform(abstractBuild, launcher, buildListener,
this.getTagBaseURL(), this.getTagComment(),
this.getTagDeleteComment());
this.getTagDeleteComment(), this.getWaitBeforeTagging());
}

@Override
Expand Down Expand Up @@ -109,13 +127,16 @@ public static final class SvnTagDescriptorImpl

private String tagDeleteComment;

private int waitBeforeTagging;

/**
* Creates a new SvnTagDescriptorImpl object.
*/
public SvnTagDescriptorImpl() {
this.defaultTagBaseURL = Messages.DefaultTagBaseURL();
this.tagComment = Messages.DefaultTagComment();
this.tagDeleteComment = Messages.DefaultTagDeleteComment();
this.waitBeforeTagging = 0;
load();
}

Expand Down Expand Up @@ -219,5 +240,41 @@ public boolean isApplicable(Class<? extends AbstractProject> jobType) {
return true;
}

/**
* Returns how many seconds to wait before tagging
*
* @return how many seconds to wait before tagging
*/
public int getWaitBeforeTagging() {
return waitBeforeTagging;
}

/**
* Sets how many seconds to wait before tagging
*
* @param waitBeforeTagging
*/
public void setWaitBeforeTagging(int waitBeforeTagging) {
this.waitBeforeTagging = waitBeforeTagging;
}

/**
* Validate WaitBeforeTagging parameter - value should be numeric
*
* @param waitBeforeTagging
* @return
*/
public FormValidation doCheckWaitBeforeTagging(@QueryParameter final String waitBeforeTagging) {
try {
int value = Integer.parseInt(waitBeforeTagging);
if(value < 0) {
return FormValidation.error(Messages.NegativeWaitBeforeTagging());
}
return FormValidation.ok();
} catch (NumberFormatException e) {
return FormValidation.error(Messages.BadWaitBeforeTagging(e.getMessage()));
}
}

}
}
Expand Up @@ -17,4 +17,7 @@ TagBaseURL=Tag Base URL: {0}.
RemoteModuleLocation=Remote Module Location: {0}.
NoSVNAuthProvider=No subversion authentication provider available.
FailedParsingRevisionFile=Failed to parse revision.txt. {0}
FailedToTag=Creating the tag failed with the following error: {0}
FailedToTag=Creating the tag failed with the following error: {0}
WaitBeforeTagging=Waiting for {0} seconds before tagging
BadWaitBeforeTagging=Wait before tagging value should be integer. {0}
NegativeWaitBeforeTagging=Wait before tagging value should be 0 or higher.
Expand Up @@ -9,4 +9,8 @@
help="${descriptor.getHelpFile('tagComment')}">
<f:textbox default="${descriptor.tagDeleteComment}"/>
</f:entry>
<f:entry title="${%Wait Before Tagging}" field="waitBeforeTagging"
help="${descriptor.getHelpFile('waitBeforeTagging')}">
<f:textbox default="${descriptor.waitBeforeTagging}"/>
</f:entry>
</j:jelly>
Expand Up @@ -12,5 +12,9 @@
help="${descriptor.getHelpFile('tagComment')}">
<f:textbox/>
</f:entry>
<f:entry title="${%Wait before tagging}" field="waitBeforeTagging"
help="${descriptor.getHelpFile('waitBeforeTagging')}">
<f:textbox/>
</f:entry>
</f:section>
</j:jelly>
@@ -0,0 +1,2 @@
<p>Wait the specified number of seconds before creating the tag.</p>
<p><code>waitBeforeTagging</code> is useful when your source repository is synced between several instances and access to it is determined by geographical location, like the SVN repository at the Apache Software Foundation.</p>

0 comments on commit fb68b73

Please sign in to comment.