如何为Jenkins pipeline发送的Slack通知添加时间戳
实现方案
你可以通过Groovy自带的日期格式化方法生成指定格式的时间戳,拼接至slackSend的消息参数即可,修改后的代码如下:
def trial = 'jobName' // 注意格式化参数中月份为大写M,小写m会识别为分钟 def buildDate = new Date().format('dd/MM/yyyy') slackSend color: "good", message: "${trial} build successful on ${buildDate}"
如果你使用的是声明式Pipeline,需要将上述逻辑包裹在script块中使用,示例如下:
pipeline { agent any stages { stage('Build') { steps { // 此处为你的构建逻辑 } } } post { success { script { def trial = 'jobName' def buildDate = new Date().format('dd/MM/yyyy') slackSend color: "good", message: "${trial} build successful on ${buildDate}" } } } }
内容的提问来源于stack exchange,提问作者Varghese John
相关产品推荐
相关产品推荐

