Reputation: 107
I have installed Description Setter Plugin but I don't know if and how I can use the BUILD_ID which in jenkins/env-vars.html/ is displayed in the format: "2005-08-22_23-59-59" (YYYY-MM-DD_hh-mm-ss). Does anyone know if I can use it and how?
Displaying the BUILD_ID would be the easiest way to add timestamp to the build description, but if not possible, how can I achieve that?
Thanks!
Upvotes: 3
Views: 22443
Reputation: 16971
You can use a groovy token such as:
${GROOVY,script = "String.format('%tF %<tH:%<tM', java.time.LocalDateTime.now())"}
It will add to the build description timestamp like: 2021-12-05 13:29
Note that build.getTimestampString2() would also print the timestamp, but according to UTC (in my timezone it's two hours earlier): 2021-12-05T11:29:09Z
Upvotes: 0
Reputation: 601
"Build Timestamp Plugin" will be the Best Answer to get the TIMESTAMPS in the Build process. Follow the below Simple steps to get the "BUILD_TIMESTAMP" variable enabled.
STEP1:
Manage Jenkins -> Plugin Manager -> Installed...
Search for "Build Timestamp Plugin".
Install with or without Restart.
STEP2:
Manage Jenkins -> Configure System.
Search for 'Build Timestamp' section, then Enable the CHECKBOX.
Select the TIMEZONE, TIME format you want to setup with..Save the Page.
USAGE:
When Configuring the Build with ANT or MAVEN,
Please declare a Global variable as,
E.G. btime=${BUILD_TIMESTAMP}
(use this in your Properties box in ANT or MAVEN Build Section)
use 'btime' in your Code to any String Variables etc..
Upvotes: 2
Reputation: 10382
If you have a fresh Jenkins version (1.6xx), you have to install the ZenTimestamp plugin and use the BUILD_TIMESTAMP variable:
You can customise the format in the global Jenkins settings:
(my solution also shows how to use a custom link as a description)
Upvotes: 4
Reputation: 11440
They replaced the ${BUILD_ID}
variable to contain the build number instead of this timestamp (since 1.597+). See https://issues.jenkins-ci.org/browse/JENKINS-26520
There are some workarounds with other plugins like EnvInject or you just use the regexp feature of the Description Setter Plugin like this:
echo "date:" $(date +'%Y-%m-%d_%H-%M-%S')
date:(.*)
\1
Upvotes: 6