79

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?

lanoxx
  • 12,249
  • 13
  • 87
  • 142
  • 32
    `options { timestamps() }` below the `agent` should work. I forget where I learned it, but you can see an example [here](https://stackoverflow.com/questions/42956598/how-to-set-job-properties-for-jobs-within-a-jenkins-multi-branch-pipeline-projec/42961160#42961160). I don't know how to tell what things are supported inside `options` but `timestamps()` is. Pretty sure you need this plugin: https://wiki.jenkins.io/display/JENKINS/Timestamper. – Quantic Oct 31 '17 at 19:20
  • 1
    @Quantic Can I use `options` in a scripted pipeline? – lanoxx Nov 07 '17 at 15:08
  • Oh, I don't know. I use declarative with a couple `script {}` sections. I'm not having any luck figuring it out with their docs either. – Quantic Nov 07 '17 at 23:32
  • That link isn't working. https://plugins.jenkins.io/timestamper/ – nroose Sep 11 '21 at 04:55

4 Answers4

116

Adding options to the declarative pipeline

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

Credit goes to the comment above Jenkins Pipeline: Enable timestamps in build log console

Samer Makary
  • 1,815
  • 2
  • 22
  • 25
60

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

Will Brode
  • 1,026
  • 2
  • 10
  • 27
wojciech_rak
  • 2,276
  • 2
  • 21
  • 30
  • 13
    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 – roomsg Jul 10 '19 at 12:36
  • 2
    The option mentioned by @roomsg can be found under `/configure` – Marcello Romani Nov 23 '20 at 13:23
  • That link isn't working. How about https://plugins.jenkins.io/timestamper/ – nroose Sep 11 '21 at 04:54
6

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

soninob
  • 428
  • 11
  • 22
2

To enable Timestamper globally (all builds):

  • Go to the Jenkins configuration
  • Go to the "Timestamper" configration

-> Select the "Enabled for all Pipeline builds" checkbox.

fl0w
  • 3,593
  • 30
  • 34