如何显示在Jenkins中运行构建所花费的时间?

如何显示在Jenkins中运行构建所花费的时间?,第1张

如何显示在Jenkins中运行构建所花费的时间

由于此 jenkins-pipeline 脚本位于 Groovy中,因此 您可以

new Date()
在其上简单地使用它。这样
"Currenttime ${new Date()}"
message
论点必须起作用:

slackSend (channel: '#slack-test', color: 'warning', message: "Current time ${new Date()}")

这将在您的频道中产生以下消息:

Current time: Thu Oct 13 17:25:12 CEST 2016

如果需要特定的日期格式,可以使用

format(String format)
方法,例如
"${newDate().format('dd/MM/yyyy')}"

slackSend (channel: '#slack-test', color: 'warning', message: "Current time ${new Date().format('dd/MM/yyyy')}")

相反,它将产生以下消息:

Current time: 13/10/2016

更新

由于您不想使用任何外部插件(这样做有些棘手),因此可以使用jenkins-pipeline中的follow脚本将开始时间保存在文件中:

def f = new File("/tmp/buildStart.txt")def start = new Date().format('dd/MM/yyyy HH:mm:ss')f.text = startslackSend color: 'red', message: "Build start at ${start}"

然后在构建完成的另一个jenkins管道中,从文件中解析日期,并获得与当前时间的差值:

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


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5642392.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存