Your browser was unable to load all of the resources. They may have been blocked by your firewall, proxy or browser configuration.
Press Ctrl+F5 or Ctrl+Shift+R to have your browser try again.

why is step.getDuration() always null? #3866

HealingQuickly ·

Hello Robin

I'm trying to collect step information of configuration, and I'm recording the duration of certain steps. According to the API, "step.getDuration()" returns the value.
I've tried to use this function during the step is running, and within "post-execution action". It always display null. How should I access the duration of a step?

Thanks!

In addition, if I have disabled steps in a config, and I still want to record their status, such as "it's skipped", that'a all. But I know that no script, no matter pre-execution or post-execution action, will get executed. Even the step status ENUM doesn't have a SKIPPED status. Is it possible that I can record it?

Thank you!

  • replies 5
  • views 1522
  • stars 0
robinshen ADMIN ·

step.getDuration() will only be populated when build is finished. You may test it in post-build script. Skipped step will have status IDLE, and is also available when build is finished.

HealingQuickly ·

Hello Robin
Thanks for the reply

Can you tell me the order of the steps returned by steps.getAll() ? Is it the same order as the steps get executed during a build?

Also, in QB GUI, I noticed that when a build is running, each step has a running time displayed (which is the duration time when the step is finished). How can I also record the duration time of steps when a build is running? Could you give some tips on this?

Thank you very much!


PS:

I tried displaying the duration of steps after build, in post-build script under advanced settings. The script is simply this:

groovy: 
steps.getAll().each { 
  logger.debug(it.getDuration().toString()) 
}

And I couldn't find it in the server log anywhere, which doesn't matter because I have a few steps that try to use the duration values. If it executes post-build, I won't be able to access them anyway.

robinshen ADMIN ·

steps.getAll() just returns all steps without any order guarantees, as it does not make too much sense considering there are concurrent steps. To find out step arrangement, you need to access master step, to get its children, and so one.

Duration displayed at GUI calculates duration simply by deducting current system time with step start time.

tomz ·

Is there any way to get the step duration of a build in progress?

I have a build task where the step has a failure condition with a 3rd party installer. If the installer returns with a success error code but took too short a time, it actually failed.

How would I go about checking this during the build. Bonus points if there's a way to conditionally run additional steps if this is detected.

robinshen ADMIN ·

You may calculate it with below code:
System.currentTimeMillis() - build.beginDate.time