#下载release包 /releases/dingding-sonar-1.0-SNAPSHOT.jar
wget https://gitee.com/chejiangyi/dingding-sonar/repository/archive/master.zip
unzip master.zip
#运行jar包 sonar.url为sonar安装地址
cd dingding-sonar/releases
#启动服务
nohup java -jar dingding-sonar-1.0-SNAPSHOT.jar \ --server.port=8082 \ --sonar.url=http://your sonar IP:9000 \ > /dev/null 2 >& 1 &
#检查部署成功 sonar-project-id 为sonar的项目id com.jmeter:jmeter-jenkins-maven-test
curl http://your dingding-sonar-server IP:8082/?projectname={sonar-project-id}
#返回结果
bug:0,漏洞:0,坏味道:0,覆盖率:[未知],重复:0.0,状态:OK
钉钉通知发布脚本内容示例:
#!/bin/bash
#参考钉钉文档 https://open-doc.dingtalk.com/microapp/serverapi2/qf2nxq
projectName=com.jmeter:jmeter-jenkins-maven-test
projectId=com.jmeter%3Ajmeter-jenkins-maven-test
dingdingToken=你的钉钉机器人token
sonarreport=$(curl -s http://dingding-sonar-server IP:8082/?projectname=${projectName})
echo ${sonarreport}
curl -s "https://oapi.dingtalk.com/robot/send?access_token=${dingdingToken}" -H "Content-Type: application/json" -d "{ \"msgtype\": \"markdown\", \"markdown\": { \"title\":\"sonar代码质量\", \"text\": \"## Sonar代码质量报告 \n
>${projectName} \n
> [sonar地址](http://your sonar IP:9000/dashboard?id=${projectId}) \n
> ${sonarreport} \n\"
}
}"