1

I am using scripted jenkins pipeline to run our CI pipeline. We want to capture the time taken by each stage and store it in mongoDB which gets picked up for further processing.

I had 2 options so far -

  1. Make a call to the pipeline-stage-view-plugin at the end of the pipeline. This API will give me details of all the stages but there is no way I can know what is the end point of my pipeline. THere are so many stages and the pipeline can fail or end at any of the stage.

  2. Make a call to update mongo at the end of each stage and keep updating the collection after each stage.

Is there any better way to capture the time taken & build result of each stage after the stage gets executed ?

swetad90
  • 784
  • 1
  • 13
  • 34
  • See my answer to this other question, it might be useful https://stackoverflow.com/questions/47569922/determine-failed-stage-in-jenkins-scripted-pipeline/56002617#56002617 – JJCV May 06 '19 at 09:49

1 Answers1

0

I think your best bet is #1. Use the post's section "always" to run a step regardless of the completion status (SUCCESS, FAILURE, UNSTABLE, etc.) of the pipeline or stage run.

For more details: https://jenkins.io/doc/book/pipeline/syntax/#post

Quirino Gervacio
  • 1,240
  • 9
  • 9