jenkins中使用例子:
#定义sonar项目名称
sonar_url=bus-pub
#邮件接收人
send1=111111111@qq.com
send2=222222222@qq.com
send3=
#重新下载对应项目扫描报告
rm -f ${JOB_NAME}.pdf
wget http://192.168.20.243:9000/api/pdfreport/get?componentKey=${sonar_url} -O ${JOB_NAME}.pdf
#邮件内容
echo "${JOB_NAME}-第${BUILD_NUMBER}次代码扫描报告" > mail.txt
echo "项目名称 : ${JOB_NAME}" >> mail.txt
echo "构建编号 : 第${BUILD_NUMBER}次构建" >> mail.txt
echo "代码路径 : ${GIT_URL}" >> mail.txt
echo "代码分支 : ${GIT_BRANCH}" >> mail.txt
echo "构建日志 : ${BUILD_URL}consoleText" >> mail.txt
echo "构建Url : ${JOB_URL}" >> mail.txt
echo "工作目录 : ${WORKSPACE}" >> mail.txt
#发送邮件附件为扫描报告
sudo mail -s "=?UTF-8?B?`echo ${JOB_NAME}第${BUILD_NUMBER}次代码扫描报告 | base64`?=" ${send1},${send2},${send3} < mail.txt -A ${WORKSPACE}/*.pdf