diff --git a/src/main/java/jenkins/plugins/slack/ActiveNotifier.java b/src/main/java/jenkins/plugins/slack/ActiveNotifier.java index 7712116e..b4ad8978 100755 --- a/src/main/java/jenkins/plugins/slack/ActiveNotifier.java +++ b/src/main/java/jenkins/plugins/slack/ActiveNotifier.java @@ -379,14 +379,17 @@ public MessageBuilder appendCustomMessage() { } private String createBackToNormalDurationString(){ + // This status code guarantees that the previous build fails and has been successful before + // The back to normal time is the time since the build first broke Run previousSuccessfulBuild = build.getPreviousSuccessfulBuild(); - long previousSuccessStartTime = previousSuccessfulBuild.getStartTimeInMillis(); - long previousSuccessDuration = previousSuccessfulBuild.getDuration(); - long previousSuccessEndTime = previousSuccessStartTime + previousSuccessDuration; + Run initialFailureAfterPreviousSuccessfulBuild = previousSuccessfulBuild.getNextBuild(); + long initialFailureStartTime = initialFailureAfterPreviousSuccessfulBuild.getStartTimeInMillis(); + long initialFailureDuration = initialFailureAfterPreviousSuccessfulBuild.getDuration(); + long initialFailureEndTime = initialFailureStartTime + initialFailureDuration; long buildStartTime = build.getStartTimeInMillis(); long buildDuration = build.getDuration(); long buildEndTime = buildStartTime + buildDuration; - long backToNormalDuration = buildEndTime - previousSuccessEndTime; + long backToNormalDuration = buildEndTime - initialFailureEndTime; return Util.getTimeSpanString(backToNormalDuration); }