Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-48533

Add setter for currentBuild.duration

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Open (View Workflow)
    • Priority: Minor
    • Resolution: Unresolved
    • Component/s: core
    • Labels:
      None
    • Similar Issues:

      Description

      Please add setter for duration property of Run,

      so that user can override this in case of custom pipelines, parallel stages, etc.

       


      In Run.java, something like:

      /**
       * Sets the {@link #getDuration} of this build.
       * @param d the proposed new duration
       */
       
      public void setDuration(Long d) {

          duration = d;
          LOGGER.log(FINE, this + " in " + getRootDir() + ": Run duration is set to " + d, LOGGER.isLoggable(Level.FINER) ? new Exception() : null);
          }
      }

        Attachments

          Activity

          Hide
          oleg_nenashev Oleg Nenashev added a comment -

          Not sure it is a good idea to do that.
          What's wrong with the default duration calculation logic?

          Show
          oleg_nenashev Oleg Nenashev added a comment - Not sure it is a good idea to do that. What's wrong with the default duration calculation logic?
          Hide
          dni300 David Nikoloski added a comment -

          Oleg Nenashev,

          currentBuild.duration (or Run.duration) in pipeline stages do not get their own context. startTimeInMillis is always the beginning of the entire pipeline, while you would like to calculate it based on the startTime of the stage. Especially with parallel executions within stages you would typically use Groovy syntax to calculate stage duration in a proprietary way yourself, but the current protection of fields prevent you from being able to do so. Only three fields are writable: result, displayName and description.

          Of course, I could create a different variable for a calculated duration within the pipeline and log it to stdout, but this is not always solving the problem. In my case, I would like to use the available field, because this is being picked up by the logstash plugin. Custom variables are usually not being picked up by such plugins.

          Show
          dni300 David Nikoloski added a comment - Oleg Nenashev , currentBuild.duration (or Run.duration) in pipeline stages do not get their own context. startTimeInMillis is always the beginning of the entire pipeline, while you would like to calculate it based on the startTime of the stage. Especially with parallel executions within stages you would typically use Groovy syntax to calculate stage duration in a proprietary way yourself, but the current protection of fields prevent you from being able to do so. Only three fields are writable: result, displayName and description. Of course, I could create a different variable for a calculated duration within the pipeline and log it to stdout, but this is not always solving the problem. In my case, I would like to use the available field, because this is being picked up by the logstash plugin. Custom variables are usually not being picked up by such plugins.
          Hide
          danielbeck Daniel Beck added a comment -

          The use case is a dubious workaround to no useful duration for pipelines that will probably introduce challenges related to caching all over Jenkins. This should instead just be solved properly.

          Show
          danielbeck Daniel Beck added a comment - The use case is a dubious workaround to no useful duration for pipelines that will probably introduce challenges related to caching all over Jenkins. This should instead just be solved properly.

            People

            • Assignee:
              Unassigned
              Reporter:
              dni300 David Nikoloski
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated: