Google Cloud Build Slack通知弹窗显示“no preview available”问题求助
解决Google Cloud Build Slack通知Windows桌面端显示“no preview available”问题
问题核心原因
Slack桌面端的通知预览不会解析消息内的blocks结构内容,它优先读取消息顶层的text字段。你的当前模板仅包含blocks数组,没有顶层text属性,导致Slack无法生成有效预览文本,从而显示“no preview available”。
解决方案
修改JSON模板,在blocks数组外层添加顶层text字段,填入你想要的预览内容(支持模板动态变量)。
修改后的完整JSON模板
{ "text": "Cloud Build Completed! Status: {{.Params.buildStatus}}", "blocks": [ { "type": "section", "text": { "type": "plain_text", "text": "Cloud Build Completed" } }, { "type": "section", "text": { "type": "mrkdwn", "text": "*BUILD DETAILS:*" } }, { "type": "section", "text": { "type": "mrkdwn", "text": "Status: {{.Params.buildStatus}}\nEnvironment: {{.Build.Substitutions._ENVIRONMENT}}" } }, { "type": "section", "text": { "type": "mrkdwn", "text": "*GITHUB DETAILS:*" } }, { "type": "section", "text": { "type": "mrkdwn", "text": "Repo: {{.Build.Substitutions.REPO_NAME}}\nBranch: {{.Build.Substitutions.BRANCH_NAME}}\nPR: #{{.Build.Substitutions._PR_NUMBER}}" } }, { "type": "section", "text": { "type": "mrkdwn", "text": "You can access your service here: {{.Build.Substitutions._DEV_SERVICE_URL}}" } }, { "type": "divider" }, { "type": "section", "text": { "type": "mrkdwn", "text": "View Build Logs" }, "accessory": { "type": "button", "text": { "type": "plain_text", "text": "Logs" }, "value": "click_me_123", "url": "{{.Build.LogUrl}}", "action_id": "button-action" } } ] }
操作步骤
- 将上述修改后的模板内容替换原有的JSON文件
- 重新上传修改后的模板到GCS的
gs://path-to-json-template.json路径 - 触发一次Cloud Build任务,检查Windows桌面端Slack通知的预览是否已显示自定义文本
额外说明
- 顶层
text字段支持使用模板变量(如{{.Params.buildStatus}}),可以动态插入构建状态等信息,让预览内容更具实用性 - 无需修改Slack Notifier的YAML配置文件,仅调整JSON模板结构即可生效
内容的提问来源于stack exchange,提问作者André Engelbrecht
相关产品推荐
相关产品推荐

