Skip to content
This repository has been archived by the owner on Jan 23, 2020. It is now read-only.

Commit

Permalink
Merge pull request #28 from DataDog/zeller/rebase-blacklist
Browse files Browse the repository at this point in the history
Use isJobTracked() when sorting out blacklist
  • Loading branch information
JohnLZeller committed Dec 3, 2015
2 parents a97abcd + 847663c commit daa957f
Showing 1 changed file with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,10 @@ public DatadogBuildListener() { }
@Override
public final void onStarted(final Run run, final TaskListener listener) {
logger = listener.getLogger();
String jobname = run.getParent().getDisplayName();
String[] blacklist = blacklistStringtoArray( getDescriptor().getBlacklist() );
String jobName = run.getParent().getDisplayName();

// Process only if job is NOT in blacklist
if ( (blacklist == null) || !Arrays.asList(blacklist).contains(jobname.toLowerCase()) ) {
if ( isJobTracked(jobName) ) {
printLog("Started build!");

// Grab environment variables
Expand All @@ -114,7 +113,7 @@ public final void onStarted(final Run run, final TaskListener listener) {
// Gather pre-build metadata
JSONObject builddata = new JSONObject();
builddata.put("hostname", getHostname(envVars)); // string
builddata.put("job", jobname); // string
builddata.put("job", jobName); // string
builddata.put("number", run.number); // int
builddata.put("result", null); // null
builddata.put("duration", null); // null
Expand All @@ -129,6 +128,17 @@ public final void onStarted(final Run run, final TaskListener listener) {
}
}

/**
* Checks if a jobName is blacklisted, or not.
*
* @param jobName - A String containing the name of some job.
* @return a boolean to signify if the jobName is or is not blacklisted.
*/
private final boolean isJobTracked(final String jobName) {
final String[] blacklist = blacklistStringtoArray( getDescriptor().getBlacklist() );
return (blacklist == null) || !Arrays.asList(blacklist).contains(jobName.toLowerCase());
}

/**
* Called when a build is completed.
*
Expand All @@ -139,11 +149,10 @@ public final void onStarted(final Run run, final TaskListener listener) {
@Override
public final void onCompleted(final Run run, @Nonnull final TaskListener listener) {
logger = listener.getLogger();
String jobname = run.getParent().getDisplayName();
String[] blacklist = blacklistStringtoArray( getDescriptor().getBlacklist() );
final String jobName = run.getParent().getDisplayName();

// Process only if job in NOT in blacklist
if ( (blacklist == null) || !Arrays.asList(blacklist).contains(jobname.toLowerCase()) ) {
if ( isJobTracked(jobName) ) {
printLog("Completed build!");

// Collect Data
Expand Down

0 comments on commit daa957f

Please sign in to comment.