【发布时间】:2023-04-03 10:29:02
【问题描述】:
我正在使用 Groovy 脚本通过 Slack API 发送 POST,目前我收到了 invalid_payload 返回,我认为这很可能是由于我的 JSON 格式。我知道 Slack API 期望它带有双引号的 JSON,但我似乎无法将变量传递给 JSON 对象:
SUCCESS_MESSAGE = '{"attachments": [{"color": "#2A9B3A", "author_name": ${DEV_NAME}, "title": "Build Status", "title_link": ${BUILD_URL}, "text": "Successful Build" }]}'
def response = ["curl", "-X", "POST", "-H", "Content-Type: application/json", "-d", "${SUCCESS_MESSAGE}", "https://hooks.slack.com/services/${SLACK_WEBHOOK}"].execute().text
我应该如何正确格式化我的SUCCESS_MESSAGE var,以免出现错误?
【问题讨论】: