Jenkins will typically record timestamps in ISO 8601, a standardized format for representing dates and times. They can be used in various ways, such as to generate reports or trigger other actions based on the event’s time.
In Jenkins, timestamps are governed by the timestampper plugin. This plugin allows you to add timestamps to the console output of a given Jenkins job.
In this tutorial, we will learn how to manage various aspects of the timestamper plugin to add flexibility to the timestamps of your Jenkins output.
Jenkins Timestamper Plugin
By default, you will find the Timestamper plugin installed on your Jenkins controller. However, it is good to ensure that the plugin is installed.
Navigate to the Jenkins Dashboard -> Manage Jenkins -> Manage Plugins -> Installed Plugins.
Configuring the Jenkins Timestamper Plugin
You can customize various parameters of the Timestamper plugin from the Jenkins Dashboard.
Navigate to Manage Jenkins -> Configure System -> Timestamper.
In this section, you can customize the system clock and elapsed time formats.
You can customize formats using the DurationFormats, as shown in the documentation below.
To enable the Timestamper on all Jenkins build, check the “Enable for all pipeline builds” checkbox and click save.
Once enabled, a timestamp will be added to every line in the console output of a Jenkins build.
An example is shown below:
Enabling Timestamps for a Job
Sometimes, you may not want to enable the timestamps for specific jobs rather than globally.
Start by disabling the Global timestamps option as shown in the previous step.
Next, you can add timestamps in a given job by adding the timestamps option in a Jenkins pipeline.
An example is as shown:
agent any
options {
timestamps()
}
stages {
stage('Start') {
steps {
sh 'date +%s'
}
}
stage('Pausing') {
steps {
sleep(time: 2, unit: 'MINUTES')
}
}
stage('End') {
steps {
sh "date +%s"
}
}
}
}
By adding the timestamp() options in the Jenkinsfile, Jenkins will enable timestamps for the console output of the job.
Conclusion
In this article, you learned how to enable, disable and customize timestamps in Jenkins pipelines.