You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.02 17:45:04