我正在尝试使用curl向我的松弛通道发送自定义松弛通知。低于我的负载。使用curl向Slack频道发布通知,以便团队成员能够看到Verison,s3链接和Directly直接访问。任何建议或意见将不胜感激。
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
任何投入都非常赞赏。
答案 0 :(得分:1)
您的第一个danger
附件的field
指定了一个名为text
的无效属性 - 将此属性更改为value
,使其成为有效的Slack {{1} }。
您可以通过Slack Message Formatting页面对Slack消息有效负载进行故障排除,看它们是否有效:here's the corrected message payload。
答案 1 :(得分:0)
尝试以下操作:有效负载和curl用于自定义松弛通知。 我在Gitlab-CI.yml文件中使用了该文件,以将Job工件和报告发送到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'
答案 2 :(得分:0)
我也将使其变得简单: 请注意:在“ content-type:”和“ application / json”犯错之后,不能有任何空格。 并注意反斜杠。您也可以在终端/ cmd上尝试此操作。我应该工作
curl -X POST -H“ Content-type:application / json” --data'{\“ text \”:\“ here_is_your_message \”}“ YOUR_WEBHOOK_URL