Skip to content

Commit

Permalink
[BuildListener] dont mess with the jobnames.
Browse files Browse the repository at this point in the history
  • Loading branch information
truthbk committed May 25, 2017
1 parent 2fffcd4 commit 4cc7f04
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 18 deletions.
Expand Up @@ -92,7 +92,6 @@ public DatadogBuildListener() { }
@Override
public final void onStarted(final Run run, final TaskListener listener) {
String jobName = run.getParent().getFullDisplayName();
jobName = DatadogUtilities.normalizeFullDisplayName(jobName);
HashMap<String,String> tags = new HashMap<String,String>();

// Process only if job is NOT in blacklist and is in whitelist
Expand All @@ -101,7 +100,7 @@ public final void onStarted(final Run run, final TaskListener listener) {

// Gather pre-build metadata
JSONObject builddata = new JSONObject();
builddata.put("job", jobName); // string
builddata.put("job", DatadogUtilities.normalizeFullDisplayName(jobName)); // string
builddata.put("number", run.number); // int
builddata.put("result", null); // null
builddata.put("duration", null); // null
Expand Down Expand Up @@ -138,7 +137,6 @@ public final void onStarted(final Run run, final TaskListener listener) {
@Override
public final void onCompleted(final Run run, @Nonnull final TaskListener listener) {
String jobName = run.getParent().getFullDisplayName();
jobName = DatadogUtilities.normalizeFullDisplayName(jobName);

// Process only if job in NOT in blacklist and is in whitelist
if ( DatadogUtilities.isJobTracked(jobName) ) {
Expand Down Expand Up @@ -575,11 +573,8 @@ public boolean configure(final StaplerRequest req, final JSONObject formData)
// Grab blacklist
this.setBlacklist(formData.getString("blacklist"));

// Grab whitelist, strip whitespace, remove duplicate commas, and make lowercase
whitelist = formData.getString("whitelist")
.replaceAll("\\s", "")
.replaceAll(",,", "")
.toLowerCase();
// Grab whitelist
this.setWhitelist(formData.getString("whitelist"));

// Grab tagNode and coerse to a boolean
if ( formData.getString("tagNode").equals("true") ) {
Expand Down
Expand Up @@ -41,7 +41,7 @@ public void onCheckout(Run<?, ?> build, SCM scm, FilePath workspace, TaskListene
File changelogFile, SCMRevisionState pollingBaseline) throws Exception {

String jobName = build.getParent().getFullDisplayName();
jobName = DatadogUtilities.normalizeFullDisplayName(jobName);
String normalizedJobName = DatadogUtilities.normalizeFullDisplayName(jobName);
HashMap<String,String> tags = new HashMap<String,String>();
DatadogJobProperty prop = DatadogUtilities.retrieveProperty(build);
// Process only if job is NOT in blacklist and is in whitelist
Expand All @@ -63,7 +63,7 @@ public void onCheckout(Run<?, ?> build, SCM scm, FilePath workspace, TaskListene
// Gather pre-build metadata
JSONObject builddata = new JSONObject();
builddata.put("hostname", DatadogUtilities.getHostname(envVars)); // string
builddata.put("job", jobName); // string
builddata.put("job", normalizedJobName); // string
builddata.put("number", build.number); // int
builddata.put("result", null); // null
builddata.put("duration", null); // null
Expand Down
Expand Up @@ -134,13 +134,11 @@ public static boolean isJobWhitelisted(final String jobName) {
final String[] whitelist = DatadogUtilities.joblistStringtoArray( DatadogUtilities.getWhitelist() );
final String jobNameLowerCase = jobName.toLowerCase();

if ( whitelist != null ) {
if ( whitelist.length == 0 ) {
if ( whitelist == null || whitelist.length == 0) {
return true;
}
return Arrays.asList(whitelist).contains(jobNameLowerCase);
}
return true;

return Arrays.asList(whitelist).contains(jobNameLowerCase);
}

/**
Expand Down
Expand Up @@ -24,11 +24,11 @@
<f:validateButton title="${%Test Hostname}" progress="${%Testing...}"
method="testHostname" with="hostname" />
<f:entry title="Blacklisted Jobs"
description="A comma-separated list of job names that should not monitored. This takes precedent over whitelist. (e.g.: susans-job,johns-job,prod-release)." >
description="A comma-separated list of job names that should not monitored. This takes precedence over whitelist. (e.g.: susans-job,johns-job,prod-release)." >
<f:textarea field="blacklist" optional="true" default="${blacklist}" />
</f:entry>
<f:entry title="Whitelisted Jobs"
description="A comma-separated list of job names that should be monitored. (e.g. susans-job,johns-job,prof-release). An empty whitelist permits all jobs." >
description="A comma-separated list of job names that should be monitored. (e.g.: susans-job,johns-job,prof-release). An empty whitelist permits all jobs." >
<f:textarea field="whitelist" optional="true" default="${whitelist}" />
</f:entry>
<f:entry title="Optional Tags"
Expand Down
Expand Up @@ -109,4 +109,4 @@ private JSONObject capturePostMetricRequestPayload() throws IOException {
private double valueOfFirstPoint(JSONObject series) {
return series.getJSONArray("points").getJSONArray(0).getDouble(1);
}
}
}

0 comments on commit 4cc7f04

Please sign in to comment.