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 -
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.
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 ?