diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/DatadogJobProperty.java b/src/main/java/org/datadog/jenkins/plugins/datadog/DatadogJobProperty.java index d04426d26..8c98d6fb4 100644 --- a/src/main/java/org/datadog/jenkins/plugins/datadog/DatadogJobProperty.java +++ b/src/main/java/org/datadog/jenkins/plugins/datadog/DatadogJobProperty.java @@ -152,19 +152,43 @@ public void setEmitSCMEvents(boolean emitSCMEvents) { * @return - A String containing the contents of the scanned file. Returns null when * the file cannot be found. */ - public String readTagFile(Run r) { + public String readTagFile(Run r) { String s = null; + FilePath workspace; + + // Check if a tags file has been enabled before continuing + if (getTagFile() == null) { + logger.fine(String.format("No tag file defined for run '%s'", r)); + return null; + } + + //We need to make sure that the workspace has been created. When 'onStarted' is + //invoked, the workspace has not yet been established, so this check is necessary. + try { + Executor executor = r.getExecutor(); + if(executor == null) { + logger.fine("Failed to read tag file: Executor is null"); + return null; + } + workspace = executor.getCurrentWorkspace(); + if (workspace == null) { + logger.fine("Failed to read tag file: Workspace is null"); + return null; + } + } catch (Exception e) { + DatadogUtilities.severe(logger, e, "Failed to read tag file when gathering workspace"); + return null; + } + + FilePath path = new FilePath(workspace, getTagFile()); try { - //We need to make sure that the workspace has been created. When 'onStarted' is - //invoked, the workspace has not yet been established, so this check is necessary. - FilePath workspace = r.getExecutor().getCurrentWorkspace(); - if (workspace != null && getTagFile() != null) { - FilePath path = new FilePath(workspace, getTagFile()); - if (path.exists()) { - s = path.readToString(); - } + if (path.exists()) { + s = path.readToString(); + logger.info(String.format("readTagFile successfully read tag file, tag count: %d", s.split("\n").length)); + } else { + DatadogUtilities.severe(logger, null, String.format("Failed to read tag file: for run '%s', tags path not found: %s", r, path)); } - } catch (IOException | InterruptedException | NullPointerException e) { + } catch (IOException | InterruptedException e) { DatadogUtilities.severe(logger, e, "Failed to read tag file"); } return s; diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/util/git/GitUtils.java b/src/main/java/org/datadog/jenkins/plugins/datadog/util/git/GitUtils.java index 29580afc4..c405bbe4c 100644 --- a/src/main/java/org/datadog/jenkins/plugins/datadog/util/git/GitUtils.java +++ b/src/main/java/org/datadog/jenkins/plugins/datadog/util/git/GitUtils.java @@ -58,7 +58,7 @@ public static FilePath buildFilePath(final Run run){ final Executor executor = run.getExecutor(); if(executor == null) { - LOGGER.fine("Unable to build FilePath. Run is null"); + LOGGER.fine("Unable to build FilePath. Run executor is null"); return null; }