title: Jenkins Pipeline currentBuild duration time returns always 0
body: <p>I am trying to get build duration for our report but it always returns 0.</p>
  
  <p>From reading docs, going through Slack plugin source and reading other resources I should be able to do one of the following:</p>
  
  <pre><code>def duration = currentBuild.duration
  def duration = currentBuild.durationString
  def duration = currentBuild.durationString()
  def duration = currentBuild.getDurationString()
  </code></pre>
  
  <p>none of which works. From my understanding this might be because I am calling this before the build actually finished and so th duration is not available yet. </p>
  
  <p>Structure of the pipeline looks something like this:</p>
  
  <pre><code>node {
      try {
          stage("Stage 1"){}
          stage("Stage 2"){}
      } catch (e) {
          currentBuild.result = "FAILED"
          throw e
      } finally {
          notifyBuild(currentBuild.result)
      }
  }
  
  def notifyBuild(String buildStatus = 'STARTED') {
      def duration = currentBuild.duration;
  }
  </code></pre>
  
  <p>My question is:</p>
  
  <ol>
  <li>Why don't I get the duration</li>
  <li>Is there a way in pipeline to specify "after build" step? From what I read try-catching should work that way</li>
  </ol>
  
  <p>My temporary solution is to use:</p>
  
  <pre><code>int jobDuration = (System.currentTimeMillis() - currentBuild.startTimeInMillis)/1000;
  </code></pre>
  
  <p>Which works fine, but always gives time in seconds and I <em>think</em> the <code>currentBuild.duration</code> should be smart enough to give different units (?) </p>