栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

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

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何显示在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}"


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/636559.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号