I want to get Getting current timestamp in inline pipeline script using pipeline plugin of hudson. For setting up build display name.
Inline groovy script used:
There are a bunch of ways to get time depending on what APIs you find most intuitive:
new Date() has since been added to the script-security-plugin whitelist
RunWrapper APIs through use of currentBuild
global variable
long
value of when the build was started in millisecondslong
value of when the build was scheduled in millisecondsduration
as a String
Using whitelisted java.time APIs, for example LocalDateTime
import java.time.LocalDateTime
final LocalDateTime currentTime = LocalDateTime.now()
// do stuff with LocalDateTime
Of course, shelling out and using the return value in your script
final String currentTime = sh(returnStdout: true, script: 'date +%Y-%m-%d').trim()
And I'm sure there are other methods, too.