我正在尝试使用 curl 向我的 slack 频道发送自定义松弛通知。在我的有效载荷下方.使用 curl 将通知发布到 Slack 频道,以便团队成员能够看到 Verison、s3 链接和直接访问,他们可以直接访问。任何建议或意见将不胜感激。
version=1.2.4
bundleversion=1.3.4.5
SLACK_MSG="Version=$version bundleversion=$bundleversion s3link:Random "
curl -H "Content-type: application/json" -X POST --data-urlencode -d
"payload='{
"username": "Kalyan",
"attachments": [
{
"color": "danger",
"fields": [
{
"title": "Danger Event",
"text": "$SLACK_MSG",
"short": false
}
]
},
{
"color": "warning",
"fields": [
{
"title": "Warning Event",
"value": "This is a warning",
"short": false
}
]
},
{
"color": "good",
"fields": [
{
"title": "Good Event",
"value": "This is good",
"short": false
}
]
}
]
}'" https://hooks.slack.com/services/XXXXXX/XXXXXXX/XXXXXXXXXX
Below Jenkins Error
curl: (3) [globbing] nested brace in column 51
curl: (3) Illegal characters found in URL
curl: (6) Could not resolve host: bundleversion=1.3.4.5
curl: (3) Port number ended with 'R'
curl: (3) [globbing] unmatched close brace/bracket in column 52
curl: (3) Illegal characters found in URL
curl: (6) Could not resolve host: is
curl: (6) Could not resolve host: a
curl: (3) Illegal characters found in URL
curl: (6) Could not resolve host: is
curl: (3) [globbing] unmatched close brace/bracket in column 56
任何输入都非常感谢。
你的第一个danger
附件有一个field
,其中包含一个名为 text
的无效属性 - 将此属性更改为 value
以使其成为有效的 Slack field
。
你可以通过 Slack 消息格式页面对 Slack 消息有效负载进行故障排除,以查看它们是否有效:以下是更正的消息有效负载。
我也会让它变得简单:请注意:"内容类型:"和"应用程序/json"之后不应该有任何空格,人们犯了这个错误。并注意反斜杠。您也可以在终端/cmd上尝试此操作。我应该工作
curl -X POST -H "Content-type:application/json" --data '{\"text\":\"here_is_your_message\"}' YOUR_WEBHOOK_URL
试试这个:用于自定义松弛通知的有效负载和卷曲。我在Gitlab-CI.yml文件中使用它来向Slack发送作业工件和报告。它工作正常。您可以修改下面的代码,因为我写了这样的代码,就像作业通过或失败时显示为绿色/红色一样。
- 'curl -H "Content-Type:application/json" -X POST --data "{
"attachments": [
{
"mrkdwn_in": ["text"],
"color": "#36a64f",
"author_name": "<https://$Gitlab_Home_URL/${GITLAB_USER_LOGIN}|${GITLAB_USER_NAME}>($GITLAB_USER_LOGIN)",
"text": "*Job <https://$REPO_URL/-/jobs/${CI_JOB_ID}|TESTING> was SUCCESSFUL in pipeline <https://$REPO_URL/pipelines/${CI_PIPELINE_ID}|${CI_PIPELINE_ID}>*",
"fields": [
{
"title": "Trigger source",
"value": "$CI_PIPELINE_SOURCE",
"short": true
},
{
"title": "Branch",
"value": "<https://$REPO_URL/tree/$CI_COMMIT_REF_NAME|$CI_COMMIT_REF_NAME>",
"short": true
},
{
"title": "Commit message",
"value": "<https://$REPO_URL/commit/${CI_COMMIT_SHA}|$CI_COMMIT_TITLE>",
"short": true
}
],
"footer": "<https://$REPO_URL|$CI_PROJECT_NAME>",
"footer_icon": "https://www.stickpng.com/assets/images/5847f997cef1014c0b5e48c1.png",
}
]
}" YOUR_SLACK_WEBHOOK'