Skip to content
Permalink
Browse files

JENKINS-31150 - supporting multiple coma separated scm tags

  • Loading branch information
yurigo79 committed Oct 24, 2015
1 parent 7aed42a commit 3ddad7c59b29c6fd99b29aa1430f6aba6c8274ce
@@ -23,8 +23,7 @@
import hudson.util.FormValidation;

import java.io.IOException;
import java.util.List;
import java.util.Properties;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@@ -65,7 +64,7 @@

private final String nodeFilters;

private final String tag;
private final String[] tags;

private final Boolean shouldWaitForRundeckJob;

@@ -82,12 +81,12 @@ public RundeckNotifier(String jobId, String options, String nodeFilters, String
}

@DataBoundConstructor
public RundeckNotifier(String jobId, String options, String nodeFilters, String tag,
public RundeckNotifier(String jobId, String options, String nodeFilters, String tagsStr,
Boolean shouldWaitForRundeckJob, Boolean shouldFailTheBuild, Boolean includeRundeckLogs, Boolean tailLog) {
this.jobId = jobId;
this.options = options;
this.nodeFilters = nodeFilters;
this.tag = tag;
this.tags = extracttags(tagsStr,",");
this.shouldWaitForRundeckJob = shouldWaitForRundeckJob;
this.shouldFailTheBuild = shouldFailTheBuild;
this.includeRundeckLogs = includeRundeckLogs;
@@ -130,17 +129,19 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
* @return true if we should notify Rundeck, false otherwise
*/
private boolean shouldNotifyRundeck(AbstractBuild<?, ?> build, BuildListener listener) {
if (StringUtils.isBlank(tag)) {
if (tags.length == 0) {
listener.getLogger().println("Notifying Rundeck...");
return true;
}

// check for the tag in the changelog
for (Entry changeLog : build.getChangeSet()) {
if (StringUtils.containsIgnoreCase(changeLog.getMsg(), tag)) {
listener.getLogger().println("Found " + tag + " in changelog (from " + changeLog.getAuthor().getId()
+ ") - Notifying Rundeck...");
return true;
for(String tag: tags) {
if (StringUtils.containsIgnoreCase(changeLog.getMsg(), tag)) {
listener.getLogger().println("Found " + tag + " in changelog (from " + changeLog.getAuthor().getId()
+ ") - Notifying Rundeck...");
return true;
}
}
}

@@ -154,12 +155,14 @@ private boolean shouldNotifyRundeck(AbstractBuild<?, ?> build, BuildListener lis
AbstractBuild<?, ?> upstreamBuild = upstreamProject.getBuildByNumber(upstreamCause.getUpstreamBuild());
if (upstreamBuild != null) {
for (Entry changeLog : upstreamBuild.getChangeSet()) {
if (StringUtils.containsIgnoreCase(changeLog.getMsg(), tag)) {
listener.getLogger().println("Found " + tag + " in changelog (from "
+ changeLog.getAuthor().getId() + ") in upstream build ("
+ upstreamBuild.getFullDisplayName()
+ ") - Notifying Rundeck...");
return true;
for(String tag: tags) {
if (StringUtils.containsIgnoreCase(changeLog.getMsg(), tag)) {
listener.getLogger().println("Found " + tag + " in changelog (from "
+ changeLog.getAuthor().getId() + ") in upstream build ("
+ upstreamBuild.getFullDisplayName()
+ ") - Notifying Rundeck...");
return true;
}
}
}
}
@@ -373,8 +376,8 @@ public String getNodeFilters() {
return nodeFilters;
}

public String getTag() {
return tag;
public String[] getTags() {
return tags;
}

public Boolean getShouldWaitForRundeckJob() {
@@ -622,4 +625,20 @@ public String getUrlName() {

}


/**
*
* @param tagsStr
* @return
*/
private String[] extracttags(String tagsStr, String delimiter){

if (tagsStr == null)
return new String[0];

List<String> list = new ArrayList<String>(Arrays.asList(tagsStr.split(delimiter)));
list.removeAll(Collections.singleton(""));
return list.toArray(new String[list.size()]);
}

}
@@ -60,7 +60,7 @@ public void testCommitWithoutTag() throws Exception {
}

public void testStandardCommitWithTag() throws Exception {
RundeckNotifier notifier = new RundeckNotifier("1", null, null, "#deploy", false, false);
RundeckNotifier notifier = new RundeckNotifier("1", null, null, "#deploy, #redeploy", false, false);
notifier.getDescriptor().setRundeckInstance(new MockRundeckClient());

FreeStyleProject project = createFreeStyleProject();
@@ -283,6 +283,9 @@ public void testWaitForRundeckJob() throws Exception {
assertTrue(s.contains("Rundeck execution #1 finished in 3 minutes 27 seconds, with status : SUCCEEDED"));
}




private String createOptions() {
Properties options = new Properties();
options.setProperty("option1", "value 1");

0 comments on commit 3ddad7c

Please sign in to comment.
You can’t perform that action at this time.