I\'m configuring a process of Android application build by using Jenkins pipeline.
At the beginning and the end of the build, a message is sent to a relevant Slack c
Since this jenkins-pipeline script is in Groovy you can simply use new Date()
on it. Something like this "Current time ${new Date()}"
on the message
argument must work:
slackSend (channel: '#slack-test', color: 'warning', message: "Current time ${new Date()}")
This will produce the follow message in your channel:
Current time: Thu Oct 13 17:25:12 CEST 2016
If you want a specific date format you can use format(String format)
method, for example "${new Date().format('dd/MM/yyyy')}"
:
slackSend (channel: '#slack-test', color: 'warning', message: "Current time ${new Date().format('dd/MM/yyyy')}")
This instead will produce the follow message:
Current time: 13/10/2016
UPDATE
Since you don't want to use any external plugins a possible way to do so (it's a little tricky) it's to save the start time in a file using the follow script in your jenkins-pipeline:
def f = new File("/tmp/buildStart.txt")
def start = new Date().format('dd/MM/yyyy HH:mm:ss')
f.text = start
slackSend color: 'red', message: "Build start at ${start}"
Then in an other jenkins-pipeline where your build finish, parse the date from the file and get the difference with the current time:
def f = new File("/tmp/buildStart.txt")
def startDate = new Date().parse('dd/MM/yyyy HH:mm:ss',f.text)
def endDate = new Date()
def tookTime = groovy.time.TimeCategory.minus(endDate,startDate).toString()
slackSend color: 'red', message: "Total time: ${tookTime}"