jenkins钉钉机器人发版成功消息通知 模板
时间: 2023-11-15 22:05:01 浏览: 39
以下是一个Jenkins钉钉机器人发版成功消息通知模板的示例:
```python
def send_dingtalk_msg(msg):
import requests
import json
webhook_url = 'https://oapi.dingtalk.com/robot/send?access_token=your_access_token_here'
headers = {'Content-Type': 'application/json;charset=utf-8'}
data = {
"msgtype": "markdown",
"markdown": {
"title": "Jenkins构建通知",
"text": msg
}
}
r = requests.post(url=webhook_url, headers=headers, data=json.dumps(data))
return r.text
msg = """
### Jenkins构建通知
> **项目名称:** $PROJECT_NAME
> **构建状态:** $BUILD_STATUS
> **构建日志:** $BUILD_LOG_URL
> **构建编号:** $BUILD_NUMBER
> **构建时间:** $BUILD_TIMESTAMP
"""
msg = msg.replace('$PROJECT_NAME', 'my_project')
msg = msg.replace('$BUILD_STATUS', 'SUCCESS')
msg = msg.replace('$BUILD_LOG_URL', 'http://jenkins.com/job/my_project/1/console')
msg = msg.replace('$BUILD_NUMBER', '1')
msg = msg.replace('$BUILD_TIMESTAMP', '2021-01-01 00:00:00')
send_dingtalk_msg(msg)
```
这个模板使用了Jenkins的构建变量,可以自动获取构建的相关信息,并将其填充到钉钉消息模板中。你可以根据自己的需求修改模板中的内容和格式。