Jenkins Pipeline: Enable timestamps in build log console

Jenkins Pipeline

Jenkins Pipeline Problem Overview


How can I display build timestamps for each line of a multi-branch pipeline project? Is it a supported feature? If yes, does it need to be enabled in the Jenkinsfile or is there a GUI option?

Jenkins Pipeline Solutions


Solution 1 - Jenkins Pipeline

Adding options to the declarative pipeline

pipeline {
  agent any
  options { timestamps () }
  // stages and rest of pipeline.
}

Credit goes to the comment above https://stackoverflow.com/questions/47039924/jenkins-pipeline-enable-timestamps-in-build-log-console#comment81033213_47039924

Solution 2 - Jenkins Pipeline

For scripted pipeline just wrap your script in timestamps { } Eg.

timestamps {
  // do your job
}

Note: You must have the timestamper plugin installed: wiki.jenkins.io/display/JENKINS/Timestamper

Solution 3 - Jenkins Pipeline

I'm wondering why @roomsg comment on the accepted answer didn't become an answer.

> I just noticed that (at least in our setup) you can configure this > globally: check the "Enabled for all Pipeline builds" in the > "Timestamper" section in Jenkins configuration

I think this is the best answering for Q. So,in case you have access as admin you can set it for all pipeline jobs through GUI

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionlanoxxView Question on Stackoverflow
Solution 1 - Jenkins PipelineSamer MakaryView Answer on Stackoverflow
Solution 2 - Jenkins Pipelinewojciech_rakView Answer on Stackoverflow
Solution 3 - Jenkins PipelinesoninobView Answer on Stackoverflow