3

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!

Maria
  • 107
  • 1
  • 1
  • 8

4 Answers4

6

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:

  • add execute shell blog (works for Linux)
  • insert command echo "date:" $(date +'%Y-%m-%d_%H-%M-%S')
  • Set Description Setter plugin to regexp date:(.*)
  • Set Description Setter plugin to description \1
mszalbach
  • 10,612
  • 1
  • 41
  • 53
  • yes, it works like that, just instead shell I used batch command for Windows: @echo off for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2% %ldt:~8,2%:%ldt:~10,2%:%ldt:~12,6% echo date: [%ldt%] – Maria Jan 08 '16 at 13:02
4

If you have a fresh Jenkins version (1.6xx), you have to install the ZenTimestamp plugin and use the BUILD_TIMESTAMP variable:

enter image description here

enter image description here

You can customise the format in the global Jenkins settings:

enter image description here

(my solution also shows how to use a custom link as a description)

Bruno Lavit
  • 10,184
  • 2
  • 32
  • 38
  • Which Jenkins version are you using? I tested with 1.643 and the variabloe $BUILD_ID contains the build number not a date anymore. – mszalbach Jan 08 '16 at 12:34
  • yes, I have 1.602 and for me also it displays the build number instead of date...:( – Maria Jan 08 '16 at 12:39
  • I did my test with an old version, I'll update my post with a new solution :) – Bruno Lavit Jan 08 '16 at 12:50
  • 1
    Build Timestamp Plugin looks a little fresher and more featured than Zen Timestamp Plugin: https://wiki.jenkins-ci.org/display/JENKINS/Build+Timestamp+Plugin – skiphoppy Oct 28 '16 at 16:54
2

"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..

enter image description here

enter image description here

WillDeStijl
  • 111
  • 2
  • 6
Raghav Tallam
  • 581
  • 4
  • 8
0

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

Noam Manos
  • 15,216
  • 3
  • 86
  • 85