Skip to content

Commit

Permalink
JENKINS-31150 - supporting multiple coma separated scm tags
Browse files Browse the repository at this point in the history
  • Loading branch information
yurigo79 committed Oct 24, 2015
1 parent 7aed42a commit 3ddad7c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 19 deletions.
55 changes: 37 additions & 18 deletions src/main/java/org/jenkinsci/plugins/rundeck/RundeckNotifier.java
Expand Up @@ -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;

Expand Down Expand Up @@ -65,7 +64,7 @@ public class RundeckNotifier extends Notifier {

private final String nodeFilters;

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

private final Boolean shouldWaitForRundeckJob;

Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
}
}

Expand All @@ -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;
}
}
}
}
Expand Down Expand Up @@ -373,8 +376,8 @@ public String getNodeFilters() {
return nodeFilters;
}

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

public Boolean getShouldWaitForRundeckJob() {
Expand Down Expand Up @@ -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()]);
}

}
Expand Up @@ -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();
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 3ddad7c

Please sign in to comment.