code: @Override
      public void onCompleted(WorkflowRun workflowRun, @Nonnull TaskListener listener) {
          super.onCompleted(workflowRun, listener);
  
          // Note: run.duration is zero in onCompleted(), do the substraction in this listener
          Result result = workflowRun.getResult();
          if (result == null) {
              result = Result.SUCCESS; // FIXME more elegant handling
          }
          globalPipelineMavenConfig.getDao().updateBuildOnCompletion(
                  workflowRun.getParent().getFullName(),
                  workflowRun.getNumber(),
                  result.ordinal,
                  workflowRun.getStartTimeInMillis(),
                   Math.max(System.currentTimeMillis() - workflowRun.getStartTimeInMillis(), 0)); // @see HUDSON-5844
      }
docs: /*
  TODO ensure that this code executes before DownstreamPipelineTriggerRunListener#onCompleted