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

Jenkins脚本化Pipeline中slackSend无垂直颜色条问题求助

Jenkins脚本化Pipeline中Slack消息颜色条不显示问题解决

问题描述

在Jenkins脚本化(Groovy)Pipeline中使用以下代码发送Slack通知:

slackSend channel: '#Regression-Testing-Result', 
color: (currentBuild.result.equals("SUCCESS")) ? "good" : "danger",
message: (currentBuild.result.equals("SUCCESS")) ? "Tests passed" : "Tests failed"

消息可正常发送至指定Slack频道,但成功时的绿色垂直条、失败时的红色垂直条未显示。

环境信息

  • Jenkins版本:2.319.3
  • Slack Upload Plugin版本:1.7

解决方法

Slack Upload Plugin 1.7版本中,slackSend的color参数单独使用不会触发侧边颜色条,需将消息内容放入attachments参数的JSON结构中,通过附件里的color字段定义颜色:

修改后的Pipeline代码:

def slackColor = currentBuild.result == "SUCCESS" ? "good" : "danger"
def slackMessage = currentBuild.result == "SUCCESS" ? "Tests passed" : "Tests failed"

slackSend channel: '#Regression-Testing-Result', 
    attachments: """[
        {
            "color": "${slackColor}",
            "text": "${slackMessage}"
        }
    ]"""

额外注意事项

  • 确保执行slackSend时currentBuild.result已被正确赋值,建议在Pipeline的post阶段执行通知逻辑,此时构建结果已完全确定。
  • 确认Slack插件配置的Webhook权限正常,能正确解析附件格式的消息。

内容的提问来源于stack exchange,提问作者Vijay Kumar R

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.14 05:01:33