How to get console log of current stage?

Viewed 881

In Jenkins pipeline, we can get console log of current build with following -

String logData = currentBuild.rawBuild.getLog(X)

Is there a way to get only log of current stage?

1 Answers

[UPDATED] you may refer to this post for a good solution to this, based on more recent Jenkins API's.

[ORIGINAL answer : only works well for non-parallel stages] The only way I know is to print out (echo) a marker at the beginning and the end of the stage. Then you can have a parsing function that get the whole console log and slices out the stage log between the start and end markers.

For convenience, I recommend creating a custom stage DSL command (e.g. myStage) that places these markers automatically for you.

Related