sonarqube use nails alarm

Description: Due to project requirements, create Jenkins is a free project that requires sonar scan through the code and then continue maven build, and not send an alarm nails, scanning does not stop by the building and sent nails alarm.

1, the plug-alarm installation

# Download release package /releases/dingding-sonar-1.0-SNAPSHOT.jar

wget https://gitee.com/chejiangyi/dingding-sonar/repository/archive/master.zip
unzip master.zip

# Run jar package sonar.url as sonar installation address

cd dingding-sonar/releases

# Start Service

nohup java -jar dingding-sonar-1.0-SNAPSHOT.jar \ --server.port=8082 \ --sonar.url=http://192.168.0.129:9000 \ > /dev/null 2 >& 1 &

# Check the successful deployment sonar-project-id for the sonar project id: task-dev

curl http://<your dingding-sonar-server IP>:8082/?projectname={sonar-project-id}

# Return results

bug: 0, vulnerabilities: 0, bad taste: 58, Reach: 0.0, repeat: 0.0, states: OK

image-20200305135649539.png

2, alarm notification is sent

Nail notice published script content Example:

#!/bin/bash
projectName=task-dev
projectId=task-dev
dingdingToken=a9c7f0dff01a01cefda6af09e5d0ec068a55d755008c2f559ec2598e9f377djl    #钉钉群组创建一个自由的webhook的token
sonarreport=$(curl -s http://192.168.0.121:8082/?projectname=${projectName})
sonar=$(curl -s http://192.168.0.121:8082/?projectname=task-dev |awk -F ":" '{print $7}'|tee dev.txt)
echo "$sonar"
if [[ "$sonar" == "ERROR" ]]
then
  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 Code Quality Report \ n
> the projectName} {$ \ n-
> [sonar地址](http://192.168.0.129:9000/dashboard?id=${projectId}) \n
> ${sonarreport} \n\"
}
}"
  exit 1
else
  echo ${sonarreport}
fi

Reference article: https://www.cnblogs.com/chejiangyi/p/10844232.html

Guess you like

Origin blog.51cto.com/14268033/2475712