首页 > 代码库 > Jenkins-job创建MavenDeploy Job

Jenkins-job创建MavenDeploy Job

一、概述

  本次讲述jenkins的jar包MavenDeploy  job的配置

二、MavenDeploy  job配置

2.1、Project名称

技术分享

2.2、

 技术分享

技术分享

Description:

<b>【必选项】</b><br>
package:编译打包,用来检查是否可以编译成功。<br>
deploy:编译打包,且发布至Maven仓库。使用方在pom.xml中添加依赖,即可使用。<br>
<br>

 技术分享

Default Value:

请填写发布说明。示例如下:
【新增】
1.xxx
2.xxx

【优化】

【修复】

【删除】

Description:

<b>【选填项】</b><br>
<font color=red><b>警告:如果BUILD_COMMAND是deploy,则该项一定要填写,且不少于10个字符!</b><br></font>
<br>

 2.3、源码管理

技术分享

 2.4、maven-deploy中的脚本

技术分享

①check_sonar_data.sh

技术分享
  1 #!/bin/bash
  2 
  3 # -----------------------------------------------------------------------------
  4 # Filename:      check_sonar_data.sh
  5 # Encoding:      UTF-8
  6 # Date:          2015/11/24
  7 # Author:        Xiao Longqiang
  8 # Email:         xiaolongqiang@yhd.com
  9 # Function:      与Jenkins集成,拼接WAR URL、发布、日志分析、Heathcheck
 10 # Usage:         -j Job的URL
 11 #                -n Job name
 12 #                -m Job的子模块目录
 13 #                -r WAR包的正则匹配表达式
 14 #                -t Tomcat ID
 15 # Version:       
 16 # -----------------------------------------------------------------------------
 17 
 18 while getopts "u:n:d:m:b:c:r:s:" option; do
 19     case ${option} in
 20         u )
 21             REMOTE_JENKINS_URL=${OPTARG}
 22             ;;
 23         n )
 24             CI_JOB_NAME=${OPTARG}
 25             ;;
 26         d )
 27             DB_JOB_NAME=${OPTARG}
 28             ;;
 29         m )
 30             JOB_MODULE=${OPTARG}
 31             ;;
 32         b )
 33             QS_SONAR_BLOCKER_VIOLATIONS=${OPTARG}
 34             ;;
 35         c )
 36             QS_SONAR_CRITICAL_VIOLATIONS=${OPTARG}
 37             ;;
 38         r )
 39             QS_SONAR_COVERAGE=${OPTARG}
 40             ;;
 41         s )
 42             QS_SONAR_TEST_SUCCESS_DENSITY=${OPTARG}
 43             ;;
 44         \? )
 45             echo "UNKNOWN wrong parameter"
 46             exit 1
 47             ;;
 48         * )
 49             echo "UNKNOWN error while processing options"
 50             exit 1
 51             ;;
 52     esac
 53 done
 54 
 55 # 导入通用函数
 56 source  maven-deploy/define_function.sh
 57 source /etc/profile
 58 
 59 # 如果CI_JOB_NAME为空,跳过pool质量检测
 60 if [[ ${CI_JOB_NAME} = "None" ]];then
 61     DefineOutput "2" "Step :Checking CI Job config" "CI Job 为空,跳过pool质量检测"
 62     exit 0
 63 fi
 64 
 65 mkdir -p db_target
 66 touch db_target/sqlcontent.log
 67 GetQualityStandard ${JOB_NAME}
 68 
 69 # 定义变量
 70 TMP_RETRUN_PATH="db_target/${CI_JOB_NAME}_Build.tmp"
 71 
 72 # 远程运行Job
 73 #JOB_BUILD_NUMBER=`java -jar "${JENKINS_CLI_PATH}" -s "${REMOTE_JENKINS_URL}" yhd-build-job "${CI_JOB_NAME}" --username ${JENKINS_USERNAME} --password ${JENKINS_PASSWORD} | sed s/.*: //g`
 74 java -jar "${JENKINS_CLI_PATH}" -s "${REMOTE_JENKINS_URL}" yhd-build-job "${CI_JOB_NAME}" --username ${JENKINS_USERNAME} --password ${JENKINS_PASSWORD} > ${TMP_RETRUN_PATH} 2>&1
 75 
 76 # 判断返回值,最终得到{JOB_BUILD_NUMBER}
 77 if [[ `cat ${TMP_RETRUN_PATH}` = "Job is Unable To Build." ]];then
 78     DefineOutput "1" "Step :Checking CI Job FAILURE" "${CI_JOB_NAME} is Disabled" 
 79     RecordSQLContent ${DB_TABLE_NAME}.status=31 ${DB_TABLE_NAME}.end_time="`date "+%Y-%m-%d %H:%M:%S"`"
 80     exit 1
 81 elif [[ `cat ${TMP_RETRUN_PATH}` = "Job Isn‘t Building, But In Queue." ]];then
 82     for ((i=1;i<=360;i++));
 83     do
 84         if [[ `cat ${TMP_RETRUN_PATH}` = "Job Isn‘t Building, But In Queue." ]];then
 85             echo "[`date "+%Y-%m-%d %H:%M:%S"`] CI Job:${CI_JOB_NAME}在队列中,${LOOP_WAIT_TIME}秒后第$i次重试..."
 86             sleep ${LOOP_WAIT_TIME}
 87             java -jar "${JENKINS_CLI_PATH}" -s "${REMOTE_JENKINS_URL}" yhd-build-job "${CI_JOB_NAME}" --username ${JENKINS_USERNAME} --password ${JENKINS_PASSWORD}> ${TMP_RETRUN_PATH} 2>&1
 88         else
 89             JOB_BUILD_NUMBER=`cat ${TMP_RETRUN_PATH} | sed s/.*: //g`
 90             echo "[`date "+%Y-%m-%d %H:%M:%S"`] 第$i次重试成功,CI Job:${CI_JOB_NAME}触发成功,构建ID为${JOB_BUILD_NUMBER}"
 91             break 2
 92         fi
 93 
 94         # 如果在3小时后,Job仍在在队列中,那么则视为超时,退出循环。
 95         if [[ $i = 360 ]];then
 96             DefineOutput "1" "Step :Checking CI Job FAILURE" "${CI_JOB_NAME} is In Queue More Than 3 Hours"
 97             RecordSQLContent ${DB_TABLE_NAME}.status=32 ${DB_TABLE_NAME}.end_time="`date "+%Y-%m-%d %H:%M:%S"`"
 98             exit 1
 99         fi
100     done
101 elif [[ -n `cat ${TMP_RETRUN_PATH} | grep ^Job Is Building With Number: ` ]] || [[ -n `cat ${TMP_RETRUN_PATH} | grep ^Job Has Been Building With Number: ` ]];then
102     JOB_BUILD_NUMBER=`cat ${TMP_RETRUN_PATH} | sed s/.*: //g`
103 else
104     DefineOutput "1" "Step :Checking CI Job FAILURE" "${CI_JOB_NAME} is Triggered Faild" 
105     RecordSQLContent ${DB_TABLE_NAME}.status=33 ${DB_TABLE_NAME}.end_time="`date "+%Y-%m-%d %H:%M:%S"`"
106     exit 1
107 fi
108 
109 # 获取构建ID
110 JOB_BUILD_DATE=`curl -s ${REMOTE_JENKINS_URL}/job/${CI_JOB_NAME}/${JOB_BUILD_NUMBER}/ | sed -n "/Build #${JOB_BUILD_NUMBER}/{n;p}" | sed s#.*(\(.*\)).*#\1#`
111 JOB_BUILD_ID=`date -d "${JOB_BUILD_DATE}" +"%Y-%m-%d_%H-%M-%S"`
112 
113 # 记录CI Job ID、token和start_time
114 CI_JOB_ID=`curl -s "${CMIS_API_HOST}/jenkins/getJenkinsJobByJobName/1/${CI_JOB_NAME}${CMIS_API_AUTH}" | sed -e s/\([{,]\)\s*/\1\n/g -e s/}/\n}/g | sed /poolJenkinsJobRelationshipVoList/,$d | sed /"id"/!d | sed s/.*://g | sed s/,//`
115 RecordSQLContent ${CI_TABLE_NAME}.jenkins_job_id="${CI_JOB_ID}" ${CI_TABLE_NAME}.token="${JOB_BUILD_ID}_${JOB_BUILD_NUMBER}" ${CI_TABLE_NAME}.start_time="`date "+%Y-%m-%d %H:%M:%S"`"
116 
117 # 使用yhd-job-build-status命令每30秒获取一次构建状态
118 # 如果Job状态是Job Build Status: .*#.*#IsFinished,则认为结束,输出console,中断循环
119 # 否则,认为Job还在运行,继续循环
120 JOB_BUILD_STATUS=`java -jar "${JENKINS_CLI_PATH}" -s "${REMOTE_JENKINS_URL}" yhd-job-build-status "${CI_JOB_NAME}" ${JOB_BUILD_NUMBER} --username ${JENKINS_USERNAME} --password ${JENKINS_PASSWORD}`
121 for ((j=1;j<=960;j++));
122 do
123     if [[ -n `echo ${JOB_BUILD_STATUS} | sed /^Job Build Status: .*#.*#IsFinished$/!d` ]];then
124         echo "[`date "+%Y-%m-%d %H:%M:%S"`] 第$j次重试成功,CI Job:${CI_JOB_NAME}构建完成,构建ID为${JOB_BUILD_NUMBER}"
125         java -jar ${JENKINS_CLI_PATH} -s ${REMOTE_JENKINS_URL} console ${CI_JOB_NAME} ${JOB_BUILD_NUMBER} -f --username ${JENKINS_USERNAME} --password ${JENKINS_PASSWORD}
126         break 2
127     else
128         echo "[`date "+%Y-%m-%d %H:%M:%S"`] CI Job:${CI_JOB_NAME}在运行中,请等待。${LOOP_WAIT_TIME}秒后第$j次检查是否运行结束..."
129         sleep ${LOOP_WAIT_TIME}
130         JOB_BUILD_STATUS=`java -jar "${JENKINS_CLI_PATH}" -s "${REMOTE_JENKINS_URL}" yhd-job-build-status "${CI_JOB_NAME}" ${JOB_BUILD_NUMBER} --username ${JENKINS_USERNAME} --password ${JENKINS_PASSWORD}`
131     fi
132     
133     # 如果在8小时后,Job仍在在队列中,那么则视为超时,退出循环。
134     # if [[ $j = 960 ]];then
135         # DefineOutput "1" "Step 3.1:Checking CI Job FAILURE" "${CI_JOB_NAME} is In Queue More Than 3 Hours"
136         # RecordSQLContent ${DB_TABLE_NAME}.status=32 ${DB_TABLE_NAME}.end_time="`date "+%Y-%m-%d %H:%M:%S"`"
137         # exit 1
138     # fi
139 done
140 
141 # 获取构建状态
142 BUILD_STATUS=`curl -s ${REMOTE_JENKINS_URL}/job/${CI_JOB_NAME}/${JOB_BUILD_NUMBER}/console | grep "Finished:" | sed s/Finished: //g`
143 
144 # 生成Sonar标识符
145 java -jar ${JENKINS_CLI_PATH} -s ${CI_REMOTE_JENKINS_URL} get-job ${CI_JOB_NAME} --username ${JENKINS_USERNAME} --password ${JENKINS_PASSWORD} > ${CI_JOB_NAME}_config.xml 2>&1
146 wget --auth-no-challenge --http-user=${JENKINS_USERNAME} --http-password=${JENKINS_PASSWORD} -q ${REMOTE_JENKINS_URL}/job/${CI_JOB_NAME}/ws/pom.xml -O ${CI_JOB_NAME}_pom.xml
147 MVN_GROUP_ID=`cat ${CI_JOB_NAME}_pom.xml | sed /<properties>*/,$d | sed /<modules>*/,$d | sed /<dependencies>*/,$d | sed /<build>*/,$d | sed /<repositories>*/,$d | sed /<distributionManagement>*/,$d | sed /<parent>/,/<\/parent>/d | grep "<groupId>" | sed s#.*<groupId>\(.*\)</.*#\1#`
148 SONAR_BRANCH=`cat CI*_config.xml | grep "<branch>" | sed s#.*<branch>\(.*\)</.*#\1#`
149 if [[ -z ${SONAR_BRANCH} ]];then
150     SONAR_BRANCH=`cat CI*_config.xml | grep "Dsonar.branch" | sed s#.*Dsonar.branch="\(.*\)".*#\1#`
151 fi
152 
153 # if [[ -n `cat ${EXCEPTION_LIST_PATH} | sed /<parent-sub>/,/<\/parent-sub>/!d | sed /\<parent-sub>/d | awk -v var=${DB_JOB_NAME} $1==var""` ]] && [[ ${JOB_MODULE} != None ]];then
154 #     wget --auth-no-challenge --http-user=${JENKINS_USERNAME} --http-password=${JENKINS_PASSWORD} -q ${REMOTE_JENKINS_URL}/job/${CI_JOB_NAME}/ws/${JOB_MODULE}/pom.xml -O ${CI_JOB_NAME}_${JOB_MODULE}_pom.xml
155 
156 #     MVN_ARTIFACT_ID=`cat ${CI_JOB_NAME}_${JOB_MODULE}_pom.xml | sed /<properties>*/,$d | sed /<modules>*/,$d | sed /<dependencies>*/,$d | sed /<build>*/,$d | sed /<repositories>*/,$d | sed /<distributionManagement>*/,$d | sed /<parent>/,/<\/parent>/d | grep "<artifactId>" | sed s#.*<artifactId>\(.*\)</.*#\1#`
157 #     MVN_NAME=${MVN_ARTIFACT_ID}
158 # else
159 #     MVN_ARTIFACT_ID=`cat ${CI_JOB_NAME}_pom.xml | sed /<properties>*/,$d | sed /<modules>*/,$d | sed /<dependencies>*/,$d | sed /<build>*/,$d | sed /<repositories>*/,$d | sed /<distributionManagement>*/,$d | sed /<parent>/,/<\/parent>/d | grep "<artifactId>" | sed s#.*<artifactId>\(.*\)</.*#\1#`
160 #     MVN_NAME=${MVN_ARTIFACT_ID}
161 # fi
162 MVN_ARTIFACT_ID=`cat pom.xml | sed /<properties>*/,$d | sed /<modules>*/,$d | sed /<dependencies>*/,$d | sed /<build>*/,$d | sed /<repositories>*/,$d | sed /<distributionManagement>*/,$d | sed /<parent>/,/<\/parent>/d | grep "<artifactId>" | sed s#.*<artifactId>\(.*\)</.*#\1#`
163 MVN_NAME=${MVN_ARTIFACT_ID}
164 RecordSQLContent ${CI_TABLE_NAME}.trigger_user=IT_Test_SCM_Jenkins ${CI_TABLE_NAME}.mvn_group_id=${MVN_GROUP_ID} ${CI_TABLE_NAME}.mvn_artifact_id=${MVN_ARTIFACT_ID} ${CI_TABLE_NAME}.mvn_name=${MVN_NAME} ${CI_TABLE_NAME}.sonar_branch=${SONAR_BRANCH}
165 
166 # 判断构建结果
167 if [[ ${BUILD_STATUS} = "SUCCESS" ]];then
168     DefineOutput "2" "Step :Checking CI Job SUCCESS" "${CI_JOB_NAME} is Build Successed"
169         
170     # 获取代码质量结果
171     SONAR_API_URL="http://sonar.yihaodian.com.cn/api/resources?resource=${MVN_GROUP_ID}:${MVN_NAME}:${SONAR_BRANCH}&format=json&verbose=true&metrics=lines,blocker_violations,critical_violations,major_violations,tests,coverage,test_success_density"
172     GetSonarDate ${SONAR_API_URL}    
173 
174 CI_SONAR_BLOCKER_VIOLATIONS=`cat ${SQL_CONTENT} | grep -w "${CI_TABLE_NAME}.sonar_blocker_violations" | sed s/.*=//`
175 CI_SONAR_CRITICAL_VIOLATIONS=`cat ${SQL_CONTENT} | grep -w "${CI_TABLE_NAME}.sonar_critical_violations" | sed s/.*=//`
176 CI_SONAR_COVERAGE=`cat ${SQL_CONTENT} | grep -w "${CI_TABLE_NAME}.sonar_coverage" | sed s/.*=//`
177 CI_SONAR_TEST_SUCCESS_DENSITY=`cat ${SQL_CONTENT} | grep -w "${CI_TABLE_NAME}.sonar_test_success_density" | sed s/.*=//`
178 
179 RecordSQLContent ${CI_TABLE_NAME}.ci_job_status=0 ${CI_TABLE_NAME}.end_time="`date "+%Y-%m-%d %H:%M:%S"`"
180 if [[ `echo "${QS_SONAR_BLOCKER_VIOLATIONS}<${CI_SONAR_BLOCKER_VIOLATIONS}" | bc` != 0 ]];then
181     DefineOutput "1" "Step :Checking CodeStaticQuality FAILURE" "Blocker Violations is ${CI_SONAR_BLOCKER_VIOLATIONS}(>${QS_SONAR_BLOCKER_VIOLATIONS})"
182     
183     #if [[ -n `cat ${EXCEPTION_LIST_PATH} | sed ‘/<unitest>/,/<\/unitest>/!d‘ | sed ‘/\<unitest>/d‘ | awk -v var=${DB_JOB_NAME} ‘$1==var""‘` ]];then
184         RecordSQLContent ${DB_TABLE_NAME}.status=36 ${DB_TABLE_NAME}.end_time="`date "+%Y-%m-%d %H:%M:%S"`"
185         exit 1
186     #fi
187 elif [[ `echo "${QS_SONAR_CRITICAL_VIOLATIONS}<${CI_SONAR_CRITICAL_VIOLATIONS}" | bc` != 0 ]];then
188     DefineOutput "1" "Step :Checking CodeStaticQuality FAILURE" "Critical Violations is ${CI_SONAR_CRITICAL_VIOLATIONS}(>${QS_SONAR_CRITICAL_VIOLATIONS})"
189     
190     #if [[ -n `cat ${EXCEPTION_LIST_PATH} | sed ‘/<unitest>/,/<\/unitest>/!d‘ | sed ‘/\<unitest>/d‘ | awk -v var=${DB_JOB_NAME} ‘$1==var""‘` ]];then
191         RecordSQLContent ${DB_TABLE_NAME}.status=36 ${DB_TABLE_NAME}.end_time="`date "+%Y-%m-%d %H:%M:%S"`"
192         exit 1
193     #fi
194 # elif [[ `echo "${QS_SONAR_COVERAGE}>${CI_SONAR_COVERAGE}" | bc` != 0 ]];then
195 #     DefineOutput "1" "Step :Checking UnitTest FAILURE" "Unit Test‘s Coverage is ${CI_SONAR_COVERAGE}%(<${QS_SONAR_COVERAGE}%)"
196     
197 #    # if [[ -n `cat ${EXCEPTION_LIST_PATH} | sed /<unitest>/,/<\/unitest>/!d | sed /\<unitest>/d | awk -v var=${DB_JOB_NAME} $1==var""` ]];then
198 #         RecordSQLContent ${DB_TABLE_NAME}.status=37 ${DB_TABLE_NAME}.end_time="`date "+%Y-%m-%d %H:%M:%S"`"
199 #         exit 1
200 #     # fi
201 # elif [[ `echo "${QS_SONAR_TEST_SUCCESS_DENSITY}>${CI_SONAR_TEST_SUCCESS_DENSITY}" | bc` != 0 ]];then
202 #     DefineOutput "1" "Step :Checking UnitTest FAILURE" "Unit Test‘s SuccessDensity is ${CI_SONAR_TEST_SUCCESS_DENSITY}%(<${QS_SONAR_TEST_SUCCESS_DENSITY}%)"
203     
204 #     # if [[ -n `cat ${EXCEPTION_LIST_PATH} | sed /<unitest>/,/<\/unitest>/!d | sed /\<unitest>/d | awk -v var=${DB_JOB_NAME} $1==var""` ]];then
205 #         RecordSQLContent ${DB_TABLE_NAME}.status=37 ${DB_TABLE_NAME}.end_time="`date "+%Y-%m-%d %H:%M:%S"`"
206 #         exit 1
207 #     # fi
208 else
209     DefineOutput "2" "Step :Checking CodeStaticQuality And UnitTest SUCCESS" "Blocker&Critical Violations/Unit Test‘s Coverage&SuccessDensity Are Conform To The Quality Standard"
210 fi
211 elif [[ ${BUILD_STATUS} = "ABORTED" ]];then
212     DefineOutput "1" "Step :Checking CI Job FAILURE" "${CI_JOB_NAME} is Aborted"
213     RecordSQLContent ${CI_TABLE_NAME}.ci_job_status=2 ${DB_TABLE_NAME}.status=35 ${CI_TABLE_NAME}.end_time="`date "+%Y-%m-%d %H:%M:%S"`" ${DB_TABLE_NAME}.end_time="`date "+%Y-%m-%d %H:%M:%S"`"
214     exit 1
215 else
216     DefineOutput "1" "Step :Checking CI Job FAILURE" "${CI_JOB_NAME} is Build Faild"
217     RecordSQLContent ${CI_TABLE_NAME}.ci_job_status=1 ${DB_TABLE_NAME}.status=34 ${CI_TABLE_NAME}.end_time="`date "+%Y-%m-%d %H:%M:%S"`" ${DB_TABLE_NAME}.end_time="`date "+%Y-%m-%d %H:%M:%S"`"
218     exit 1
219 fi
check_sonar_data.sh

②define_function.sh

技术分享
   1 #!/bin/bash
   2 
   3 # -----------------------------------------------------------------------------
   4 # Filename:      define_function.sh
   5 # Encoding:      UTF-8
   6 # Date:          2013/08/08
   7 # Author:        Li Jinyan
   8 # Email:         lijinyan@yihaodian.com
   9 # Function:      定义通用函数
  10 # Usage:         
  11 # Version:       
  12 # -----------------------------------------------------------------------------
  13 
  14 # 定义全局变量
  15 JENKINS_CLI_PATH="/data/jenkins/jenkins-cli.jar"
  16 SSHPASS_PATH="/usr/local/bin/sshpass"
  17 MUTT_PATH="/usr/local/bin/mutt"
  18 MVN_LOCAL_REPOS="/home/maven/repos"
  19 JENKINS_JOB_PATH="/data/jenkins/jobs"
  20 NGINX_DEFAULT_PATH="/usr/share/nginx/html"
  21 OS_ROOT_PASSWORD=!yhd&345
  22 
  23 SONAR_COLUMN=( lines tests test_success_density coverage blocker_violations critical_violations major_violations )
  24 TOMCAT_PORT_LIST=( 9080 8080 8090 9090 9070 )
  25 
  26 DB_JOB_PREFIX="Daily-"
  27 CI_REMOTE_JENKINS_URL="http://jenkins_sh.yihaodian.com.cn"
  28 SONAR_URL="http://sonar.yihaodian.com.cn"
  29 AUTO_REMOTE_JENKINS_URL="http://hudson.yihaodian.cn"
  30 
  31 NOW="`date "+%Y-%m-%d %H:%M:%S"`"
  32 LOOP_WAIT_TIME="30"
  33 
  34 #CMIS_API_HOST="http://192.168.20.29:9080/rest/api"
  35 CMIS_API_HOST="http://cmis.yihaodian.com.cn/rest/api"
  36 CMIS_API_AUTH="?username=api_scm_jenkinsjob&password=m@86eAkq"
  37 AUTOTJ_API_EXCE_BYID="http://atds.yihaodian.com.cn/Report/getReportExecInfoById"
  38 AUTOTJ_API_EXCE_BYJOB="http://atds.yihaodian.com.cn/Report/getReportExecInfoByJob"
  39 AUTOTJ_API_GET_PROBLEM="http://atds.yihaodian.com.cn/Report/getUnsovledProblemByJoblist"
  40 AUTOTJ_API_INSERT_PROBLEM="http://atds.yihaodian.com.cn/Report/insertProblemInfo"
  41 
  42 DB_TABLE_NAME="scm_cmis_daily_build"
  43 CI_TABLE_NAME="scm_cmis_code_quality"
  44 AUTO_TABLE_NAME="scm_cmis_auto_test"
  45 #注释by何磊CONTAINER_TABLE_NAME="yhd_container"
  46 #注释by何磊CONTAINER_TABLE_NAME="yhd_container"
  47 #注释by何磊CONTAINER_TOMCAT_TABLE_NAME="scm_cmis_container_tomcat"
  48 
  49 #新增by何磊
  50 COMPONENT_TOMCAT_TABLE_NAME="scm_cmis_component_tomcat"
  51 
  52 SUCCESS_RGB="101,196,0"
  53 FAILURE_RGB="196,13,13"
  54 
  55 SQL_CONTENT="db_target/sqlcontent.log"
  56 HTML_MAIL_PATH="db_target/dailybuild_mail.html"
  57 EXCEPTION_LIST_PATH="db_daily-build/exception_list.txt"
  58 
  59 WIKI_DB_PROBLEM="http://wiki.yihaodian.cn/mediawiki/index.php/DailyBuild%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98%E5%8F%8A%E5%A4%84%E7%90%86"
  60 
  61 DB_MAIL_CC="xiarong@yhd.com,wangtao4@yhd.com,panchunjun@yhd.com"
  62 # AUTO_MAIL_CC_TO=",yanxiaoting@yhd.com,chenxueqin@yhd.com,zhangaizhen@yhd.com,gongwenli@yhd.com,xuwenqiao@yhd.com,liaoqian@yhd.com,fanwenli@yhd.com,caiyubing@yhd.com,liyiming@yhd.com"
  63 
  64 CMIS_DB_IP="192.168.17.102"
  65 CMIS_DB_PORT="3306"
  66 CMIS_DB_USERNAME="cmis_admin"
  67 CMIS_DB_PASSWORD=V%f4azj!
  68 CMIS_DB_NAME="cmis"
  69 CMIS_DB_LOG="/var/log/jenkins/mysql_sdbc.log"
  70 
  71 JENKINS_USERNAME="IT_Test_SCM_Jenkins"
  72 JENKINS_PASSWORD="ezwpk8sx,js526"
  73 
  74 ANDROID_TEST_PACKAGE=( com.thestore.main com.yhd.mobile.test com.yihaodian.themall com.yihaodian.themall.test )
  75 
  76 # 定义全局函数
  77 function DefineOutput()
  78 {
  79 # 函数功能说明
  80 # 根据传入的Type,输出不同的日志
  81 # 示例:DefineOutput "2" "Step 5:AutoTesting SUCCESS" "Automation Test is Successed"
  82 # 示例:DefineOutput "1" "Step 5:AutoTesting FAILURE" "Automation Test is Faild"
  83 OUTPUT_ARRAY=( [1]=ERROR [2]=INFO )
  84 OUTPUT_STATS=( [1]=Reson [2]=Status )
  85 OUTPUT_TYPE=$1
  86 OUTPUT_RESULT=$2
  87 OUTPUT_STATUS=$3
  88 echo -e "\033[0;3${OUTPUT_TYPE}m[DailyBuild_${OUTPUT_ARRAY[${OUTPUT_TYPE}]}] -------------------------------------------------------------------------------------------------------------------"
  89 echo -e "\033[1;3${OUTPUT_TYPE}m[DailyBuild_${OUTPUT_ARRAY[${OUTPUT_TYPE}]}] ${OUTPUT_RESULT}"
  90 echo -e "\033[1;3${OUTPUT_TYPE}m[DailyBuild_${OUTPUT_ARRAY[${OUTPUT_TYPE}]}] ${OUTPUT_STATS[${OUTPUT_TYPE}]}:${OUTPUT_STATUS}"
  91 echo -e "\033[0;3${OUTPUT_TYPE}m[DailyBuild_${OUTPUT_ARRAY[${OUTPUT_TYPE}]}] -------------------------------------------------------------------------------------------------------------------"
  92 }
  93 
  94 function CheckCodeUpdate()
  95 {
  96 # 函数功能说明
  97 # 检查程序代码是否有更新,并将结果写入${SQL_CONTENT}
  98 # 如果代码无更新,且是自动触发的,则成功退出
  99 # 0代表有更新,1代表无更新
 100 # 示例:CheckCodeUpdate 177
 101 CURR_BUILD_NUMBER=$1
 102 BUILD_USER=$2
 103 
 104 LAST_BUILD_NUMBER=$((${CURR_BUILD_NUMBER}-1))
 105 
 106 if [[ ${CURR_BUILD_NUMBER} = 1 ]];then
 107     RecordSQLContent ${DB_TABLE_NAME}.is_code_update=0
 108 else
 109     if [[ ${BUILD_USER} = "Poll SCM" ]] || [[ ${BUILD_USER} = "IT_Test_SCM_Jenkins" ]];then
 110         # 循环20次,获取最近一次是自动触发的BUILD_NUMBER
 111         for ((i=1;i<=20;i++));
 112         do
 113             # 如果在循环范围内,上一次构建ID是0,则表明该次自动触发,是Job创建以来的首次自动触发,那么可以认为最LAST_BUILD_NUMBER=1
 114             if [[ ${LAST_BUILD_NUMBER} = "0" ]];then
 115                 LAST_BUILD_NUMBER="1"
 116                 break 2
 117             fi
 118         
 119             LAST_BUILD_USER=`cat ../builds/${LAST_BUILD_NUMBER}/build.xml 2>/dev/null | grep -A3 <hudson.model.CauseAction> | grep <userId>.*</userId> | sed s/.*<userId>\(.*\)<\/userId>/\1/ `
 120             
 121             if [[ "${LAST_BUILD_USER}" != "${JENKINS_USERNAME}" ]];then
 122                 LAST_BUILD_NUMBER=$((${LAST_BUILD_NUMBER}-1))
 123             else
 124                 break 2
 125             fi
 126             
 127             # 如果第20次,还没有自动触发的记录,则中断退出
 128             if [[ $i = 20 ]];then
 129                 DefineOutput "1" "Step 1.0: Checking Code Update FAILURE" "None Auto-Build In Last 10 History"
 130                 exit 1
 131             fi
 132         done
 133     fi
 134 
 135     CURR_CODE_REVISION=`cat ../builds/${CURR_BUILD_NUMBER}/revision.txt | sed /07_Environment\|10_SCM\|actionbarsherlock\|Alipay_lib\|WeiboSDK\|9.Others\|02_MobileAutoTestProjects/d | sed s#.*/##`
 136     LAST_CODE_REVISION=`cat ../builds/${LAST_BUILD_NUMBER}/revision.txt | sed /07_Environment\|10_SCM\|actionbarsherlock\|Alipay_lib\|WeiboSDK\|9.Others\|02_MobileAutoTestProjects/d | sed s#.*/##`
 137     
 138     if [[ ${CURR_CODE_REVISION} = ${LAST_CODE_REVISION} ]];then
 139         RecordSQLContent ${DB_TABLE_NAME}.is_code_update=1
 140         
 141         if [[ ${BUILD_USER} = "Poll SCM" ]] || [[ ${BUILD_USER} = "IT_Test_SCM_Jenkins" ]];then
 142             DefineOutput "2" "Step 1:Checking Code Update" "Exit.No Code was submited."
 143             exit 0
 144         fi
 145     else
 146         RecordSQLContent ${DB_TABLE_NAME}.is_code_update=0
 147     fi
 148 fi
 149 }
 150 
 151 function DeployStatics()
 152 {
 153 # 函数功能说明
 154 # 根据传入的静态服务器IP及ZIP包,发布静态文件
 155 # 静态服务器的/usr/share/nginx/html的owner,必须是whtest
 156 # 示例:
 157 STATICS_HOST_IP=$1
 158 JOB_MODULE=$2
 159 ZIP_REGULAR=$3
 160 
 161 if [[ ${STATICS_HOST_IP} = None ]];then
 162     DefineOutput "2" "Step 4.4:Deploying Statics SUCCESS" "No Need to Deploy Statics"
 163 elif [[ ${STATICS_HOST_IP} != None ]] && [[ -n ${STATICS_HOST_IP} ]];then
 164     APP_NAME=`echo ${ZIP_REGULAR} | sed s/\.\*\.zip//`
 165     STATIC_SCRIPT=`${SSHPASS_PATH} -p yhd;123 ssh whtest@${STATICS_HOST_IP} "ls /home/yhdteopts/*.sh | grep "${APP_NAME}.sh" | sed ‘/111/d‘"`
 166 
 167     # 根据Job是否有子Module,和ZIP包名字的正则表达式(变量ZIP_REGULAR),确定Zip包的URL
 168     if [ ${JOB_MODULE} == None ];then
 169         ZIP_DIRECTORY="${JENKINS_JOB_PATH}/${JOB_NAME}/workspace/target/"
 170         ZIP_NAME=`cd ${ZIP_DIRECTORY} && ls *.zip | sed /${ZIP_REGULAR}/!d`
 171         ZIP_URL="${JOB_URL}ws/target/${ZIP_NAME}"
 172     else
 173         ZIP_DIRECTORY="${JENKINS_JOB_PATH}/${JOB_NAME}/workspace/${JOB_MODULE}/target/"
 174         ZIP_NAME=`cd ${ZIP_DIRECTORY} && ls *.zip | sed /${ZIP_REGULAR}/!d`
 175         ZIP_URL="${JOB_URL}ws/${JOB_MODULE}/target/${ZIP_NAME}"
 176     fi
 177 
 178     # 判断ZIP_URL是否有效
 179     ZIP_URL_STATUS=`curl --user ${JENKINS_USERNAME}:${JENKINS_PASSWORD} -I -s ${ZIP_URL} | sed /HTTP\/1.1/!d`
 180     if [[ ${ZIP_NAME} != *.zip && ${ZIP_URL_STATUS} = "HTTP/1.1 200 OK"* ]];then
 181         DefineOutput "1" "Step 4.4:Deploying Statics FAILURE" "Invaild ZIP URL:${ZIP_URL}"
 182         RecordSQLContent ${DB_TABLE_NAME}.status=45 ${DB_TABLE_NAME}.deploy_end_time="`date "+%Y-%m-%d %H:%M:%S"`" ${DB_TABLE_NAME}.end_time="`date "+%Y-%m-%d %H:%M:%S"`"
 183         exit 1
 184     fi
 185 
 186     # 匹配不到静态发布脚本,提示报警,否则发布静态至测试环境
 187     if [[ -z "${STATIC_SCRIPT}" ]]; then
 188         STATIC_SCRIPT=`${SSHPASS_PATH} -p yhd;123 ssh whtest@${STATICS_HOST_IP} "ls /home/yhdteopts/*.sh | grep "${APP_NAME}.sh" | sed ‘/111/d‘"`
 189         if [[ -z "${STATIC_SCRIPT}" ]]; then
 190             DefineOutput "1" "Step 4.4:Deploying Statics FAILURE" "Zip DeployScript is Not Exist"
 191             RecordSQLContent ${DB_TABLE_NAME}.status=46 ${DB_TABLE_NAME}.deploy_end_time="`date "+%Y-%m-%d %H:%M:%S"`" ${DB_TABLE_NAME}.end_time="`date "+%Y-%m-%d %H:%M:%S"`"
 192             exit 1
 193         fi
 194     fi
 195 
 196     ZIP_BASENAME=`basename ${ZIP_URL}`
 197     ZIP_LOCAL_URL="http://127.0.0.1/${ZIP_BASENAME}"
 198 
 199     ${SSHPASS_PATH} -p yhd;123 ssh whtest@${STATICS_HOST_IP} "source /etc/profile && wget --auth-no-challenge --http-user=${JENKINS_USERNAME} --http-password=${JENKINS_PASSWORD} -q ${ZIP_URL} -P ${NGINX_DEFAULT_PATH} && sh ${STATIC_SCRIPT} ${ZIP_LOCAL_URL} && rm -rf ${NGINX_DEFAULT_PATH}/${ZIP_BASENAME}"
 200 
 201     DefineOutput "2" "Step 4.4:Deploying Statics SUCCESS" "Use ${ZIP_LOCAL_URL} to Deploy ${STATICS_HOST_IP}‘s ${STATIC_SCRIPT}"
 202 fi
 203 }
 204 
 205 function CheckHcURL()
 206 {
 207 # 函数功能说明
 208 # 1.将IP、端口、Tomcat server.xml中的path和新HeathCheck,拼接成HeathCheck的URL
 209 # 2.使用curl访问此URL,根据返回结果判断URL是否可用
 210 TOMCAT_ID=$1
 211 HOST_IP=$2
 212 TOMCAT_PORT="${TOMCAT_PORT_LIST[$((`echo ${TOMCAT_ID} | sed ‘s/tomcat//‘`%5))]}"
 213 #注释by何磊SELECT_TOMCAT_HC="SELECT T.health_check_url FROM ${CONTAINER_TABLE_NAME} C,${CONTAINER_TOMCAT_TABLE_NAME} T where C.id = T.yhd_container_id and C.container_code ="""${TOMCAT_ID}""
 214 #新增by何磊
 215 SELECT_TOMCAT_HC="SELECT T.health_check_url FROM ${COMPONENT_TOMCAT_TABLE_NAME} T where T.tomcat_code ="""${TOMCAT_ID}""
 216 TOMCAT_ADDR=`db_common/mysql_sdbc.sh -h ${CMIS_DB_IP} -p ${CMIS_DB_PORT} -u ${CMIS_DB_USERNAME} -w ${CMIS_DB_PASSWORD} -d ${CMIS_DB_NAME} -c "${SELECT_TOMCAT_HC}" -l ${CMIS_DB_LOG} | sed -n 3p`
 217 
 218 HEATH_CHECK_URL="http://${HOST_IP}:${TOMCAT_PORT}${TOMCAT_ADDR}"
 219 HC_CHECK_STATUS=`/usr/bin/curl -s --connect-timeout 20 -m 30 "${HEATH_CHECK_URL}"`
 220 
 221 if [[ -n ${HC_CHECK_STATUS} && ${HC_CHECK_STATUS} = ok ]] || [[ -n ${HC_CHECK_STATUS} && ${HC_CHECK_STATUS} = OK ]];then
 222     DefineOutput "2" "Step 4.3:Checking HeathCheck SUCCESS" "Vaild HeathCheck URL:${HEATH_CHECK_URL}"
 223     RecordSQLContent ${DB_TABLE_NAME}.health_check_url=${HEATH_CHECK_URL} ${DB_TABLE_NAME}.health_check_result=SUCCESS
 224 else
 225     TOMCAT_APP_PATH=`/usr/local/bin/sshpass -p yhd;123 ssh whtest@${HOST_IP} "cat /home/tomcatcluster/${TOMCAT_ID}/conf/server.xml "  | grep "<Context displayName*" |  sed s/.*path="//g | sed s/".*//g`
 226     HEATH_CHECK_URL="http://${HOST_IP}:${TOMCAT_PORT}${TOMCAT_APP_PATH}/getCheckInfo.hck"
 227     HC_CHECK_STATUS=`/usr/bin/curl -s --connect-timeout 20 -m 30 "${HEATH_CHECK_URL}"`
 228     
 229     if [[ -n ${HC_CHECK_STATUS} && ${HC_CHECK_STATUS} = ok ]] || [[ -n ${HC_CHECK_STATUS} && ${HC_CHECK_STATUS} = OK ]];then
 230         DefineOutput "2" "Step 4.3:Checking HeathCheck SUCCESS" "Vaild HeathCheck URL:${HEATH_CHECK_URL}"
 231         RecordSQLContent ${DB_TABLE_NAME}.health_check_url=${HEATH_CHECK_URL} ${DB_TABLE_NAME}.health_check_result=SUCCESS
 232     elif [[ -z ${HC_CHECK_STATUS} ]];then
 233         DefineOutput "1" "Step 4.3:Checking HeathCheck FAILURE" "No Response From ${HEATH_CHECK_URL}"
 234         RecordSQLContent ${DB_TABLE_NAME}.health_check_url=${HEATH_CHECK_URL} ${DB_TABLE_NAME}.health_check_result=FAILURE ${DB_TABLE_NAME}.status=44 ${DB_TABLE_NAME}.deploy_end_time="`date "+%Y-%m-%d %H:%M:%S"`" ${DB_TABLE_NAME}.end_time="`date "+%Y-%m-%d %H:%M:%S"`"
 235         exit 1
 236     else
 237         DefineOutput "1" "Step 4.3:Checking HeathCheck FAILURE" "Invaild HeathCheck URL:${HEATH_CHECK_URL}.The Response Are:"
 238         echo -e "${HC_CHECK_STATUS}"
 239         RecordSQLContent ${DB_TABLE_NAME}.health_check_url=${HEATH_CHECK_URL} ${DB_TABLE_NAME}.health_check_result=FAILURE ${DB_TABLE_NAME}.status=44 ${DB_TABLE_NAME}.deploy_end_time="`date "+%Y-%m-%d %H:%M:%S"`" ${DB_TABLE_NAME}.end_time="`date "+%Y-%m-%d %H:%M:%S"`"
 240         exit 1
 241     fi
 242 fi
 243 }
 244 
 245 function SendMail()
 246 {
 247 # 函数功能说明
 248 # 发送邮件
 249 # 示例:SendMail "test" "lijinyan@yihaodian.com" "db_target/sqlcontent.log"
 250 MAIL_SUBJECT=$1
 251 MAIL_TO=$2
 252 MAIL_CC_TO=$3
 253 MAIL_CONTENT=$4
 254 
 255 "${MUTT_PATH}" -s "${MAIL_SUBJECT}" -e set content_type="text/html" -e "my_hdr from:Jenkins-每日构建<non-repl
 256 y@yhd.com>" "${MAIL_TO}" -c "${MAIL_CC_TO}"< "${MAIL_CONTENT}"
 257 }
 258 
 259 function GenHtmlTableContent()
 260 {
 261 # 函数功能说明
 262 # 生成html表格的内容,td或th
 263 # 示例:GenHtmlTableContent th left "204, 255, 255" "Job Name"
 264 HTML_TABLE_TYPE=$1
 265 HTML_TABLE_STYLE_RGB=$2
 266 HTML_TABLE_CONTENT=$3
 267 if [[ ${HTML_TABLE_TYPE} = "th" ]];then
 268     echo                 <${HTML_TABLE_TYPE} align="left" style="background-color: rgb(‘"${HTML_TABLE_STYLE_RGB}"‘);">‘"${HTML_TABLE_CONTENT}"‘</${HTML_TABLE_TYPE}> >> ${HTML_MAIL_PATH}
 269 else
 270     echo                 <${HTML_TABLE_TYPE} align="left" style="background-color: rgb(‘"${HTML_TABLE_STYLE_RGB}"‘);color: rgb(0, 0, 0)">‘"${HTML_TABLE_CONTENT}"‘</${HTML_TABLE_TYPE}> >> ${HTML_MAIL_PATH}
 271 fi
 272 }
 273 
 274 function SendDailyBuildMail()
 275 {
 276 # 函数功能说明
 277 # 生成html邮件,保存至${HTML_MAIL_PATH},并通过邮件发送
 278 # 示例:SENDDBMAIL ${JOB_NAME} ${JOB_URL} ${BUILD_NUMBER} "${MAIL_RECIPIENT}" "${DB_MAIL_CC}"
 279 DB_JOB_NAME=$1
 280 DB_JOB_URL=$2
 281 DB_BUILD_NUMBER=$3
 282 DB_TOMCAT_ID=$4
 283 DB_MAIL_TO=$5
 284 DB_MAIL_CC_TO=$6
 285 AUTO_JOB_NAME=$7
 286 TRIGGER_USER=$8
 287 IS_SKIP_AUTO=$9
 288 IS_SKIP_UNIT=${10}
 289 IS_SKIP_DEPLOY=${11}
 290 QS_SONAR_BLOCKER_VIOLATIONS=${12}
 291 QS_SONAR_CRITICAL_VIOLATIONS=${13}
 292 QS_SONAR_COVERAGE=${14}
 293 QS_SONAR_TEST_SUCCESS_DENSITY=${15}
 294 QS_AUTO_PASS_RATE=${16}
 295 
 296 if [[ ${TRIGGER_USER} = "Poll SCM" ]] || [[ ${TRIGGER_USER} = "IT_Test_SCM_Jenkins" ]];then
 297     TRIGGER_USER="自动触发"
 298 else
 299     TRIGGER_USER=`curl -s ${CMIS_API_HOST}/user/getUserInfoByAdAccount/${TRIGGER_USER}${CMIS_API_AUTH} | sed -e s/\([{,]\)\s*/\1\n/g -e s/}/\n}/g | sed /displayName/!d | sed -n 1p | sed s/.*://g | sed s/"// | sed s/".*//`
 300 fi
 301 
 302 # 从${SQL_CONTENT}及数据库中获取DailyBuild各种数据
 303 DB_STATUS=`cat ${SQL_CONTENT} | grep -w "${DB_TABLE_NAME}.status" | sed s/.*=//`
 304 DB_START_TIME=`cat ${SQL_CONTENT} | grep -w "${DB_TABLE_NAME}.start_time" | sed s/.*=//`
 305 DB_IS_CODE_UPDATE=`cat ${SQL_CONTENT} | grep -w "${DB_TABLE_NAME}.is_code_update" | sed s/.*=//`
 306 DB_END_TIME=`cat ${SQL_CONTENT} | grep -w "${DB_TABLE_NAME}.end_time" | sed s/.*=//`
 307 DB_WAR_URL=`cat ${SQL_CONTENT} | grep -w "${DB_TABLE_NAME}.war_url" | sed s/.*=//`
 308 DB_WAR_NAME=`echo ${DB_WAR_URL} | sed s#.*/##`
 309 DB_TOMCAT_STARTUP_TIME=`cat ${SQL_CONTENT} | grep -w "${DB_TABLE_NAME}.tomcat_startup_time" | sed s/.*=//`
 310 DB_TOMCAT_HEATHCKECK_URL=`cat ${SQL_CONTENT} | grep -w "${DB_TABLE_NAME}.health_check_url" | sed s/.*=//`
 311 
 312 CI_SONAR_LINES=`cat ${SQL_CONTENT} | grep -w "${CI_TABLE_NAME}.sonar_lines" | sed s/.*=//`
 313 CI_SONAR_BLOCKER_VIOLATIONS=`cat ${SQL_CONTENT} | grep -w "${CI_TABLE_NAME}.sonar_blocker_violations" | sed s/.*=//`
 314 CI_SONAR_CRITICAL_VIOLATIONS=`cat ${SQL_CONTENT} | grep -w "${CI_TABLE_NAME}.sonar_critical_violations" | sed s/.*=//`
 315 CI_SONAR_MAJOR_VIOLATIONS=`cat ${SQL_CONTENT} | grep -w "${CI_TABLE_NAME}.sonar_major_violations" | sed s/.*=//`
 316 CI_SONAR_TESTS=`cat ${SQL_CONTENT} | grep -w "${CI_TABLE_NAME}.sonar_tests" | sed s/.*=//`
 317 CI_SONAR_COVERAGE=`cat ${SQL_CONTENT} | grep -w "${CI_TABLE_NAME}.sonar_coverage" | sed s/.*=//`
 318 CI_SONAR_TEST_SUCCESS_DENSITY=`cat ${SQL_CONTENT} | grep -w "${CI_TABLE_NAME}.sonar_test_success_density" | sed s/.*=//`
 319 CI_SONAR_BARNCH=`cat ${SQL_CONTENT} | grep -w "${CI_TABLE_NAME}.sonar_branch" | sed s/.*=//`
 320 CI_MVN_GROUP_ID=`cat ${SQL_CONTENT} | grep -w "${CI_TABLE_NAME}.mvn_group_id" | sed s/.*=//`
 321 CI_MVN_ARTIFACT_ID=`cat ${SQL_CONTENT} | grep -w "${CI_TABLE_NAME}.mvn_artifact_id" | sed s/.*=//`
 322 
 323 AUTO_AUTO_ID=`cat ${SQL_CONTENT} | grep -w "${AUTO_TABLE_NAME}.auto_id" | sed s/.*=//`
 324 
 325 SELETE_DB_STATUS_MESSAGE="SET NAMES ‘utf8‘;SELECT message FROM cmis.scm_cmis_daily_build_status where id="""${DB_STATUS}""
 326 DB_STATUS_MESSAGE=`db_common/mysql_sdbc.sh -h ${CMIS_DB_IP} -p ${CMIS_DB_PORT} -u ${CMIS_DB_USERNAME} -w ${CMIS_DB_PASSWORD} -d ${CMIS_DB_NAME} -c "${SELETE_DB_STATUS_MESSAGE}" -l ${CMIS_DB_LOG} | sed -n 3p`
 327 
 328 SELETE_TOMCAT_HOST_IP_OWNER="SET NAMES ‘utf8‘;SELECT host_ip,yhd_user.display_name FROM yhd_container,yhd_user where yhd_container.container_code = """${DB_TOMCAT_ID}""" and yhd_container.owner_user_id = yhd_user.id"
 329 TOMCAT_HOST_IP_OWNER=`db_common/mysql_sdbc.sh -h ${CMIS_DB_IP} -p ${CMIS_DB_PORT} -u ${CMIS_DB_USERNAME} -w ${CMIS_DB_PASSWORD} -d ${CMIS_DB_NAME} -c "${SELETE_TOMCAT_HOST_IP_OWNER}" -l ${CMIS_DB_LOG} | sed -n 3p`
 330 DB_TOMCAT_HOST_IP=`echo ${TOMCAT_HOST_IP_OWNER} | awk {print $1}`
 331 DB_TOMCAT_OWNER=`echo ${TOMCAT_HOST_IP_OWNER} | awk {$1="";print} | sed s/ //`
 332 
 333 DB_JOB_ID=`curl -s "${CMIS_API_HOST}/jenkins/getJenkinsJobByJobName/2/${DB_JOB_NAME}${CMIS_API_AUTH}" | sed -e s/\([{,]\)\s*/\1\n/g -e s/}/\n}/g | sed /poolJenkinsJobRelationshipVoList/,$d | sed /id/!d | sed s/.*://g | sed s/,//`
 334 AUTO_JOB_ID=`curl -s "${CMIS_API_HOST}/jenkins/getJenkinsJobByJobName/3/${AUTO_JOB_NAME}${CMIS_API_AUTH}" | sed -e s/\([{,]\)\s*/\1\n/g -e s/}/\n}/g | sed /poolJenkinsJobRelationshipVoList/,$d | sed /id/!d | sed s/.*://g | sed s/,//`
 335 UNSOVLED_PROBLEM_NUM=`curl -s "${AUTOTJ_API_GET_PROBLEM}?job_list\[\]=${DB_JOB_ID}&job_list\[\]=${AUTO_JOB_ID}" | sed -e s/\([{,]\)\s*/\1\n/g -e s/}/\n}/g | sed /total/!d | sed s/.*://g | sed s/"// | sed s/".*//`
 336 
 337 # 生成邮件头
 338 rm -rf ${HTML_MAIL_PATH}
 339 if [[ ${DB_STATUS} = 0 ]];then
 340     DB_BUILD_RESULT="SUCCESS"
 341     echo <table border="0" cellpadding="0" width="100%" style="background-color:rgb(${SUCCESS_RGB});border-collapse:collapse;font-family:微软雅黑;font-size:35px;color: rgb(255, 255, 255)"> >> ${HTML_MAIL_PATH}
 342     echo             <tr> >> ${HTML_MAIL_PATH}
 343     echo                 <th align="left" valign="top">DailyBuild-SUCCESS</th> >> ${HTML_MAIL_PATH}
 344     echo             </tr> >> ${HTML_MAIL_PATH}
 345     echo             <tr> >> ${HTML_MAIL_PATH}
 346     echo                 <th align="right" style="color: rgb(${SUCCESS_RGB});font-size:15px">DailyBuild Is</th> >> ${HTML_MAIL_PATH}
 347 else
 348     DB_BUILD_RESULT="FAILURE"
 349     echo <table border="0" cellpadding="0" width="100%" style="background-color:rgb(${FAILURE_RGB});border-collapse:collapse;font-family:微软雅黑;font-size:35px;color: rgb(255, 255, 255)"> >> ${HTML_MAIL_PATH}
 350     echo             <tr> >> ${HTML_MAIL_PATH}
 351     echo                 <th align="left" valign="top">DailyBuild-FAILURE</th> >> ${HTML_MAIL_PATH}
 352     echo             </tr> >> ${HTML_MAIL_PATH}
 353     echo             <tr> >> ${HTML_MAIL_PATH}
 354     echo                 <th align="right" style="color: rgb(${FAILURE_RGB});font-size:15px">DailyBuild Is A Good Job!</th> >> ${HTML_MAIL_PATH}
 355 fi
 356 echo             </tr> >> ${HTML_MAIL_PATH}
 357 echo </table> >> ${HTML_MAIL_PATH}
 358 echo ‘‘ >> ${HTML_MAIL_PATH}
 359 
 360 # 生成邮件头与表格之间的空行
 361 echo <table border="0" cellpadding="0" cellpadding="2" width="100%" style="background-color:rgb(255,255,255);border-collapse:collapse;font-size:3px;color: rgb(255, 255, 255)"> >> ${HTML_MAIL_PATH}
 362 echo             <tr> >> ${HTML_MAIL_PATH}
 363 echo                 <th align="left" valign="top">DailyBuild Is A Good Job!</th> >> ${HTML_MAIL_PATH}
 364 echo             </tr> >> ${HTML_MAIL_PATH}
 365 echo </table> >> ${HTML_MAIL_PATH}
 366 echo ‘‘ >> ${HTML_MAIL_PATH}
 367 
 368 # 生成邮件的第一个表格,内容是Job名、编译URL、开始和结束时间
 369 echo <table border="1" bordercolor="black"  width="100%" cellspacing="0" cellpadding="1" style="border-collapse:collapse;font-family:微软雅黑;font-size:17px;"> >> ${HTML_MAIL_PATH}
 370 echo             <tr> >> ${HTML_MAIL_PATH}
 371 echo                 <th align="left" width="25%" style="background-color: rgb(204, 255, 255);">DailyBuild Job名</th> >> ${HTML_MAIL_PATH}
 372 GenHtmlTableContent th "204, 255, 102" ${DB_JOB_NAME}(<a href="http://www.mamicode.com/${DB_JOB_URL}">点击此处</a>进入Job主页)
 373 echo             </tr> >> ${HTML_MAIL_PATH}
 374 echo             <tr> >> ${HTML_MAIL_PATH}
 375 if [[ ${TRIGGER_USER} = "自动触发" ]];then
 376     GenHtmlTableContent th "204, 255, 255" "触发方式"
 377 else
 378     GenHtmlTableContent th "204, 255, 255" "触发者"
 379 fi
 380 GenHtmlTableContent th "204, 255, 102" "${TRIGGER_USER}"
 381 echo             </tr> >> ${HTML_MAIL_PATH}
 382 echo             <tr> >> ${HTML_MAIL_PATH}
 383 GenHtmlTableContent th "204, 255, 255" "代码是否有更新"
 384 if [[ ${DB_IS_CODE_UPDATE} = 0 ]];then
 385     GenHtmlTableContent th "204, 255, 102" ""
 386 else
 387     GenHtmlTableContent th "204, 255, 102" ""
 388 fi
 389 echo             </tr> >> ${HTML_MAIL_PATH}
 390 echo             <tr> >> ${HTML_MAIL_PATH}
 391 GenHtmlTableContent th "204, 255, 255" "未处理问题总数"
 392 GenHtmlTableContent th "204, 255, 102" "${UNSOVLED_PROBLEM_NUM}"
 393 echo             </tr> >> ${HTML_MAIL_PATH}
 394 echo             <tr> >> ${HTML_MAIL_PATH}
 395 GenHtmlTableContent th "204, 255, 255" "构建开始时间"
 396 GenHtmlTableContent th "204, 255, 102" "${DB_START_TIME}"
 397 echo             </tr> >> ${HTML_MAIL_PATH}
 398 echo             <tr> >> ${HTML_MAIL_PATH}
 399 GenHtmlTableContent th "204, 255, 255" "构建结束时间"
 400 GenHtmlTableContent th "204, 255, 102" "${DB_END_TIME}"
 401 echo             </tr> >> ${HTML_MAIL_PATH}
 402 echo             <tr> >> ${HTML_MAIL_PATH}
 403 if [[ -z ${DB_STATUS} ]];then
 404     GenHtmlTableContent th "204, 255, 255" "构建失败原因"
 405     GenHtmlTableContent th "204, 255, 102" <FONT color=red>获取DailyBuild状态异常!</FONT><a href="http://www.mamicode.com/${DB_JOB_URL}${DB_BUILD_NUMBER}/consoleFull">点击此处</a>查看详细日志;<a href="http://www.mamicode.com/${WIKI_DB_PROBLEM}">点击此处</a>查看解决办法
 406 elif [[ ${DB_STATUS} != 0 ]];then
 407     GenHtmlTableContent th "204, 255, 255" "构建失败原因"
 408     GenHtmlTableContent th "204, 255, 102" "<FONT color=red>${DB_STATUS_MESSAGE}!</FONT><a href=http://www.mamicode.com/${DB_JOB_URL}${DB_BUILD_NUMBER}/consoleFull>点击此处查看详细日志;点击此处查看解决办法"
 409 else
 410     GenHtmlTableContent th "204, 255, 255" "构建日志地址"
 411     GenHtmlTableContent th "204, 255, 102" <a href="http://www.mamicode.com/${DB_JOB_URL}${DB_BUILD_NUMBER}/consoleFull">点击此处</a>查看详细日志
 412 fi
 413 echo             </tr> >> ${HTML_MAIL_PATH}
 414 echo </table> >> ${HTML_MAIL_PATH}
 415 echo ‘‘ >> ${HTML_MAIL_PATH}
 416 
 417 # 生成邮件第二个表格,内容是编译的数据
 418 echo <br></br> >> ${HTML_MAIL_PATH}
 419 echo <FONT face=微软雅黑 size=4><b>编译</b></FONT> >> ${HTML_MAIL_PATH}
 420 echo <table border="1" bordercolor="black" width="100%" cellspacing="0" cellpadding="3" style="border-collapse:collapse;font-family:Arial;color: rgb(255, 255, 255)"> >> ${HTML_MAIL_PATH}
 421 echo             <tr> >> ${HTML_MAIL_PATH}
 422 if [[ -n `echo ${DB_STATUS} | grep -E ^1|^2` ]];then
 423     echo                 <th align="left" width="25%" rowspan="0" style="background-color: rgb(${FAILURE_RGB});">War Name</th> >> ${HTML_MAIL_PATH}
 424     echo             </tr> >> ${HTML_MAIL_PATH}
 425     echo             <tr> >> ${HTML_MAIL_PATH}
 426     GenHtmlTableContent td "${FAILURE_RGB}" "NA"
 427 else
 428     echo                 <th align="left" width="25%" rowspan="0" style="background-color: rgb(${SUCCESS_RGB});">War Name</th> >> ${HTML_MAIL_PATH}
 429     echo             </tr> >> ${HTML_MAIL_PATH}
 430     echo             <tr> >> ${HTML_MAIL_PATH}
 431     GenHtmlTableContent td "219, 255, 180" "${DB_WAR_NAME}"
 432 fi
 433 echo             </tr> >> ${HTML_MAIL_PATH}
 434 echo </table> >> ${HTML_MAIL_PATH}
 435 echo ‘‘ >> ${HTML_MAIL_PATH}
 436 
 437 # 生成邮件第三个表格,内容是单元测试&代码质量检查的数据
 438 echo <br></br> >> ${HTML_MAIL_PATH}
 439 echo <FONT face=微软雅黑 size=4><b>单元测试&代码质量检查</b></FONT> >> ${HTML_MAIL_PATH}
 440 echo <table border="1" bordercolor="black" width="100%" cellspacing="0" cellpadding="3" style="border-collapse:collapse;font-family:Arial;color: rgb(255, 255, 255)"> >> ${HTML_MAIL_PATH}
 441 echo             <tr> >> ${HTML_MAIL_PATH}
 442 if [[ ${IS_SKIP_UNIT} == "Yes" ]] && [[ -n `echo ${DB_STATUS} | grep -E ^0|^4|^5` ]];then
 443     GenHtmlTableContent th "${SUCCESS_RGB}" "您已选择跳过单元测试&代码质量检查"
 444     echo             </tr> >> ${HTML_MAIL_PATH}
 445     echo </table> >> ${HTML_MAIL_PATH}
 446 elif [[ ${IS_SKIP_UNIT} == "Yes" ]] && [[ -n `echo ${DB_STATUS} | grep -E ^1|^2` ]];then
 447     GenHtmlTableContent th "${FAILURE_RGB}" "您已选择跳过单元测试&代码质量检查"
 448     echo             </tr> >> ${HTML_MAIL_PATH}
 449     echo </table> >> ${HTML_MAIL_PATH}
 450 elif [[ ${IS_SKIP_UNIT} == "No" ]];then
 451     # 表格的第一行
 452     if [[ -z ${CI_MVN_GROUP_ID} ]] || [[ -z ${CI_MVN_ARTIFACT_ID} ]] || [[ -z ${CI_SONAR_BARNCH} ]];then
 453         echo                 <th align="left" width="25%" rowspan="2" style="background-color: rgb(${FAILURE_RGB});">Sonar名</th> >> ${HTML_MAIL_PATH}
 454     else
 455            echo                 <th align="left" width="25%" rowspan="2" style="background-color: rgb(${SUCCESS_RGB});">Sonar名</th> >> ${HTML_MAIL_PATH}
 456     fi
 457 
 458     if [[ -n `echo ${DB_STATUS} | grep -E ^1|^2` ]];then
 459         echo                 <th align="center" colspan="4" style="background-color: rgb(${FAILURE_RGB});">代码质量检查</th> >> ${HTML_MAIL_PATH}
 460         echo                 <th align="center" colspan="3" style="background-color: rgb(${FAILURE_RGB});">单元测试</th> >> ${HTML_MAIL_PATH}
 461         echo             </tr> >> ${HTML_MAIL_PATH}
 462     elif [[ -n `echo ${DB_STATUS} | grep -E ^3` ]];then
 463         if [[ ${DB_STATUS} = 36 ]] || [[ ${DB_STATUS} = 37 ]];then
 464             if [[ `echo "${QS_SONAR_BLOCKER_VIOLATIONS}<${CI_SONAR_BLOCKER_VIOLATIONS}" | bc` != 0 ]] || [[ `echo "${QS_SONAR_CRITICAL_VIOLATIONS}<${CI_SONAR_CRITICAL_VIOLATIONS}" | bc` != 0 ]];then
 465                 echo                 <th align="center" colspan="4" style="background-color: rgb(${FAILURE_RGB});">代码质量检查</th> >> ${HTML_MAIL_PATH}
 466             else
 467                 echo                 <th align="center" colspan="4" style="background-color: rgb(${SUCCESS_RGB});">代码质量检查</th> >> ${HTML_MAIL_PATH}
 468             fi
 469         
 470             if [[ `echo "${QS_SONAR_COVERAGE}>${CI_SONAR_COVERAGE}" | bc` != 0 ]] || [[ `echo "${QS_SONAR_TEST_SUCCESS_DENSITY}>${CI_SONAR_TEST_SUCCESS_DENSITY}" | bc` != 0 ]];then
 471                 echo                 <th align="center" colspan="3" style="background-color: rgb(${FAILURE_RGB});">单元测试</th> >> ${HTML_MAIL_PATH}
 472             else
 473                 echo                 <th align="center" colspan="3" style="background-color: rgb(${SUCCESS_RGB});">单元测试</th> >> ${HTML_MAIL_PATH}
 474             fi
 475         else
 476             echo                 <th align="center" colspan="4" style="background-color: rgb(${FAILURE_RGB});">代码质量检查</th> >> ${HTML_MAIL_PATH}
 477             echo                 <th align="center" colspan="3" style="background-color: rgb(${FAILURE_RGB});">单元测试</th> >> ${HTML_MAIL_PATH}
 478         fi
 479             
 480         echo             </tr> >> ${HTML_MAIL_PATH}
 481     else
 482         echo                 <th align="center" colspan="4" style="background-color: rgb(${SUCCESS_RGB});">代码质量检查</th> >> ${HTML_MAIL_PATH}
 483         echo                 <th align="center" colspan="3" style="background-color: rgb(${SUCCESS_RGB});">单元测试</th> >> ${HTML_MAIL_PATH}
 484         echo             </tr> >> ${HTML_MAIL_PATH}
 485     fi
 486     
 487     # 表格的第二行
 488     echo             <tr> >> ${HTML_MAIL_PATH}
 489     
 490     if [[ -n ${CI_SONAR_LINES} ]];then
 491         GenHtmlTableContent th "${SUCCESS_RGB}" "代码行数"
 492     else
 493         GenHtmlTableContent th "${FAILURE_RGB}" "代码行数"
 494     fi
 495     
 496     if [[ `echo "${QS_SONAR_BLOCKER_VIOLATIONS}<${CI_SONAR_BLOCKER_VIOLATIONS}" | bc 2>/dev/null` != 0 ]];then
 497         GenHtmlTableContent th "${FAILURE_RGB}" "阻断违规"
 498     else
 499         GenHtmlTableContent th "${SUCCESS_RGB}" "阻断违规"
 500     fi
 501     
 502     if [[ `echo "${QS_SONAR_CRITICAL_VIOLATIONS}<${CI_SONAR_CRITICAL_VIOLATIONS}" | bc 2>/dev/null` != 0 ]];then
 503         GenHtmlTableContent th "${FAILURE_RGB}" "严重违规"
 504     else
 505         GenHtmlTableContent th "${SUCCESS_RGB}" "严重违规"
 506     fi
 507     
 508     if [[ -n ${CI_SONAR_MAJOR_VIOLATIONS} ]];then
 509         GenHtmlTableContent th "${SUCCESS_RGB}" "主要违规"
 510     else
 511         GenHtmlTableContent th "${FAILURE_RGB}" "主要违规"
 512     fi
 513     
 514     if [[ -n ${CI_SONAR_TESTS} ]];then
 515         GenHtmlTableContent th "${SUCCESS_RGB}" "单元测试数"
 516     else
 517         GenHtmlTableContent th "${FAILURE_RGB}" "单元测试数"
 518     fi
 519     
 520     if [[ `echo "${QS_SONAR_COVERAGE}>${CI_SONAR_COVERAGE}" | bc 2>/dev/null` != 0 ]];then
 521         GenHtmlTableContent th "${FAILURE_RGB}" "覆盖率"
 522     else
 523         GenHtmlTableContent th "${SUCCESS_RGB}" "覆盖率"
 524     fi
 525     
 526     if [[ `echo "${QS_SONAR_TEST_SUCCESS_DENSITY}>${CI_SONAR_TEST_SUCCESS_DENSITY}" | bc 2>/dev/null` != 0 ]];then
 527         GenHtmlTableContent th "${FAILURE_RGB}" "成功率"
 528     else
 529         GenHtmlTableContent th "${SUCCESS_RGB}" "成功率"
 530     fi
 531     
 532     echo             </tr> >> ${HTML_MAIL_PATH}
 533     
 534     # 表格的第三行
 535     echo             <tr> >> ${HTML_MAIL_PATH}
 536     if [[ -z ${CI_MVN_GROUP_ID} ]] || [[ -z ${CI_MVN_ARTIFACT_ID} ]] || [[ -z ${CI_SONAR_BARNCH} ]];then
 537         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
 538     else
 539            GenHtmlTableContent td "219, 255, 180" "${CI_MVN_ARTIFACT_ID} ${CI_SONAR_BARNCH}"‘<br><b>(<a href="http://www.mamicode.com/${SONAR_URL}/dashboard/index/${CI_MVN_GROUP_ID}:${CI_MVN_ARTIFACT_ID}:${CI_SONAR_BARNCH}">点击此处</a>查看Sonar数据)</b>
 540     fi
 541     
 542     if [[ -n ${CI_SONAR_LINES} ]];then
 543         GenHtmlTableContent td "219, 255, 180" "${CI_SONAR_LINES}"
 544     else
 545         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
 546     fi
 547     
 548     if [[ -z ${CI_SONAR_BLOCKER_VIOLATIONS} ]];then
 549         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
 550     else
 551         if [[ `echo "${QS_SONAR_BLOCKER_VIOLATIONS}<${CI_SONAR_BLOCKER_VIOLATIONS}" | bc` != 0 ]];then
 552             GenHtmlTableContent td "${FAILURE_RGB}" "${CI_SONAR_BLOCKER_VIOLATIONS}"
 553         else
 554             GenHtmlTableContent td "219, 255, 180" "${CI_SONAR_BLOCKER_VIOLATIONS}"
 555         fi
 556     fi
 557     
 558     if [[ -z ${CI_SONAR_CRITICAL_VIOLATIONS} ]];then
 559         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
 560     else
 561         if [[ `echo "${QS_SONAR_CRITICAL_VIOLATIONS}<${CI_SONAR_CRITICAL_VIOLATIONS}" | bc` != 0 ]];then
 562             GenHtmlTableContent td "${FAILURE_RGB}" "${CI_SONAR_CRITICAL_VIOLATIONS}"
 563         else
 564             GenHtmlTableContent td "219, 255, 180" "${CI_SONAR_CRITICAL_VIOLATIONS}"
 565         fi
 566     fi
 567     
 568     if [[ -n ${CI_SONAR_MAJOR_VIOLATIONS} ]];then
 569         GenHtmlTableContent td "219, 255, 180" "${CI_SONAR_MAJOR_VIOLATIONS}"
 570     else
 571         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
 572     fi
 573     
 574     if [[ -n ${CI_SONAR_TESTS} ]];then
 575         GenHtmlTableContent td "219, 255, 180" "${CI_SONAR_TESTS}"
 576     else
 577         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
 578     fi
 579     
 580     if [[ -z ${CI_SONAR_COVERAGE} ]];then
 581         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
 582     else
 583         if [[ `echo "${QS_SONAR_COVERAGE}>${CI_SONAR_COVERAGE}" | bc` != 0 ]];then
 584             GenHtmlTableContent td "${FAILURE_RGB}" "${CI_SONAR_COVERAGE}%"
 585         else
 586             GenHtmlTableContent td "219, 255, 180" "${CI_SONAR_COVERAGE}%"
 587         fi
 588     fi
 589     
 590     if [[ -z ${CI_SONAR_TEST_SUCCESS_DENSITY} ]];then
 591         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
 592     else
 593         if [[ `echo "${QS_SONAR_TEST_SUCCESS_DENSITY}>${CI_SONAR_TEST_SUCCESS_DENSITY}" | bc` != 0 ]];then
 594             GenHtmlTableContent td "${FAILURE_RGB}" "${CI_SONAR_TEST_SUCCESS_DENSITY}%"
 595         else
 596             GenHtmlTableContent td "219, 255, 180" "${CI_SONAR_TEST_SUCCESS_DENSITY}%"
 597         fi
 598     fi
 599 fi
 600 echo             </tr> >> ${HTML_MAIL_PATH}
 601 echo </table> >> ${HTML_MAIL_PATH}
 602 echo ‘‘ >> ${HTML_MAIL_PATH}
 603 
 604 # 生成邮件第四个表格,内容是发布测试环境的数据
 605 echo <br></br> >> ${HTML_MAIL_PATH}
 606 echo <FONT face=微软雅黑 size=4><b>发布测试环境</b></FONT> >> ${HTML_MAIL_PATH}
 607 echo <table border="1" bordercolor="black" width="100%" cellspacing="0" cellpadding="3" style="border-collapse:collapse;font-family:Arial;color: rgb(255, 255, 255)"> >> ${HTML_MAIL_PATH}
 608 echo             <tr> >> ${HTML_MAIL_PATH}
 609 if [[ ${IS_SKIP_DEPLOY} == "Yes" ]] && [[ -n `echo ${DB_STATUS} | grep -E ^0|^5` ]];then
 610     GenHtmlTableContent th "${SUCCESS_RGB}" "您已选择跳过发布测试环境"
 611     echo             </tr> >> ${HTML_MAIL_PATH}
 612     echo </table> >> ${HTML_MAIL_PATH}
 613 elif [[ ${IS_SKIP_DEPLOY} == "Yes" ]] && [[ -n `echo ${DB_STATUS} | grep -E ^1|^2|^3` ]];then
 614     GenHtmlTableContent th "${FAILURE_RGB}" "您已选择跳过发布测试环境"
 615     echo             </tr> >> ${HTML_MAIL_PATH}
 616     echo </table> >> ${HTML_MAIL_PATH}
 617 elif [[ ${IS_SKIP_DEPLOY} == "No" ]];then
 618     if [[ -n `echo ${DB_STATUS} | grep -E ^1|^2|^3` ]];then
 619         echo                 <th align="left" width="25%" rowspan="0" style="background-color: rgb(${FAILURE_RGB});">Tomcat编号</th> >> ${HTML_MAIL_PATH}
 620         GenHtmlTableContent th "${FAILURE_RGB}" "Host IP"
 621         GenHtmlTableContent th "${FAILURE_RGB}" "启动用时"
 622         GenHtmlTableContent th "${FAILURE_RGB}" "HeathCheck"
 623         GenHtmlTableContent th "${FAILURE_RGB}" "责任人"
 624         echo             </tr> >> ${HTML_MAIL_PATH}
 625         echo             <tr> >> ${HTML_MAIL_PATH}
 626         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
 627         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
 628         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
 629         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
 630         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
 631     elif [[ -n `echo ${DB_STATUS} | grep -E ^4` ]];then
 632         echo                 <th align="left" width="25%" rowspan="0" style="background-color: rgb(${FAILURE_RGB});">Tomcat编号</th> >> ${HTML_MAIL_PATH}
 633         GenHtmlTableContent th "${FAILURE_RGB}" "Host IP"
 634         GenHtmlTableContent th "${FAILURE_RGB}" "启动用时"
 635         GenHtmlTableContent th "${FAILURE_RGB}" "HeathCheck"
 636         GenHtmlTableContent th "${FAILURE_RGB}" "责任人"
 637         echo             </tr> >> ${HTML_MAIL_PATH}
 638         echo             <tr> >> ${HTML_MAIL_PATH}
 639         GenHtmlTableContent td "${FAILURE_RGB}" "${DB_TOMCAT_ID}"
 640         GenHtmlTableContent td "${FAILURE_RGB}" "${DB_TOMCAT_HOST_IP}"
 641         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
 642         if [[ -z ${DB_TOMCAT_HEATHCKECK_URL} ]];then
 643             GenHtmlTableContent td "${FAILURE_RGB}" "NA"
 644         else
 645             GenHtmlTableContent td "${FAILURE_RGB}" "${DB_TOMCAT_HEATHCKECK_URL}"
 646         fi
 647         GenHtmlTableContent td "${FAILURE_RGB}" "${DB_TOMCAT_OWNER}"
 648     else
 649         echo                 <th align="left" width="25%" rowspan="0" style="background-color: rgb(${SUCCESS_RGB});">Tomcat编号</th> >> ${HTML_MAIL_PATH}
 650         GenHtmlTableContent th "${SUCCESS_RGB}" "Host IP"
 651         GenHtmlTableContent th "${SUCCESS_RGB}" "启动用时"
 652         GenHtmlTableContent th "${SUCCESS_RGB}" "HeathCheck"
 653         GenHtmlTableContent th "${SUCCESS_RGB}" "责任人"
 654         echo             </tr> >> ${HTML_MAIL_PATH}
 655         echo             <tr> >> ${HTML_MAIL_PATH}
 656         GenHtmlTableContent td "219, 255, 180" "${DB_TOMCAT_ID}"
 657         GenHtmlTableContent td "219, 255, 180" "${DB_TOMCAT_HOST_IP}"
 658         GenHtmlTableContent td "219, 255, 180" "${DB_TOMCAT_STARTUP_TIME}"
 659         GenHtmlTableContent td "219, 255, 180" "${DB_TOMCAT_HEATHCKECK_URL}"
 660         GenHtmlTableContent td "219, 255, 180" "${DB_TOMCAT_OWNER}"
 661     fi
 662 fi
 663 echo             </tr> >> ${HTML_MAIL_PATH}
 664 echo </table> >> ${HTML_MAIL_PATH}
 665 echo ‘‘ >> ${HTML_MAIL_PATH}
 666 
 667 # 生成邮件第五个表格,内容是自动化测试的数据
 668 echo <br></br> >> ${HTML_MAIL_PATH}
 669 echo <FONT face=微软雅黑 size=4><b>自动化测试</b></FONT> >> ${HTML_MAIL_PATH}
 670 echo <table border="1" bordercolor="black" width="100%" cellspacing="0" cellpadding="3" style="border-collapse:collapse;font-family:Arial;color: rgb(255, 255, 255)"> >> ${HTML_MAIL_PATH}
 671 echo             <tr> >> ${HTML_MAIL_PATH}
 672 if [[ ${IS_SKIP_AUTO} == "Yes" ]] && [[ ${DB_STATUS} = 0 ]];then
 673     GenHtmlTableContent th "${SUCCESS_RGB}" "您已选择跳过自动化测试"
 674     echo             </tr> >> ${HTML_MAIL_PATH}
 675     echo </table> >> ${HTML_MAIL_PATH}
 676 elif [[ ${IS_SKIP_AUTO} == "Yes" ]] && [[ ${DB_STATUS} != 0 ]];then
 677     GenHtmlTableContent th "${FAILURE_RGB}" "您已选择跳过自动化测试"
 678     echo             </tr> >> ${HTML_MAIL_PATH}
 679     echo </table> >> ${HTML_MAIL_PATH}
 680 elif [[ ${IS_SKIP_AUTO} == "No" ]];then
 681     if [[ -n ${AUTO_AUTO_ID} ]];then
 682         AUTO_DATA=http://www.mamicode.com/`curl -s ${AUTOTJ_API_EXCE_BYID}?auto_id=${AUTO_AUTO_ID} | sed -e s/\([{,]\)\s*/\1\n/g -e s/}/\n}/g`
 683         AUTO_BUILD_ID=`echo -e "${AUTO_DATA}" | sed /build_id/!d | sed s/.*://g | sed s/"// | sed s/".*// | sed s/#//`
 684         AUTO_RUN_ENV_NAME=`echo -e "${AUTO_DATA}" | sed /run_env_name/!d | sed s/.*://g | sed s/"// | sed s/".*//`
 685         AUTO_START_RUNDATE=`echo -e "${AUTO_DATA}" | sed /start_rundate/!d | sed s/.*://g | sed s/"// | sed s/".*//`
 686         AUTO_START_RUNTIME=`echo -e "${AUTO_DATA}" | sed /start_runtime/!d | sed s/"start_runtime":// | sed s/"// | sed s/".*//`
 687         AUTO_RUN_USE_TIME=`echo -e "${AUTO_DATA}" | sed /run_use_time/!d | sed s/.*://g | sed s/"// | sed s/".*//`
 688         AUTO_SCENARIO_NUM=`echo -e "${AUTO_DATA}" | sed /scenario_num/!d | sed s/.*://g | sed s/"// | sed s/".*//`
 689         AUTO_SCENARIO_P0=`echo -e "${AUTO_DATA}" | sed /scenario_p0/!d | sed s/.*://g | sed s/"// | sed s/".*//`
 690         AUTO_SCENARIO_P1=`echo -e "${AUTO_DATA}" | sed /scenario_p1/!d | sed s/.*://g | sed s/"// | sed s/".*//`
 691         AUTO_SCENARIO_P2=`echo -e "${AUTO_DATA}" | sed /scenario_p2/!d | sed s/.*://g | sed s/"// | sed s/".*//`
 692         AUTO_PASS_RATE=`echo -e "${AUTO_DATA}" | sed /pass_rate/!d | sed s/.*://g | sed s/"// | sed s/".*// | sed s/%//`
 693         AUTO_REPORT_URL=`echo -e "${AUTO_DATA}" | sed /report_url/!d | sed s/.*:"\(.*\)"/\1/`
 694         echo                 <th align="left" width="25%" style="background-color: rgb(${SUCCESS_RGB});">自动化Job名</th> >> ${HTML_MAIL_PATH}
 695         GenHtmlTableContent th "${SUCCESS_RGB}" "被测环境"
 696         GenHtmlTableContent th "${SUCCESS_RGB}" "开始时间"
 697         GenHtmlTableContent th "${SUCCESS_RGB}" "运行用时"
 698         GenHtmlTableContent th "${SUCCESS_RGB}" "场景总数"
 699         GenHtmlTableContent th "${SUCCESS_RGB}" "P0"
 700         GenHtmlTableContent th "${SUCCESS_RGB}" "P1"
 701         GenHtmlTableContent th "${SUCCESS_RGB}" "P2"
 702         if [[ `echo "${QS_AUTO_PASS_RATE}>${AUTO_PASS_RATE}" | bc` != 0 ]];then
 703             GenHtmlTableContent th "${FAILURE_RGB}" "通过率"
 704         else
 705             GenHtmlTableContent th "${SUCCESS_RGB}" "通过率"
 706         fi
 707         echo             </tr> >> ${HTML_MAIL_PATH}
 708         echo             <tr> >> ${HTML_MAIL_PATH}
 709         GenHtmlTableContent td "219, 255, 180" ${AUTO_JOB_NAME}<br><b>(<a href="http://www.mamicode.com/${AUTO_REPORT_URL}">点击此处</a>查看自动化report)</b>
 710         GenHtmlTableContent td "219, 255, 180" "${AUTO_RUN_ENV_NAME}"
 711         GenHtmlTableContent td "219, 255, 180" "${AUTO_START_RUNDATE} ${AUTO_START_RUNTIME}"
 712         GenHtmlTableContent td "219, 255, 180" "${AUTO_RUN_USE_TIME}"
 713         GenHtmlTableContent td "219, 255, 180" "${AUTO_SCENARIO_NUM}"
 714         GenHtmlTableContent td "219, 255, 180" "${AUTO_SCENARIO_P0}"
 715         GenHtmlTableContent td "219, 255, 180" "${AUTO_SCENARIO_P1}"
 716         GenHtmlTableContent td "219, 255, 180" "${AUTO_SCENARIO_P2}"
 717         if [[ `echo "${QS_AUTO_PASS_RATE}>${AUTO_PASS_RATE}" | bc` != 0 ]];then
 718             GenHtmlTableContent td "${FAILURE_RGB}" "${AUTO_PASS_RATE}%"
 719         else
 720             GenHtmlTableContent td "219, 255, 180" "${AUTO_PASS_RATE}%"
 721         fi
 722         echo             </tr> >> ${HTML_MAIL_PATH}
 723         echo </table> >> ${HTML_MAIL_PATH}
 724         echo ‘‘ >> ${HTML_MAIL_PATH}
 725     elif [[ -z ${AUTO_AUTO_ID} ]] && [[ -n `echo ${DB_STATUS} | grep -E ^1|^2|^3|^4` ]];then
 726         echo                 <th align="left" width="25%" style="background-color: rgb(${FAILURE_RGB});">自动化Job名</th> >> ${HTML_MAIL_PATH}
 727         GenHtmlTableContent th "${FAILURE_RGB}" "被测环境"
 728         GenHtmlTableContent th "${FAILURE_RGB}" "运行目的"
 729         GenHtmlTableContent th "${FAILURE_RGB}" "开始时间"
 730         GenHtmlTableContent th "${FAILURE_RGB}" "运行用时"
 731         GenHtmlTableContent th "${FAILURE_RGB}" "场景总数"
 732         GenHtmlTableContent th "${FAILURE_RGB}" "P0"
 733         GenHtmlTableContent th "${FAILURE_RGB}" "P1"
 734         GenHtmlTableContent th "${FAILURE_RGB}" "P2"
 735         GenHtmlTableContent th "${FAILURE_RGB}" "通过率"
 736         echo             </tr> >> ${HTML_MAIL_PATH}
 737         echo             <tr> >> ${HTML_MAIL_PATH}
 738         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
 739         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
 740         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
 741         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
 742         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
 743         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
 744         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
 745         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
 746         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
 747         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
 748         echo             </tr> >> ${HTML_MAIL_PATH}
 749         echo </table> >> ${HTML_MAIL_PATH}
 750         echo ‘‘ >> ${HTML_MAIL_PATH}
 751     elif [[ -z ${AUTO_AUTO_ID} ]] && [[ -n `echo ${DB_STATUS} | grep -E ^5` ]];then
 752         echo                 <th align="left" width="25%" style="background-color: rgb(${SUCCESS_RGB});">自动化Job名</th> >> ${HTML_MAIL_PATH}
 753         GenHtmlTableContent th "${FAILURE_RGB}" "被测环境"
 754         GenHtmlTableContent th "${FAILURE_RGB}" "运行目的"
 755         GenHtmlTableContent th "${FAILURE_RGB}" "开始时间"
 756         GenHtmlTableContent th "${FAILURE_RGB}" "运行用时"
 757         GenHtmlTableContent th "${FAILURE_RGB}" "场景总数"
 758         GenHtmlTableContent th "${FAILURE_RGB}" "P0"
 759         GenHtmlTableContent th "${FAILURE_RGB}" "P1"
 760         GenHtmlTableContent th "${FAILURE_RGB}" "P2"
 761         GenHtmlTableContent th "${FAILURE_RGB}" "通过率"
 762         echo             </tr> >> ${HTML_MAIL_PATH}
 763         echo             <tr> >> ${HTML_MAIL_PATH}
 764         GenHtmlTableContent td "219, 255, 180" "${AUTO_JOB_NAME}"
 765         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
 766         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
 767         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
 768         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
 769         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
 770         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
 771         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
 772         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
 773         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
 774         echo             </tr> >> ${HTML_MAIL_PATH}
 775         echo </table> >> ${HTML_MAIL_PATH}
 776         echo ‘‘ >> ${HTML_MAIL_PATH}
 777     fi
 778 fi
 779 
 780 echo <br></br> >> ${HTML_MAIL_PATH}
 781 echo <FONT face=微软雅黑 size=3>------</FONT> >> ${HTML_MAIL_PATH}
 782 echo </br> >> ${HTML_MAIL_PATH}
 783 echo <FONT face=微软雅黑 size=3>质量标准:阻断违规≤${QS_SONAR_BLOCKER_VIOLATIONS},严重违规≤${QS_SONAR_CRITICAL_VIOLATIONS},单元测试覆盖率≥${QS_SONAR_COVERAGE}%,单元测试成功率≥${QS_SONAR_TEST_SUCCESS_DENSITY}%,自动化测试通过率≥${QS_AUTO_PASS_RATE}%</FONT> >> ${HTML_MAIL_PATH}
 784 
 785 # 发送邮件
 786 SendMail "[DailyBuild - ${DB_BUILD_RESULT}] ${DB_JOB_NAME} Build #${DB_BUILD_NUMBER}" "${DB_MAIL_TO}" "${DB_MAIL_CC_TO}" "${HTML_MAIL_PATH}"
 787 echo Send email to:‘"${DB_MAIL_TO}"
 788 }
 789 
 790 function SendDailyBuildMail_Android()
 791 {
 792 # 函数功能说明
 793 # 生成html邮件,保存至${HTML_MAIL_PATH},并通过邮件发送
 794 # 示例:SENDDBMAIL ${JOB_NAME} ${JOB_URL} ${BUILD_NUMBER} "${MAIL_RECIPIENT}" "${DB_MAIL_CC}"
 795 DB_JOB_NAME=$1
 796 DB_JOB_URL=$2
 797 DB_BUILD_NUMBER=$3
 798 DB_MOBILE_ID=$4
 799 DB_MAIL_TO=$5
 800 DB_MAIL_CC_TO=$6
 801 TRIGGER_USER=$7
 802 IS_SKIP_AUTO=$8
 803 IS_SKIP_UNIT=$9
 804 IS_SKIP_DEPLOY=${10}
 805 QS_SONAR_BLOCKER_VIOLATIONS=${11}
 806 QS_SONAR_CRITICAL_VIOLATIONS=${12}
 807 QS_SONAR_COVERAGE=${13}
 808 QS_SONAR_TEST_SUCCESS_DENSITY=${14}
 809 QS_AUTO_PASS_RATE=${15}
 810 
 811 if [[ ${TRIGGER_USER} = "Poll SCM" ]] || [[ ${TRIGGER_USER} = "IT_Test_SCM_Jenkins" ]];then
 812     TRIGGER_USER="自动触发"
 813 else
 814     TRIGGER_USER=`curl -s ${CMIS_API_HOST}/user/getUserInfoByAdAccount/${TRIGGER_USER}${CMIS_API_AUTH} | sed -e s/\([{,]\)\s*/\1\n/g -e s/}/\n}/g | sed /displayName/!d | sed s/.*://g | sed s/"// | sed s/".*//`
 815 fi
 816 
 817 # 从${SQL_CONTENT}及数据库中获取DailyBuild各种数据
 818 DB_STATUS=`cat ${SQL_CONTENT} | grep -w "${DB_TABLE_NAME}.status" | sed s/.*=//`
 819 DB_START_TIME=`cat ${SQL_CONTENT} | grep -w "${DB_TABLE_NAME}.start_time" | sed s/.*=//`
 820 DB_IS_CODE_UPDATE=`cat ${SQL_CONTENT} | grep -w "${DB_TABLE_NAME}.is_code_update" | sed s/.*=//`
 821 DB_END_TIME=`cat ${SQL_CONTENT} | grep -w "${DB_TABLE_NAME}.end_time" | sed s/.*=//`
 822 DB_JOB_ID=`cat ${SQL_CONTENT} | grep -w "${DB_TABLE_NAME}.jenkins_job_id" | sed s/.*=//`
 823 
 824 CI_SONAR_LINES=`cat ${SQL_CONTENT} | grep -w "${CI_TABLE_NAME}.sonar_lines" | sed s/.*=//`
 825 CI_SONAR_BLOCKER_VIOLATIONS=`cat ${SQL_CONTENT} | grep -w "${CI_TABLE_NAME}.sonar_blocker_violations" | sed s/.*=//`
 826 CI_SONAR_CRITICAL_VIOLATIONS=`cat ${SQL_CONTENT} | grep -w "${CI_TABLE_NAME}.sonar_critical_violations" | sed s/.*=//`
 827 CI_SONAR_MAJOR_VIOLATIONS=`cat ${SQL_CONTENT} | grep -w "${CI_TABLE_NAME}.sonar_major_violations" | sed s/.*=//`
 828 CI_SONAR_TESTS=`cat ${SQL_CONTENT} | grep -w "${CI_TABLE_NAME}.sonar_tests" | sed s/.*=//`
 829 CI_SONAR_COVERAGE=`cat ${SQL_CONTENT} | grep -w "${CI_TABLE_NAME}.sonar_coverage" | sed s/.*=//`
 830 CI_SONAR_TEST_SUCCESS_DENSITY=`cat ${SQL_CONTENT} | grep -w "${CI_TABLE_NAME}.sonar_test_success_density" | sed s/.*=//`
 831 CI_SONAR_BARNCH=`cat ${SQL_CONTENT} | grep -w "${CI_TABLE_NAME}.sonar_branch" | sed s/.*=//`
 832 CI_MVN_GROUP_ID=`cat ${SQL_CONTENT} | grep -w "${CI_TABLE_NAME}.mvn_group_id" | sed s/.*=//`
 833 CI_MVN_ARTIFACT_ID=`cat ${SQL_CONTENT} | grep -w "${CI_TABLE_NAME}.mvn_artifact_id" | sed s/.*=//`
 834 CI_MVN_NAME=`cat ${SQL_CONTENT} | grep -w "${CI_TABLE_NAME}.mvn_name" | sed s/.*=//`
 835 
 836 # 以下为临时代码,等框架组完成插入数据的功能后,再切换
 837 # AUTO_AUTO_ID=`cat ${SQL_CONTENT} | grep -w "${AUTO_TABLE_NAME}.auto_id" | sed s/.*=//`
 838 BUILD_ID=`cat ${SQL_CONTENT} | grep -w "${DB_TABLE_NAME}.token" | sed s/.*=// | sed s/.*_//`
 839 AUTO_JOB_DATA=http://www.mamicode.com/`cat ${JENKINS_JOB_PATH}/${DB_JOB_NAME}/builds/${BUILD_ID}/log | tail -14`
 840 
 841 SELETE_DB_STATUS_MESSAGE="SET NAMES ‘utf8‘;SELECT message FROM cmis.scm_cmis_daily_build_status where id="""${DB_STATUS}""
 842 DB_STATUS_MESSAGE=`db_common/mysql_sdbc.sh -h ${CMIS_DB_IP} -p ${CMIS_DB_PORT} -u ${CMIS_DB_USERNAME} -w ${CMIS_DB_PASSWORD} -d ${CMIS_DB_NAME} -c "${SELETE_DB_STATUS_MESSAGE}" -l ${CMIS_DB_LOG} | sed -n 3p`
 843 
 844 DB_MOBILE_INFO=`curl -s "${CMIS_API_HOST}/container/getMobileInfoByMobileCode/${DB_MOBILE_ID}${CMIS_API_AUTH}" | sed -e s/\([{,]\)\s*/\1\n/g -e s/}/\n}/g`
 845 DB_MOBILE_HOST_IP=`echo -e "${DB_MOBILE_INFO}" | sed /"hostIp"/!d | sed s/"hostIp":"\(.*\)",/\1/`
 846 DB_MOBILE_TYPE=`echo -e "${DB_MOBILE_INFO}" | sed /"mobileModel"/!d | sed s/"mobileModel":"\(.*\)",/\1/`
 847 DB_MOBILE_SN=`echo -e "${DB_MOBILE_INFO}" | sed /"serialNumber"/!d | sed s/"serialNumber":"\(.*\)",/\1/`
 848 DB_MOBILE_OWNER=`echo -e "${DB_MOBILE_INFO}" | sed /"ownerUserDisplayName"/!d | sed s/"ownerUserDisplayName":"\(.*\)",/\1/`
 849 
 850 UNSOVLED_PROBLEM_NUM=`curl -s "${AUTOTJ_API_GET_PROBLEM}?job_list\[\]=${DB_JOB_ID}&job_list\[\]=${AUTO_JOB_ID}" | sed -e s/\([{,]\)\s*/\1\n/g -e s/}/\n}/g | sed /total/!d | sed s/.*://g | sed s/"// | sed s/".*//`
 851 
 852 # 生成邮件头
 853 rm -rf ${HTML_MAIL_PATH}
 854 if [[ ${DB_STATUS} = 0 ]];then
 855     DB_BUILD_RESULT="SUCCESS"
 856     echo <table border="0" cellpadding="0" width="100%" style="background-color:rgb(${SUCCESS_RGB});border-collapse:collapse;font-family:微软雅黑;font-size:35px;color: rgb(255, 255, 255)"> >> ${HTML_MAIL_PATH}
 857     echo             <tr> >> ${HTML_MAIL_PATH}
 858     echo                 <th align="left" valign="top">DailyBuild-SUCCESS</th> >> ${HTML_MAIL_PATH}
 859     echo             </tr> >> ${HTML_MAIL_PATH}
 860     echo             <tr> >> ${HTML_MAIL_PATH}
 861     echo                 <th align="right" style="color: rgb(${SUCCESS_RGB});font-size:15px">DailyBuild Is</th> >> ${HTML_MAIL_PATH}
 862 else
 863     DB_BUILD_RESULT="FAILURE"
 864     echo <table border="0" cellpadding="0" width="100%" style="background-color:rgb(${FAILURE_RGB});border-collapse:collapse;font-family:微软雅黑;font-size:35px;color: rgb(255, 255, 255)"> >> ${HTML_MAIL_PATH}
 865     echo             <tr> >> ${HTML_MAIL_PATH}
 866     echo                 <th align="left" valign="top">DailyBuild-FAILURE</th> >> ${HTML_MAIL_PATH}
 867     echo             </tr> >> ${HTML_MAIL_PATH}
 868     echo             <tr> >> ${HTML_MAIL_PATH}
 869     echo                 <th align="right" style="color: rgb(${FAILURE_RGB});font-size:15px">DailyBuild Is A Good Job!</th> >> ${HTML_MAIL_PATH}
 870 fi
 871 echo             </tr> >> ${HTML_MAIL_PATH}
 872 echo </table> >> ${HTML_MAIL_PATH}
 873 echo ‘‘ >> ${HTML_MAIL_PATH}
 874 
 875 # 生成邮件头与表格之间的空行
 876 echo <table border="0" cellpadding="0" cellpadding="2" width="100%" style="background-color:rgb(255,255,255);border-collapse:collapse;font-size:3px;color: rgb(255, 255, 255)"> >> ${HTML_MAIL_PATH}
 877 echo             <tr> >> ${HTML_MAIL_PATH}
 878 echo                 <th align="left" valign="top">DailyBuild Is A Good Job!</th> >> ${HTML_MAIL_PATH}
 879 echo             </tr> >> ${HTML_MAIL_PATH}
 880 echo </table> >> ${HTML_MAIL_PATH}
 881 echo ‘‘ >> ${HTML_MAIL_PATH}
 882 
 883 # 生成邮件的第一个表格,内容是Job名、编译URL、开始和结束时间
 884 echo <table border="1" bordercolor="black"  width="100%" cellspacing="0" cellpadding="1" style="border-collapse:collapse;font-family:微软雅黑;font-size:17px;"> >> ${HTML_MAIL_PATH}
 885 echo             <tr> >> ${HTML_MAIL_PATH}
 886 echo                 <th align="left" width="25%" style="background-color: rgb(204, 255, 255);">DailyBuild Job名</th> >> ${HTML_MAIL_PATH}
 887 GenHtmlTableContent th "204, 255, 102" ${DB_JOB_NAME}(<a href="http://www.mamicode.com/${DB_JOB_URL}">点击此处</a>进入Job主页)
 888 echo             </tr> >> ${HTML_MAIL_PATH}
 889 echo             <tr> >> ${HTML_MAIL_PATH}
 890 if [[ ${TRIGGER_USER} = "自动触发" ]];then
 891     GenHtmlTableContent th "204, 255, 255" "触发方式"
 892 else
 893     GenHtmlTableContent th "204, 255, 255" "触发者"
 894 fi
 895 GenHtmlTableContent th "204, 255, 102" "${TRIGGER_USER}"
 896 echo             </tr> >> ${HTML_MAIL_PATH}
 897 echo             <tr> >> ${HTML_MAIL_PATH}
 898 GenHtmlTableContent th "204, 255, 255" "代码是否有更新"
 899 if [[ ${DB_IS_CODE_UPDATE} = 0 ]];then
 900     GenHtmlTableContent th "204, 255, 102" ""
 901 else
 902     GenHtmlTableContent th "204, 255, 102" ""
 903 fi
 904 echo             </tr> >> ${HTML_MAIL_PATH}
 905 echo             <tr> >> ${HTML_MAIL_PATH}
 906 GenHtmlTableContent th "204, 255, 255" "未处理问题总数"
 907 GenHtmlTableContent th "204, 255, 102" "${UNSOVLED_PROBLEM_NUM}"
 908 echo             </tr> >> ${HTML_MAIL_PATH}
 909 echo             <tr> >> ${HTML_MAIL_PATH}
 910 GenHtmlTableContent th "204, 255, 255" "构建开始时间"
 911 GenHtmlTableContent th "204, 255, 102" "${DB_START_TIME}"
 912 echo             </tr> >> ${HTML_MAIL_PATH}
 913 echo             <tr> >> ${HTML_MAIL_PATH}
 914 GenHtmlTableContent th "204, 255, 255" "构建结束时间"
 915 GenHtmlTableContent th "204, 255, 102" "${DB_END_TIME}"
 916 echo             </tr> >> ${HTML_MAIL_PATH}
 917 echo             <tr> >> ${HTML_MAIL_PATH}
 918 if [[ -z ${DB_STATUS} ]];then
 919     GenHtmlTableContent th "204, 255, 255" "构建失败原因"
 920     GenHtmlTableContent th "204, 255, 102" <FONT color=red>获取DailyBuild状态异常!</FONT><a href="http://www.mamicode.com/${DB_JOB_URL}${DB_BUILD_NUMBER}/consoleFull">点击此处</a>查看详细日志;<a href="http://www.mamicode.com/${WIKI_DB_PROBLEM}">点击此处</a>查看解决办法
 921 elif [[ ${DB_STATUS} != 0 ]];then
 922     GenHtmlTableContent th "204, 255, 255" "构建失败原因"
 923     GenHtmlTableContent th "204, 255, 102" "<FONT color=red>${DB_STATUS_MESSAGE}!</FONT><a href=http://www.mamicode.com/${DB_JOB_URL}${DB_BUILD_NUMBER}/consoleFull>点击此处查看详细日志;点击此处查看解决办法"
 924 else
 925     GenHtmlTableContent th "204, 255, 255" "构建日志地址"
 926     GenHtmlTableContent th "204, 255, 102" <a href="http://www.mamicode.com/${DB_JOB_URL}${DB_BUILD_NUMBER}/consoleFull">点击此处</a>查看详细日志
 927 fi
 928 echo             </tr> >> ${HTML_MAIL_PATH}
 929 echo </table> >> ${HTML_MAIL_PATH}
 930 echo ‘‘ >> ${HTML_MAIL_PATH}
 931 
 932 # 生成邮件第二个表格,内容是编译的数据
 933 echo <br></br> >> ${HTML_MAIL_PATH}
 934 echo <FONT face=微软雅黑 size=4><b>编译</b></FONT> >> ${HTML_MAIL_PATH}
 935 echo <table border="1" bordercolor="black" width="100%" cellspacing="0" cellpadding="3" style="border-collapse:collapse;font-family:Arial;color: rgb(255, 255, 255)"> >> ${HTML_MAIL_PATH}
 936 echo             <tr> >> ${HTML_MAIL_PATH}
 937 if [[ -n `echo ${DB_STATUS} | grep -E ^1|^2` ]];then
 938     echo                 <th align="left" width="25%" rowspan="0" style="background-color: rgb(${FAILURE_RGB});">APP Name</th> >> ${HTML_MAIL_PATH}
 939     echo             </tr> >> ${HTML_MAIL_PATH}
 940     echo             <tr> >> ${HTML_MAIL_PATH}
 941     GenHtmlTableContent td "${FAILURE_RGB}" "NA"
 942 else
 943     DB_APP_URL=`cat ${SQL_CONTENT} | grep -w "${DB_TABLE_NAME}.war_url" | sed s/.*=//`
 944     DB_APP_NAME=`basename ${DB_APP_URL}`
 945     echo                 <th align="left" width="25%" rowspan="0" style="background-color: rgb(${SUCCESS_RGB});">APP Name</th> >> ${HTML_MAIL_PATH}
 946     echo             </tr> >> ${HTML_MAIL_PATH}
 947     echo             <tr> >> ${HTML_MAIL_PATH}
 948     GenHtmlTableContent td "219, 255, 180" "${DB_APP_NAME}"
 949 fi
 950 echo             </tr> >> ${HTML_MAIL_PATH}
 951 echo </table> >> ${HTML_MAIL_PATH}
 952 echo ‘‘ >> ${HTML_MAIL_PATH}
 953 
 954 # 生成邮件第三个表格,内容是单元测试&代码质量检查的数据
 955 echo <br></br> >> ${HTML_MAIL_PATH}
 956 echo <FONT face=微软雅黑 size=4><b>单元测试&代码质量检查</b></FONT> >> ${HTML_MAIL_PATH}
 957 echo <table border="1" bordercolor="black" width="100%" cellspacing="0" cellpadding="3" style="border-collapse:collapse;font-family:Arial;color: rgb(255, 255, 255)"> >> ${HTML_MAIL_PATH}
 958 echo             <tr> >> ${HTML_MAIL_PATH}
 959 if [[ ${IS_SKIP_UNIT} == "Yes" ]] && [[ -n `echo ${DB_STATUS} | grep -E ^0|^4|^5` ]];then
 960     GenHtmlTableContent th "${SUCCESS_RGB}" "您已选择跳过单元测试&代码质量检查"
 961     echo             </tr> >> ${HTML_MAIL_PATH}
 962     echo </table> >> ${HTML_MAIL_PATH}
 963 elif [[ ${IS_SKIP_UNIT} == "Yes" ]] && [[ -n `echo ${DB_STATUS} | grep -E ^1|^2` ]];then
 964     GenHtmlTableContent th "${FAILURE_RGB}" "您已选择跳过单元测试&代码质量检查"
 965     echo             </tr> >> ${HTML_MAIL_PATH}
 966     echo </table> >> ${HTML_MAIL_PATH}
 967 elif [[ ${IS_SKIP_UNIT} == "No" ]];then
 968     # 表格的第一行
 969     if [[ -z ${CI_MVN_GROUP_ID} ]] || [[ -z ${CI_MVN_ARTIFACT_ID} ]] || [[ -z ${CI_SONAR_BARNCH} ]];then
 970         echo                 <th align="left" width="25%" rowspan="2" style="background-color: rgb(${FAILURE_RGB});">Sonar名</th> >> ${HTML_MAIL_PATH}
 971     else
 972            echo                 <th align="left" width="25%" rowspan="2" style="background-color: rgb(${SUCCESS_RGB});">Sonar名</th> >> ${HTML_MAIL_PATH}
 973     fi
 974 
 975     if [[ -n `echo ${DB_STATUS} | grep -E ^1|^2` ]];then
 976         echo                 <th align="center" colspan="4" style="background-color: rgb(${FAILURE_RGB});">代码质量检查</th> >> ${HTML_MAIL_PATH}
 977         echo                 <th align="center" colspan="3" style="background-color: rgb(${FAILURE_RGB});">单元测试</th> >> ${HTML_MAIL_PATH}
 978         echo             </tr> >> ${HTML_MAIL_PATH}
 979     elif [[ -n `echo ${DB_STATUS} | grep -E ^3` ]];then
 980         if [[ ${DB_STATUS} = 36 ]] || [[ ${DB_STATUS} = 37 ]];then
 981             if [[ `echo "${QS_SONAR_BLOCKER_VIOLATIONS}<${CI_SONAR_BLOCKER_VIOLATIONS}" | bc` != 0 ]] || [[ `echo "${QS_SONAR_CRITICAL_VIOLATIONS}<${CI_SONAR_CRITICAL_VIOLATIONS}" | bc` != 0 ]];then
 982                 echo                 <th align="center" colspan="4" style="background-color: rgb(${FAILURE_RGB});">代码质量检查</th> >> ${HTML_MAIL_PATH}
 983             else
 984                 echo                 <th align="center" colspan="4" style="background-color: rgb(${SUCCESS_RGB});">代码质量检查</th> >> ${HTML_MAIL_PATH}
 985             fi
 986         
 987             if [[ `echo "${QS_SONAR_COVERAGE}>${CI_SONAR_COVERAGE}" | bc` != 0 ]] || [[ `echo "${QS_SONAR_TEST_SUCCESS_DENSITY}>${CI_SONAR_TEST_SUCCESS_DENSITY}" | bc` != 0 ]];then
 988                 echo                 <th align="center" colspan="3" style="background-color: rgb(${FAILURE_RGB});">单元测试</th> >> ${HTML_MAIL_PATH}
 989             else
 990                 echo                 <th align="center" colspan="3" style="background-color: rgb(${SUCCESS_RGB});">单元测试</th> >> ${HTML_MAIL_PATH}
 991             fi
 992         else
 993             echo                 <th align="center" colspan="4" style="background-color: rgb(${FAILURE_RGB});">代码质量检查</th> >> ${HTML_MAIL_PATH}
 994             echo                 <th align="center" colspan="3" style="background-color: rgb(${FAILURE_RGB});">单元测试</th> >> ${HTML_MAIL_PATH}
 995         fi
 996             
 997         echo             </tr> >> ${HTML_MAIL_PATH}
 998     else
 999         echo                 <th align="center" colspan="4" style="background-color: rgb(${SUCCESS_RGB});">代码质量检查</th> >> ${HTML_MAIL_PATH}
1000         echo                 <th align="center" colspan="3" style="background-color: rgb(${SUCCESS_RGB});">单元测试</th> >> ${HTML_MAIL_PATH}
1001         echo             </tr> >> ${HTML_MAIL_PATH}
1002     fi
1003     
1004     # 表格的第二行
1005     echo             <tr> >> ${HTML_MAIL_PATH}
1006     
1007     if [[ -n ${CI_SONAR_LINES} ]];then
1008         GenHtmlTableContent th "${SUCCESS_RGB}" "代码行数"
1009     else
1010         GenHtmlTableContent th "${FAILURE_RGB}" "代码行数"
1011     fi
1012     
1013     if [[ `echo "${QS_SONAR_BLOCKER_VIOLATIONS}<${CI_SONAR_BLOCKER_VIOLATIONS}" | bc 2>/dev/null` != 0 ]];then
1014         GenHtmlTableContent th "${FAILURE_RGB}" "阻断违规"
1015     else
1016         GenHtmlTableContent th "${SUCCESS_RGB}" "阻断违规"
1017     fi
1018     
1019     if [[ `echo "${QS_SONAR_CRITICAL_VIOLATIONS}<${CI_SONAR_CRITICAL_VIOLATIONS}" | bc 2>/dev/null` != 0 ]];then
1020         GenHtmlTableContent th "${FAILURE_RGB}" "严重违规"
1021     else
1022         GenHtmlTableContent th "${SUCCESS_RGB}" "严重违规"
1023     fi
1024     
1025     if [[ -n ${CI_SONAR_MAJOR_VIOLATIONS} ]];then
1026         GenHtmlTableContent th "${SUCCESS_RGB}" "主要违规"
1027     else
1028         GenHtmlTableContent th "${FAILURE_RGB}" "主要违规"
1029     fi
1030     
1031     if [[ -n ${CI_SONAR_TESTS} ]];then
1032         GenHtmlTableContent th "${SUCCESS_RGB}" "单元测试数"
1033     else
1034         GenHtmlTableContent th "${FAILURE_RGB}" "单元测试数"
1035     fi
1036     
1037     if [[ `echo "${QS_SONAR_COVERAGE}>${CI_SONAR_COVERAGE}" | bc 2>/dev/null` != 0 ]];then
1038         GenHtmlTableContent th "${FAILURE_RGB}" "覆盖率"
1039     else
1040         GenHtmlTableContent th "${SUCCESS_RGB}" "覆盖率"
1041     fi
1042     
1043     if [[ `echo "${QS_SONAR_TEST_SUCCESS_DENSITY}>${CI_SONAR_TEST_SUCCESS_DENSITY}" | bc 2>/dev/null` != 0 ]];then
1044         GenHtmlTableContent th "${FAILURE_RGB}" "成功率"
1045     else
1046         GenHtmlTableContent th "${SUCCESS_RGB}" "成功率"
1047     fi
1048     
1049     echo             </tr> >> ${HTML_MAIL_PATH}
1050     
1051     # 表格的第三行
1052     echo             <tr> >> ${HTML_MAIL_PATH}
1053     if [[ -z ${CI_MVN_GROUP_ID} ]] || [[ -z ${CI_MVN_ARTIFACT_ID} ]] || [[ -z ${CI_SONAR_BARNCH} ]];then
1054         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
1055     else
1056            GenHtmlTableContent td "219, 255, 180" "${CI_MVN_NAME} ${CI_SONAR_BARNCH}"‘<br><b>(<a href="http://www.mamicode.com/${SONAR_URL}/dashboard/index/${CI_MVN_GROUP_ID}:${CI_MVN_ARTIFACT_ID}:${CI_SONAR_BARNCH}">点击此处</a>查看Sonar数据)</b>
1057     fi
1058     
1059     if [[ -n ${CI_SONAR_LINES} ]];then
1060         GenHtmlTableContent td "219, 255, 180" "${CI_SONAR_LINES}"
1061     else
1062         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
1063     fi
1064     
1065     if [[ -z ${CI_SONAR_BLOCKER_VIOLATIONS} ]];then
1066         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
1067     else
1068         if [[ `echo "${QS_SONAR_BLOCKER_VIOLATIONS}<${CI_SONAR_BLOCKER_VIOLATIONS}" | bc` != 0 ]];then
1069             GenHtmlTableContent td "${FAILURE_RGB}" "${CI_SONAR_BLOCKER_VIOLATIONS}"
1070         else
1071             GenHtmlTableContent td "219, 255, 180" "${CI_SONAR_BLOCKER_VIOLATIONS}"
1072         fi
1073     fi
1074     
1075     if [[ -z ${CI_SONAR_CRITICAL_VIOLATIONS} ]];then
1076         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
1077     else
1078         if [[ `echo "${QS_SONAR_CRITICAL_VIOLATIONS}<${CI_SONAR_CRITICAL_VIOLATIONS}" | bc` != 0 ]];then
1079             GenHtmlTableContent td "${FAILURE_RGB}" "${CI_SONAR_CRITICAL_VIOLATIONS}"
1080         else
1081             GenHtmlTableContent td "219, 255, 180" "${CI_SONAR_CRITICAL_VIOLATIONS}"
1082         fi
1083     fi
1084     
1085     if [[ -n ${CI_SONAR_MAJOR_VIOLATIONS} ]];then
1086         GenHtmlTableContent td "219, 255, 180" "${CI_SONAR_MAJOR_VIOLATIONS}"
1087     else
1088         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
1089     fi
1090     
1091     if [[ -n ${CI_SONAR_TESTS} ]];then
1092         GenHtmlTableContent td "219, 255, 180" "${CI_SONAR_TESTS}"
1093     else
1094         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
1095     fi
1096     
1097     if [[ -z ${CI_SONAR_COVERAGE} ]];then
1098         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
1099     else
1100         if [[ `echo "${QS_SONAR_COVERAGE}>${CI_SONAR_COVERAGE}" | bc` != 0 ]];then
1101             GenHtmlTableContent td "${FAILURE_RGB}" "${CI_SONAR_COVERAGE}%"
1102         else
1103             GenHtmlTableContent td "219, 255, 180" "${CI_SONAR_COVERAGE}%"
1104         fi
1105     fi
1106     
1107     if [[ -z ${CI_SONAR_TEST_SUCCESS_DENSITY} ]];then
1108         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
1109     else
1110         if [[ `echo "${QS_SONAR_TEST_SUCCESS_DENSITY}>${CI_SONAR_TEST_SUCCESS_DENSITY}" | bc` != 0 ]];then
1111             GenHtmlTableContent td "${FAILURE_RGB}" "${CI_SONAR_TEST_SUCCESS_DENSITY}%"
1112         else
1113             GenHtmlTableContent td "219, 255, 180" "${CI_SONAR_TEST_SUCCESS_DENSITY}%"
1114         fi
1115     fi
1116 fi
1117 echo             </tr> >> ${HTML_MAIL_PATH}
1118 echo </table> >> ${HTML_MAIL_PATH}
1119 echo ‘‘ >> ${HTML_MAIL_PATH}
1120 
1121 # 生成邮件第四个表格,内容是发布测试环境的数据
1122 echo <br></br> >> ${HTML_MAIL_PATH}
1123 echo <FONT face=微软雅黑 size=4><b>发布测试环境</b></FONT> >> ${HTML_MAIL_PATH}
1124 echo <table border="1" bordercolor="black" width="100%" cellspacing="0" cellpadding="3" style="border-collapse:collapse;font-family:Arial;color: rgb(255, 255, 255)"> >> ${HTML_MAIL_PATH}
1125 echo             <tr> >> ${HTML_MAIL_PATH}
1126 if [[ ${IS_SKIP_DEPLOY} == "Yes" ]] && [[ -n `echo ${DB_STATUS} | grep -E ^0|^5` ]];then
1127     GenHtmlTableContent th "${SUCCESS_RGB}" "您已选择跳过发布测试环境"
1128     echo             </tr> >> ${HTML_MAIL_PATH}
1129     echo </table> >> ${HTML_MAIL_PATH}
1130 elif [[ ${IS_SKIP_DEPLOY} == "Yes" ]] && [[ -n `echo ${DB_STATUS} | grep -E ^1|^2|^3` ]];then
1131     GenHtmlTableContent th "${FAILURE_RGB}" "您已选择跳过发布测试环境"
1132     echo             </tr> >> ${HTML_MAIL_PATH}
1133     echo </table> >> ${HTML_MAIL_PATH}
1134 elif [[ ${IS_SKIP_DEPLOY} == "No" ]];then
1135     if [[ -n `echo ${DB_STATUS} | grep -E ^1|^2|^3` ]];then
1136         echo                 <th align="left" width="25%" rowspan="0" style="background-color: rgb(${FAILURE_RGB});">移动设备编号</th> >> ${HTML_MAIL_PATH}
1137         GenHtmlTableContent th "${FAILURE_RGB}" "Host IP"
1138         GenHtmlTableContent th "${FAILURE_RGB}" "移动设备型号"
1139         GenHtmlTableContent th "${FAILURE_RGB}" "移动设备SN"
1140         GenHtmlTableContent th "${FAILURE_RGB}" "责任人"
1141         echo             </tr> >> ${HTML_MAIL_PATH}
1142         echo             <tr> >> ${HTML_MAIL_PATH}
1143         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
1144         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
1145         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
1146         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
1147         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
1148     elif [[ -n `echo ${DB_STATUS} | grep -E ^4` ]];then
1149         echo                 <th align="left" width="25%" rowspan="0" style="background-color: rgb(${FAILURE_RGB});">移动设备编号</th> >> ${HTML_MAIL_PATH}
1150         GenHtmlTableContent th "${FAILURE_RGB}" "Host IP"
1151         GenHtmlTableContent th "${FAILURE_RGB}" "移动设备型号"
1152         GenHtmlTableContent th "${FAILURE_RGB}" "移动设备SN"
1153         GenHtmlTableContent th "${FAILURE_RGB}" "责任人"
1154         echo             </tr> >> ${HTML_MAIL_PATH}
1155         echo             <tr> >> ${HTML_MAIL_PATH}
1156         GenHtmlTableContent td "${FAILURE_RGB}" "${DB_MOBILE_ID}"
1157         GenHtmlTableContent td "${FAILURE_RGB}" "${DB_MOBILE_HOST_IP}"
1158         GenHtmlTableContent td "${FAILURE_RGB}" "${DB_MOBILE_TYPE}"
1159         GenHtmlTableContent td "${FAILURE_RGB}" "${DB_MOBILE_SN}"
1160         GenHtmlTableContent td "${FAILURE_RGB}" "${DB_MOBILE_OWNER}"
1161     else
1162         echo                 <th align="left" width="25%" rowspan="0" style="background-color: rgb(${SUCCESS_RGB});">移动设备编号</th> >> ${HTML_MAIL_PATH}
1163         GenHtmlTableContent th "${SUCCESS_RGB}" "Host IP"
1164         GenHtmlTableContent th "${SUCCESS_RGB}" "移动设备型号"
1165         GenHtmlTableContent th "${SUCCESS_RGB}" "移动设备SN"
1166         GenHtmlTableContent th "${SUCCESS_RGB}" "责任人"
1167         echo             </tr> >> ${HTML_MAIL_PATH}
1168         echo             <tr> >> ${HTML_MAIL_PATH}
1169         GenHtmlTableContent td "219, 255, 180" "${DB_MOBILE_ID}"
1170         GenHtmlTableContent td "219, 255, 180" "${DB_MOBILE_HOST_IP}"
1171         GenHtmlTableContent td "219, 255, 180" "${DB_MOBILE_TYPE}"
1172         GenHtmlTableContent td "219, 255, 180" "${DB_MOBILE_SN}"
1173         GenHtmlTableContent td "219, 255, 180" "${DB_MOBILE_OWNER}"
1174     fi
1175 fi
1176 echo             </tr> >> ${HTML_MAIL_PATH}
1177 echo </table> >> ${HTML_MAIL_PATH}
1178 echo ‘‘ >> ${HTML_MAIL_PATH}
1179 
1180 # 生成邮件第五个表格,内容是自动化测试的数据
1181 echo <br></br> >> ${HTML_MAIL_PATH}
1182 echo <FONT face=微软雅黑 size=4><b>自动化测试</b></FONT> >> ${HTML_MAIL_PATH}
1183 echo <table border="1" bordercolor="black" width="100%" cellspacing="0" cellpadding="3" style="border-collapse:collapse;font-family:Arial;color: rgb(255, 255, 255)"> >> ${HTML_MAIL_PATH}
1184 echo             <tr> >> ${HTML_MAIL_PATH}
1185 if [[ ${IS_SKIP_AUTO} == "Yes" ]] && [[ ${DB_STATUS} = 0 ]];then
1186     GenHtmlTableContent th "${SUCCESS_RGB}" "您已选择跳过自动化测试"
1187     echo             </tr> >> ${HTML_MAIL_PATH}
1188     echo </table> >> ${HTML_MAIL_PATH}
1189 elif [[ ${IS_SKIP_AUTO} == "Yes" ]] && [[ ${DB_STATUS} != 0 ]];then
1190     GenHtmlTableContent th "${FAILURE_RGB}" "您已选择跳过自动化测试"
1191     echo             </tr> >> ${HTML_MAIL_PATH}
1192     echo </table> >> ${HTML_MAIL_PATH}
1193 elif [[ ${IS_SKIP_AUTO} == "No" ]];then
1194     # if [[ -n ${AUTO_AUTO_ID} ]];then
1195     if [[ -n `echo ${AUTO_JOB_DATA} | grep "TestcaseNum"` ]];then
1196         AUTO_RUN_ENV_NAME="3-主干环境"
1197         AUTO_START_RUNDATE=`echo -e "${AUTO_JOB_DATA}" | sed /StartTime/!d | sed s/.*StartTime:// | awk {print $1}`
1198         AUTO_START_RUNTIME=`echo -e "${AUTO_JOB_DATA}" | sed /StartTime/!d | sed s/.*StartTime:// | awk {print $2}`
1199         AUTO_RUN_USE_TIME=`echo -e "${AUTO_JOB_DATA}" | sed /TotalTime/!d | sed s/.*TotalTime://`
1200         AUTO_SCENARIO_NUM=`echo -e "${AUTO_JOB_DATA}" | sed /TestcaseNum/!d | sed s/.*TestcaseNum://`
1201         AUTO_PASS_RATE=`echo -e "${AUTO_JOB_DATA}" | sed /PassRate/!d | sed s/.*PassRate:\(.*\)%/\1/`
1202         AUTO_REPORT_URL="${DB_JOB_URL}${DB_BUILD_NUMBER}/artifact/AutoTest/report/html/report.html"
1203         echo                 <th align="left" width="25%" style="background-color: rgb(${SUCCESS_RGB});">被测环境</th> >> ${HTML_MAIL_PATH}
1204         GenHtmlTableContent th "${SUCCESS_RGB}" "开始时间"
1205         GenHtmlTableContent th "${SUCCESS_RGB}" "运行用时"
1206         GenHtmlTableContent th "${SUCCESS_RGB}" "场景总数"
1207         if [[ `echo "${QS_AUTO_PASS_RATE}>${AUTO_PASS_RATE}" | bc` != 0 ]];then
1208             GenHtmlTableContent th "${FAILURE_RGB}" "通过率"
1209         else
1210             GenHtmlTableContent th "${SUCCESS_RGB}" "通过率"
1211         fi
1212         echo             </tr> >> ${HTML_MAIL_PATH}
1213         echo             <tr> >> ${HTML_MAIL_PATH}
1214         GenHtmlTableContent td "219, 255, 180" ${AUTO_RUN_ENV_NAME}<br><b>(<a href="http://www.mamicode.com/${AUTO_REPORT_URL}">点击此处</a>查看自动化report)</b>
1215         GenHtmlTableContent td "219, 255, 180" "${AUTO_START_RUNDATE} ${AUTO_START_RUNTIME}"
1216         GenHtmlTableContent td "219, 255, 180" "${AUTO_RUN_USE_TIME}"
1217         GenHtmlTableContent td "219, 255, 180" "${AUTO_SCENARIO_NUM}"
1218         if [[ `echo "${QS_AUTO_PASS_RATE}>${AUTO_PASS_RATE}" | bc` != 0 ]];then
1219             GenHtmlTableContent td "${FAILURE_RGB}" "${AUTO_PASS_RATE}%"
1220         else
1221             GenHtmlTableContent td "219, 255, 180" "${AUTO_PASS_RATE}%"
1222         fi
1223         echo             </tr> >> ${HTML_MAIL_PATH}
1224         echo </table> >> ${HTML_MAIL_PATH}
1225         echo ‘‘ >> ${HTML_MAIL_PATH}
1226     elif [[ -z `echo ${AUTO_JOB_DATA} | grep "TestcaseNum"` ]] && [[ -n `echo ${DB_STATUS} | grep -E ^1|^2|^3|^4` ]];then
1227         echo                 <th align="left" width="25%" style="background-color: rgb(${FAILURE_RGB});">被测环境</th> >> ${HTML_MAIL_PATH}
1228         GenHtmlTableContent th "${FAILURE_RGB}" "运行目的"
1229         GenHtmlTableContent th "${FAILURE_RGB}" "开始时间"
1230         GenHtmlTableContent th "${FAILURE_RGB}" "运行用时"
1231         GenHtmlTableContent th "${FAILURE_RGB}" "场景总数"
1232         GenHtmlTableContent th "${FAILURE_RGB}" "通过率"
1233         echo             </tr> >> ${HTML_MAIL_PATH}
1234         echo             <tr> >> ${HTML_MAIL_PATH}
1235         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
1236         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
1237         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
1238         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
1239         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
1240         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
1241         echo             </tr> >> ${HTML_MAIL_PATH}
1242         echo </table> >> ${HTML_MAIL_PATH}
1243         echo ‘‘ >> ${HTML_MAIL_PATH}
1244     elif [[ -z `echo ${AUTO_JOB_DATA} | grep "TestcaseNum"` ]] && [[ -n `echo ${DB_STATUS} | grep -E ^5` ]];then
1245         echo                 <th align="left" width="25%" style="background-color: rgb(${SUCCESS_RGB});">被测环境</th> >> ${HTML_MAIL_PATH}
1246         GenHtmlTableContent th "${FAILURE_RGB}" "运行目的"
1247         GenHtmlTableContent th "${FAILURE_RGB}" "开始时间"
1248         GenHtmlTableContent th "${FAILURE_RGB}" "运行用时"
1249         GenHtmlTableContent th "${FAILURE_RGB}" "场景总数"
1250         GenHtmlTableContent th "${FAILURE_RGB}" "通过率"
1251         echo             </tr> >> ${HTML_MAIL_PATH}
1252         echo             <tr> >> ${HTML_MAIL_PATH}
1253         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
1254         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
1255         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
1256         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
1257         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
1258         GenHtmlTableContent td "${FAILURE_RGB}" "NA"
1259         echo             </tr> >> ${HTML_MAIL_PATH}
1260         echo </table> >> ${HTML_MAIL_PATH}
1261         echo ‘‘ >> ${HTML_MAIL_PATH}
1262     fi
1263 fi
1264 echo <br></br> >> ${HTML_MAIL_PATH}
1265 echo <FONT face=微软雅黑 size=3>------</FONT> >> ${HTML_MAIL_PATH}
1266 echo </br> >> ${HTML_MAIL_PATH}
1267 echo <FONT face=微软雅黑 size=3>质量标准:阻断违规≤${QS_SONAR_BLOCKER_VIOLATIONS},严重违规≤${QS_SONAR_CRITICAL_VIOLATIONS},单元测试覆盖率≥${QS_SONAR_COVERAGE}%,单元测试成功率≥${QS_SONAR_TEST_SUCCESS_DENSITY}%,自动化测试通过率≥${QS_AUTO_PASS_RATE}%</FONT> >> ${HTML_MAIL_PATH}
1268 
1269 # 发送邮件
1270 SendMail "[DailyBuild - ${DB_BUILD_RESULT}] ${DB_JOB_NAME} Build #${DB_BUILD_NUMBER}" "${DB_MAIL_TO}" "${DB_MAIL_CC_TO}" "${HTML_MAIL_PATH}"
1271 echo Send email to:‘"${DB_MAIL_TO}"
1272 }
1273 
1274 function CleanWS()
1275 {
1276 # 函数功能说明
1277 # 清理Workspace
1278 if [[ -d db_target ]];then
1279     echo "Cleaning local Directory db_target"
1280     rm -rf db_target/*
1281 else
1282     echo "New Directory db_target"
1283     mkdir db_target
1284 fi
1285 
1286 rm -rf CI*.xml
1287 }
1288 
1289 function RecordSQLContent()
1290 {
1291 # 函数功能说明
1292 # 记录DB各过程的日志
1293 LOG_FILE_PATH="${SQL_CONTENT}"
1294     
1295 for i in "$@"
1296 do
1297     echo "$i" >> ${LOG_FILE_PATH}
1298 done
1299 }
1300 
1301 function GetSonarDate()
1302 {
1303 # 函数功能说明
1304 # 通过获取Sonar API的Json格式的数据,处理成所需数据,并写入日志
1305 # 示例:GetSonarDate “http://sonar.yihaodian.com.cn/api/resources?resource=com.yihaodian.merchant:merchant-shangjia:@IS-Trunk&format=json&verbose=true&metrics=lines,blocker_violations,critical_violations,major_violations,tests,coverage,test_success_density”
1306 SONAR_API_URL=$1
1307 SONAR_DATA=http://www.mamicode.com/`curl --user ${JENKINS_USERNAME}:${JENKINS_PASSWORD} -s"${SONAR_API_URL}" | sed -e ‘s/\([{,]\)\s*/\1\n/g -e s/}/\n}/g`
1308 
1309 for i in ${SONAR_COLUMN[@]}
1310 do
1311     SONAR_COLUMN_VALUE=http://www.mamicode.com/`echo -e "${SONAR_DATA}" | sed -n "/$i/,+2p" | sed /val/!d | sed s/.*:\(.*\)..*/\1/g`
1312     i="sonar_$i"
1313     RecordSQLContent ${CI_TABLE_NAME}.$i=${SONAR_COLUMN_VALUE}
1314 done
1315 }
1316 
1317 function GetQualityStandard()
1318 {
1319 # 函数功能说明
1320 # 查询数据库,获取代码质量标准
1321 # 如果查询不到,则使用默认的标准:阻断违规=0,严重违规=0,单元测试覆盖率≥40%,单元测试成功率=100%,自动化测试通过率≥90% 
1322 # 示例:GetQualityStandard ${JOB_NAME}
1323 
1324 DAILY_JOB_NAME=$1
1325 
1326 SELECT_QS_SQL="SELECT D.sonar_blocker_violations,D.sonar_critical_violations,D.sonar_coverage,D.sonar_test_success_density,D.auto_pass_rate FROM scm_cmis_pool_dailybuild_prm D,scm_cmis_pool_jenkins_job P,scm_cmis_jenkins_job J
1327 where P.jenkins_job_id = J.id and P.pool_id = D.pool_id and J.job_name = ""‘"${DAILY_JOB_NAME}"‘"
1328 QUALITY_STANDARD=`db_common/mysql_sdbc.sh -h ${CMIS_DB_IP} -p ${CMIS_DB_PORT} -u ${CMIS_DB_USERNAME} -w ${CMIS_DB_PASSWORD} -d ${CMIS_DB_NAME} -c "${SELECT_QS_SQL}" -l ${CMIS_DB_LOG} | sed -n 3p`
1329 
1330 QS_SONAR_BLOCKER_VIOLATIONS=`echo ${QUALITY_STANDARD} | awk {print $1}`
1331 QS_SONAR_CRITICAL_VIOLATIONS=`echo ${QUALITY_STANDARD} | awk {print $2}`
1332 QS_SONAR_COVERAGE=`echo ${QUALITY_STANDARD} | awk {print $3}`
1333 QS_SONAR_TEST_SUCCESS_DENSITY=`echo ${QUALITY_STANDARD} | awk {print $4}`
1334 QS_AUTO_PASS_RATE=`echo ${QUALITY_STANDARD} | awk {print $5}`
1335 
1336 if [[ -z ${QS_SONAR_BLOCKER_VIOLATIONS} ]];then
1337     QS_SONAR_BLOCKER_VIOLATIONS="0"
1338 fi
1339 if [[ -z ${QS_SONAR_CRITICAL_VIOLATIONS} ]];then
1340     QS_SONAR_CRITICAL_VIOLATIONS="0"
1341 fi
1342 if [[ -z ${QS_SONAR_COVERAGE} ]];then
1343     QS_SONAR_COVERAGE="40"
1344 fi
1345 if [[ -z ${QS_SONAR_TEST_SUCCESS_DENSITY} ]];then
1346     QS_SONAR_TEST_SUCCESS_DENSITY="100"
1347 fi
1348 if [[ -z ${QS_AUTO_PASS_RATE} ]];then
1349     QS_AUTO_PASS_RATE="90"
1350 fi
1351 }
1352 
1353 function GetMobileInfoByID()
1354 {
1355 # 函数功能说明
1356 # 通过CMIS API,获取移动设备信息
1357 # GetMobileInfoByID ${MOBILE_ID}
1358 
1359 MOBILE_ID=$1
1360 
1361 MOBILE_INFO=`curl -s "${CMIS_API_HOST}/container/getMobileInfoByMobileCode/${MOBILE_ID}${CMIS_API_AUTH}" | sed -e s/\([{,]\)\s*/\1\n/g -e s/}/\n}/g`
1362 HOST_IP=`echo -e "${MOBILE_INFO}" | sed /"hostIp"/!d | sed s/"hostIp":"\(.*\)",/\1/`
1363 MOBILE_SN=`echo -e "${MOBILE_INFO}" | sed /"serialNumber"/!d | sed s/"serialNumber":"\(.*\)",/\1/`
1364 
1365 }
1366 
1367 function IfJobIsUsable()
1368 {
1369 # 函数功能说明
1370 # 检查Job是否可用。如果Job存在且启用,则输出true;否则,则输出false
1371 # 
1372 
1373 JOB_URL=$1
1374 
1375 if [[ `curl -I -s "${JOB_URL}" | sed /HTTP\/1.1/!d` = "HTTP/1.1 200 OK"* ]] && [[ -z `curl -s "${JOB_URL}" | grep This project is currently disabled` ]];then
1376     echo "true"
1377 else
1378     echo "false"
1379 fi
1380 }
define_function.sh

③maven_deploy.sh

技术分享
  1 #!/bin/bash
  2 
  3 # -----------------------------------------------------------------------------
  4 # Filename:      maven_deploy.sh
  5 # Encoding:      UTF-8
  6 # Date:          2014/05/27
  7 # Author:        Li Jinyan
  8 # Email:         lijinyan@yihaodian.com
  9 # Function:      发布Jar包至仓库
 10 # Usage:         
 11 # Version:       
 12 # -----------------------------------------------------------------------------
 13 
 14 while getopts "n:j:e:u:r:c:m:" option; do
 15     case ${option} in
 16         n )
 17             JOB_NAME=${OPTARG}
 18             ;;
 19         j )
 20             JOB_URL=${OPTARG}
 21             ;;
 22         e )
 23             BUILD_NUMBER=${OPTARG}
 24             ;;
 25         u )
 26             BUILD_USER=${OPTARG}
 27             ;;
 28         r )
 29             RELEASE_NOTE=${OPTARG}
 30             ;;
 31         c )
 32             BUILD_COMMAND=${OPTARG}
 33             ;;
 34         m )
 35             IS_SEND_MAIL=${OPTARG}
 36             ;;
 37         \? )
 38             echo "UNKNOWN wrong parameter"
 39             exit 1
 40             ;;
 41         * )
 42             echo "UNKNOWN error while processing options"
 43             exit 1
 44             ;;
 45     esac
 46 done
 47 
 48 # 导入环境变量
 49 source /etc/profile
 50 
 51 # 定义变量
 52 JENKINS_JOB_PATH="/data/jenkins/jobs"
 53 #CMIS_API_HOST="http://192.168.20.29:9080/rest/api"
 54 CMIS_API_HOST="http://cmis.yihaodian.com.cn/rest/api"
 55 CMIS_API_AUTH="?username=api_scm_jenkinsjob&password=m@86eAkq"
 56 MVN_LOCAL_REPOS="/home/maven/repos"
 57 MVN_SUB_REPOS="deploy-tru-repo"
 58 IS_SEND_MAIL="true"
 59 # MVN_SUB_REPOS="lijinyan-test"
 60 
 61 PACKAGE_LIST="md_target/package.list"
 62 RUN_LOG="md_target/run.log"
 63 
 64 JENKINS_USERNAME="IT_Test_SCM_Jenkins"
 65 JENKINS_PASSWORD="ezwpk8sx,js526"
 66 
 67 # 初始化${PACKAGE_LIST}
 68 if [[ -d md_target ]];then
 69     rm -rf md_target && mkdir md_target
 70 else
 71     mkdir md_target
 72 fi
 73 
 74 # 定义全局函数
 75 function EnCode()
 76 {
 77 # 函数功能说明
 78 # 将中文转码
 79 INPUT=$1
 80 TMP_ENCODE=""
 81 
 82 while read line;
 83 do
 84     EVERY_LINE_ENCODE=`echo $line |tr -d \n | xxd -plain | sed s/\(..\)/%\1/g`
 85     TMP_ENCODE="${TMP_ENCODE}%0A${EVERY_LINE_ENCODE}"
 86 done << EOF
 87 ${INPUT}
 88 EOF
 89 
 90 RESULT_ENCODE=`echo ${TMP_ENCODE} | sed s/%0A// | sed s/ //g`
 91 echo ${RESULT_ENCODE}
 92 }
 93 
 94 ## 从maven仓库中获取public pom
 95 ## 解析pom判断传入的artifact是不是公共jar
 96     function IsPublicJar()
 97     {
 98         PACKAGE_GROUP_ID=$1
 99         PACKAGE_ARTIFACT_ID=$2
100         mvn org.apache.maven.plugins:maven-dependency-plugin:2.4:get -Dartifact=com.yihaodian.public:public-pom:1.0-SNAPSHOT -DrepoUrl=http://maven.yihaodian.cn/content/repositories/public -Dpackaging=pom -Ddest=temp.xml -q
101         tempCout=`cat temp.xml | sed ":begin; /<\!--/,/-->/ { /-->/! { $! { N; b begin }; }; s/<\!--.*-->/ /; };" | grep -o artifactItem  | wc -l`
102         num=`expr $((($tempCout - 4) / 4))` 
103         for ((i=1;i<=$num;i++));
104         do    
105             groupId=`cat temp.xml|sed ":begin; /<\!--/,/-->/ { /-->/! { $! { N; b begin }; }; s/<\!--.*-->/ /; };" | awk /<pluginManagement>/,/<\/pluginManagement>/  | awk /<artifactItem>/,/<\/artifactItem>/  | awk /<groupId>/,/<\/groupId>/| sed s/<[\/]\?groupId>//g | sed s/[[:space:]]//g | sed -n "$i,${i}p"`
106             artifactId=`cat temp.xml|sed ":begin; /<\!--/,/-->/ { /-->/! { $! { N; b begin }; }; s/<\!--.*-->/ /; };" | awk /<pluginManagement>/,/<\/pluginManagement>/  | awk /<artifactItem>/,/<\/artifactItem>/  | awk /<artifactId>/,/<\/artifactId>/| sed s/<[\/]\?artifactId>//g | sed s/[[:space:]]//g | sed -n "$i,${i}p"`
107             # echo $groupId$artifactId
108             # groupId=`cat temp.xml |  xmllint --format - | sed 2 s/xmlns=".*"//g | xmllint --xpath  //build/pluginManagement/plugins/plugin/executions/execution/configuration/artifactItems/artifactItem[‘"${i}"‘]/groupId/text() -`
109             # artifactId=`cat temp.xml |  xmllint --format - | sed 2 s/xmlns=".*"//g | xmllint --xpath  //build/pluginManagement/plugins/plugin/executions/execution/configuration/artifactItems/artifactItem[‘"${i}"‘]/artifactId/text() -`
110             if [[ "$PACKAGE_GROUP_ID$PACKAGE_ARTIFACT_ID" == "$groupId$artifactId" ]];then
111                 RESULT="YES"
112             fi
113 
114         done
115         echo ${RESULT}
116     }
117 
118 # 检查参数是否合法
119 if [[ ${BUILD_COMMAND} = package ]];then
120     echo -e "\033[1;32m[DeployINFO] 合法的BUILD_COMMAND"
121 elif [[ ${BUILD_COMMAND} = deploy ]];then
122     echo -e "\033[1;32m[DeployINFO] 合法的BUILD_COMMAND"
123     
124     if [[ -n `echo -e "${RELEASE_NOTE}" | grep -E ^请填写|示例如下|1.xxx|2.xxx` ]];then
125         echo -e "\033[1;31m[DeployERROR] 非法的RELEASE_NOTE,请勿使用示例中的发布说明"
126         exit 1
127     elif [[ `echo -e "${RELEASE_NOTE}" | wc -m` -lt 10 ]];then
128         echo -e "\033[1;31m[DeployERROR] 非法的RELEASE_NOTE,请填写超过10个字符的发布说明"
129         exit 1
130     else
131         RELEASE_NOTE=`EnCode "${RELEASE_NOTE}"`
132         echo -e "\033[1;32m[DeployINFO] 合法的RELEASE_NOTE"
133     fi
134     
135 else
136     echo -e "\033[1;31m[DeployERROR] 非法的BUILD_COMMAND,构建命令仅能为package、deploy"
137     exit 1
138 fi
139 
140 # 获取Job所在Jenkins的ServerSiteID
141 JOB_SITE=`echo ${JOB_URL} | sed s#http://\(.*\)/job/.*#\1#`
142 
143 if [[ ${JOB_SITE} = "jenkins_sh.yihaodian.com.cn" ]];then
144     JOB_SITE_ID="1"
145     OTHER_JOB_URL="http://jenkins_wh.yihaodian.com.cn/job/${JOB_NAME}"
146 elif [[ ${JOB_SITE} = "jenkins_wh.yihaodian.com.cn" ]];then
147     JOB_SITE_ID="2"
148     OTHER_JOB_URL="http://jenkins_sh.yihaodian.com.cn/job/${JOB_NAME}"
149 elif [[ ${JOB_SITE} = "hudson.yihaodian.cn" ]];then
150     JOB_SITE_ID="3"
151 else
152     echo -e "\033[1;31m[DeployERROR] 错误的JOB_URL:${JOB_URL},请检查"
153     exit 1
154 fi
155 
156 # 获取Job的PoolID
157 POOL_ID=`curl -s ${CMIS_API_HOST}/jenkins/getJenkinsJobByJobName/${JOB_SITE_ID}/${JOB_NAME}${CMIS_API_AUTH} | sed s/.*poolJenkinsJobRelationshipVoList":\[\(.*\)].*/\1/ | sed -e s/\([{,]\)\s*/\1\n/g -e s/}/\n}/g | sed /poolId/!d | sed s/.*:\(.*\),/\1/`
158 
159 while read line;
160 do
161     if [[ $line =~ "^[0-9]+$" ]];then
162         sleep 1
163     else
164         echo -e "\033[1;31m[DeployERROR] 错误的POOL_ID:$line,请检查"
165         exit 1
166     fi
167 done << EOF
168 ${POOL_ID}
169 EOF
170 
171 # 获取触发者是否有权限运行Job
172 IS_USER_STAKEHOLDER="true"
173 while read line;
174 do
175     IS_POOL_STAKEHOLDER=`curl -s "${CMIS_API_HOST}/pool/isPoolStakeholder/$line/${BUILD_USER}${CMIS_API_AUTH}" | sed -e s/\([{,]\)\s*/\1\n/g -e s/}/\n}/g | sed /success/!d | sed s/.*:\(.*\)/\1/`
176     
177     if [[ ${IS_POOL_STAKEHOLDER} != "true" ]];then
178         IS_USER_STAKEHOLDER="false"
179     fi
180 done << EOF
181 ${POOL_ID}
182 EOF
183 
184 # 获取Jar包的相关信息
185 # 通过project-info-reports插件,生成项目信息,其中包含GAV
186 echo "[workspace] $ mvn project-info-reports:summary"
187 mvn project-info-reports:summary
188 PROJECT_SUMMARY_LIST=`find . -name project-summary.html`
189 
190 # 权限验证
191 for i in `echo -e "${PROJECT_SUMMARY_LIST}"`;
192 do
193     SUMMARY_INFO=`cat $i | grep -A14 GroupId`
194     PACKAGE_GROUP_ID=`echo -e "${SUMMARY_INFO}" | grep -A1 <td>GroupId</td> | sed /<td>GroupId<\/td>/d | sed s#<td>\(.*\)</td>.*#\1#`
195     PACKAGE_ARTIFACT_ID=`echo -e "${SUMMARY_INFO}" | grep -A1 <td>ArtifactId</td> | sed /<td>ArtifactId<\/td>/d | sed s#<td>\(.*\)</td>.*#\1#`
196     PACKAGE_VERSION=`echo -e "${SUMMARY_INFO}" | grep -A1 <td>Version</td> | sed /<td>Version<\/td>/d | sed s#<td>\(.*\)</td>.*#\1#`
197     PACKAGE_TYPE=`echo -e "${SUMMARY_INFO}" | grep -A1 <td>Type</td> | sed /<td>Type<\/td>/d | sed s#<td>\(.*\)</td>.*#\1#`
198     IS_PUBLIC_JAR=`IsPublicJar $PACKAGE_GROUP_ID $PACKAGE_ARTIFACT_ID`
199 
200     # 判断触发者是否有权限构建Job
201     # 包为SNAPSHOT时,仅允许Domain成员&配管使用package、deploy命令。
202     # 包为Release时,仅允许Domain成员&配管使用package命令。
203     # 包为Release时,仅允许配管使用deploy命令。
204     if [[ -n `echo ${PACKAGE_VERSION} | grep "SNAPSHOT"` ]];then
205         if [[ ${BUILD_COMMAND} = "package" ]] ;then
206             if [[ ${IS_USER_STAKEHOLDER} = "true" ]];then
207                 sleep 1
208             else
209                 echo -e "\033[1;31m[DeployERROR] 权限验证未通过"
210                 echo -e "\033[1;31m[DeployERROR] ${BUILD_USER}没有${PACKAGE_GROUP_ID}:${PACKAGE_ARTIFACT_ID}:${PACKAGE_VERSION}:${PACKAGE_TYPE}的${BUILD_COMMAND}权限"
211                 exit 1
212             fi
213         elif [[ ${BUILD_COMMAND} = "deploy" ]] ; then
214             if [[ ${IS_PUBLIC_JAR} = "YES" ]];then
215                 if [[ ${BUILD_USER} = "gufu" ]] || [[ ${BUILD_USER} = "zhangqigao" ]] || [[ ${BUILD_USER} = "wanmiaomiao" ]] ||  [[ ${BUILD_USER} = "zhaobingqing" ]] || [[ ${BUILD_USER} = "helei1" ]] || [[ ${BUILD_USER} = "wangtao4" ]];then
216                     sleep 1
217                 else
218                     echo -e "\033[1;31m[DeployERROR] 权限验证未通过"
219                     echo -e "\033[1;31m[DeployERROR] ${PACKAGE_GROUP_ID}:${PACKAGE_ARTIFACT_ID}是公共Jar"
220                     echo -e "\033[1;31m[DeployERROR] ${BUILD_USER}没有${PACKAGE_GROUP_ID}:${PACKAGE_ARTIFACT_ID}:${PACKAGE_VERSION}:${PACKAGE_TYPE}的${BUILD_COMMAND}权限"
221                     exit 1            
222                 fi
223             else
224                 if [[ ${IS_USER_STAKEHOLDER} = "true" ]];then
225                     sleep 1
226                 else
227                     echo -e "\033[1;31m[DeployERROR] 权限验证未通过"
228                     echo -e "\033[1;31m[DeployERROR] ${BUILD_USER}没有${PACKAGE_GROUP_ID}:${PACKAGE_ARTIFACT_ID}:${PACKAGE_VERSION}:${PACKAGE_TYPE}的${BUILD_COMMAND}权限"
229                     exit 1
230                 fi
231             fi
232         else
233             echo -e "\033[1;31m[DeployERROR] 权限验证未通过"
234             echo -e "\033[1;31m[DeployERROR] ${PACKAGE_GROUP_ID}:${PACKAGE_ARTIFACT_ID}:${PACKAGE_VERSION}:${PACKAGE_TYPE}仅能使用package或deploy命令"
235             exit 1
236         fi
237     else
238         if [[ ${BUILD_COMMAND} = "package" ]];then
239             if [[ ${IS_USER_STAKEHOLDER} = "true" ]] || [[ ${BUILD_USER} = "IT_Test_SCM_Jenkins" ]];then
240                 sleep 1
241             else
242                 echo -e "\033[1;31m[DeployERROR] 权限验证未通过"
243                 echo -e "\033[1;31m[DeployERROR] ${BUILD_USER}没有${PACKAGE_GROUP_ID}:${PACKAGE_ARTIFACT_ID}:${PACKAGE_VERSION}:${PACKAGE_TYPE}的${BUILD_COMMAND}权限"
244                 exit 1
245             fi
246         elif [[ ${BUILD_COMMAND} = "deploy" ]];then
247             if [[ ${BUILD_USER} = "gufu" ]] || [[ ${BUILD_USER} = "zhangqigao" ]] || [[ ${BUILD_USER} = "wanmiaomiao" ]] ||  [[ ${BUILD_USER} = "zhaobingqing" ]] || [[ ${BUILD_USER} = "helei1" ]] || [[ ${BUILD_USER} = "wangtao4" ]];then
248                 sleep 1
249             else
250                 echo -e "\033[1;31m[DeployERROR] 权限验证未通过"
251                 echo -e "\033[1;31m[DeployERROR] ${BUILD_USER}没有${PACKAGE_GROUP_ID}:${PACKAGE_ARTIFACT_ID}:${PACKAGE_VERSION}:${PACKAGE_TYPE}的${BUILD_COMMAND}权限"
252                 exit 1
253             fi
254         fi
255     fi
256     
257     echo `echo ${PACKAGE_GROUP_ID} | sed s/\./\//g`/${PACKAGE_ARTIFACT_ID}/${PACKAGE_VERSION}:${PACKAGE_TYPE} >> ${PACKAGE_LIST}
258     
259     echo -e "\033[1;32m[DeployINFO] 权限验证通过"
260     echo -e "\033[1;32m[DeployINFO] ${BUILD_USER}有${PACKAGE_GROUP_ID}:${PACKAGE_ARTIFACT_ID}:${PACKAGE_VERSION}:${PACKAGE_TYPE}的${BUILD_COMMAND}权限"
261 done
262 
263 # 运行${BUILD_COMMAND}
264 if [[ ${BUILD_COMMAND} = "package" ]];then
265     echo "[workspace] $ mvn clean ${BUILD_COMMAND} -U -Dmaven.repo.local=${MVN_LOCAL_REPOS}/${MVN_SUB_REPOS} -Dmaven.test.skip=true"
266     mvn clean ${BUILD_COMMAND} -U -Dmaven.repo.local=${MVN_LOCAL_REPOS}/${MVN_SUB_REPOS} -Dmaven.test.skip=true
267 elif [[ ${BUILD_COMMAND} = "deploy" ]];then
268     echo "[workspace] $ mvn clean ${BUILD_COMMAND} -U -Dmaven.repo.local=${MVN_LOCAL_REPOS}/${MVN_SUB_REPOS} -Dmaven.test.skip=true -Dcmis.dependency.record=true -Dcmis.dependency.siteId=${JENKINS_SITE_ID} -Dcmis.dependency.jenkinsjob=${JOB_NAME} -Dcmis.dependency.buildId=${BUILD_ID}"
269     mvn clean ${BUILD_COMMAND} -U -Dmaven.repo.local=${MVN_LOCAL_REPOS}/${MVN_SUB_REPOS} -Dmaven.test.skip=true -Dcmis.dependency.record=true -Dcmis.dependency.siteId=${JENKINS_SITE_ID} -Dcmis.dependency.jenkinsjob=${JOB_NAME} -Dcmis.dependency.buildId=${BUILD_ID}
270 fi
271 
272 if [[ $? != 0 ]];then
273     echo -e "\033[1;31m[DeployERROR] 编译打包失败,请检查"
274     exit 1
275 fi
276 
277 # 将deploy信息通过API传入CMIS
278 if [[ ${BUILD_COMMAND} == "deploy" ]];then
279     # 获取uploaded的包
280     UPLOADED_LIST=`cat ${JENKINS_JOB_PATH}/${JOB_NAME}/builds/${BUILD_NUMBER}/log | sed /Uploaded.*jar/!d | sed s/.*Uploaded: \(.*\).jar.*/\1.jar/ | sed s#\(.*\)/.*#\1# | sort | uniq | sed s#http://maven.yihaodian.cn/content/repositories/## | sed s#/#:# | sed s/.*://`
281     PRE_DEPLOY_LIST=`cat ${PACKAGE_LIST} | sed /:jar$/!d | sed s/:jar// | sort`
282     
283     echo -e "\n======UPLOADED_LIST======" >> ${PACKAGE_LIST}
284     echo -e "${UPLOADED_LIST}" >> ${PACKAGE_LIST}
285     echo -e "\n======PRE_DEPLOY_LIST======" >> ${PACKAGE_LIST}
286     echo -e "${PRE_DEPLOY_LIST}" >> ${PACKAGE_LIST}
287 
288     # 判断解析出的需上传的Jar包,是否都上传到仓库了
289     for j in `echo -e "${PRE_DEPLOY_LIST}"`;
290     do
291         if [[ -z `echo -e "${UPLOADED_LIST}" | awk -v var=$j $1==var""` ]];then
292             echo -e "\033[1;31m[DeployERROR] $j没有上传至Maven仓库,请检查"
293             exit 1
294         fi
295     done
296     
297     # 将发布信息打印至控制台,并调用CMIS接口
298     for k in `echo -e "${PRE_DEPLOY_LIST}"`;
299     do
300         PACKAGE_VERSION=`echo $k | sed s/.*\///`
301         PACKAGE_ARTIFACT_ID=`echo $k | sed s/\(.*\)\/.*/\1/ | sed s/.*\///`
302         PACKAGE_GROUP_ID=`echo $k | sed s/\(.*\)\/.*/\1/ | sed s/\(.*\)\/.*/\1/ | sed s/\//./g`
303         
304         echo -e "\033[1;32m[DeployINFO] 记录${PACKAGE_GROUP_ID}:${PACKAGE_ARTIFACT_ID}:${PACKAGE_VERSION}:jar的发布操作中..."
305         echo -e "\033[1;32m[DeployINFO] CMIS APT:${CMIS_API_HOST}/mvn/dependencyDeployHis/?groupId=${PACKAGE_GROUP_ID}&artifactId=${PACKAGE_ARTIFACT_ID}&version=${PACKAGE_VERSION}&packaging=jar&deployAccount=${BUILD_USER}&jobName=${JOB_NAME}&buildId=${BUILD_NUMBER}&siteId=${JOB_SITE_ID}&comment=${RELEASE_NOTE}&isSend=${IS_SEND_MAIL}"
306         curl -s "${CMIS_API_HOST}/mvn/dependencyDeployHis/?groupId=${PACKAGE_GROUP_ID}&artifactId=${PACKAGE_ARTIFACT_ID}&version=${PACKAGE_VERSION}&packaging=jar&deployAccount=${BUILD_USER}&jobName=${JOB_NAME}&buildId=${BUILD_NUMBER}&siteId=${JOB_SITE_ID}&comment=${RELEASE_NOTE}&isSend=${IS_SEND_MAIL}&username=api_scm_jenkinsjob&password=m@86eAkq" >> ${RUN_LOG}
307     done
308 fi
309 
310 # install命令暂未开放,禁用
311 # if [[ ${BUILD_COMMAND} = "install" ]];then
312     # echo -e "\033[1;32m[DeployINFO] 以install命令构建:${OTHER_JOB_URL}"
313     # curl --user ${JENKINS_USERNAME}:${JENKINS_PASSWORD} -s "${OTHER_JOB_URL}/buildWithParameters?BUILD_COMMAND=install"
314 # fi
maven_deploy.sh

④db_common/mysql_sdbc.sh

技术分享
 1 #!/bin/bash
 2 
 3 # -----------------------------------------------------------------------------
 4 # Filename:      mysql_sdbc.sh
 5 # Encoding:      UTF-8
 6 # Date:          2013/08/29
 7 # Author:        Li Jinyan
 8 # Email:         lijinyan@yihaodian.com
 9 # Function:      通用的MySQL的Shell DataBase Connectivity
10 # Usage:         
11 # Version:       
12 # -----------------------------------------------------------------------------
13 
14 while getopts "h:p:u:w:d:c:l:" option; do
15     case ${option} in
16         h )
17             MYSQL_HOST_IP=${OPTARG}
18             ;;
19         p )
20             MYSQL_HOST_PORT=${OPTARG}
21             ;;
22         u )
23             MYSQL_USERNAME=${OPTARG}
24             ;;
25         w )
26             MYSQL_PASSWORD=${OPTARG}
27             ;;
28         d )
29             MYSQL_DBNAME=${OPTARG}
30             ;;
31         c )
32             SQL_CONTENT=${OPTARG}
33             ;;
34         l )
35             MYSQL_LOG_PATH=${OPTARG}
36             ;;
37         \? )
38             echo "UNKNOWN wrong parameter"
39             exit 1
40             ;;
41         * )
42             echo "UNKNOWN error while processing options"
43             exit 1
44             ;;
45     esac
46 done
47 
48 # 定义全局函数
49 function CheckSQLValidity()
50 {
51 # 函数功能说明
52 # 检查SQL语句的合法性,仅允许select和insert语句。
53 # 示例:CheckSQLValidity “select * from cmis.scm_cmis_auto_test”
54 SQL_CONTENT=$1
55 SQL_TYPE=`echo ${SQL_CONTENT} | awk {print $1}`
56 if [[ ${SQL_TYPE} = SELECT ]] || [[ ${SQL_TYPE} = INSERT ]] || [[ ${SQL_TYPE} = UPDATE ]] || [[ ${SQL_TYPE} = SET ]];then
57     echo ""
58 else
59     echo -e "\033[0;31m[SDBC_ERROR] -------------------------------------------------------------------------------------------------------------------"
60     echo -e "\033[1;31m[SDBC_ERROR] Checking SQL TYPE FAILURE"
61     echo -e "\033[1;31m[SDBC_ERROR] SQL TYPE must be select or insert.Your is ${SQL_TYPE}"
62     echo -e "\033[0;31m[SDBC_ERROR] -------------------------------------------------------------------------------------------------------------------"
63     exit 1
64 fi
65 }
66 
67 # 参数检查
68 if [ "${MYSQL_HOST_IP}" = "" ] || [ "${MYSQL_HOST_PORT}" = "" ] || [ "${MYSQL_USERNAME}" = "" ] || [ "${MYSQL_PASSWORD}" = "" ] || [ "${MYSQL_DBNAME}" = "" ] || [ "${SQL_CONTENT}" = "" ] || [ "${MYSQL_LOG_PATH}" = "" ];then
69     echo -e "\033[0;31m[SDBC_ERROR] -------------------------------------------------------------------------------------------------------------------"
70     echo -e "\033[1;31m[SDBC_ERROR] Checking Inputted Parameter FAILURE"
71     echo -e "\033[1;31m[SDBC_ERROR] Missed Parameter"
72     echo -e "\033[0;31m[SDBC_ERROR] -------------------------------------------------------------------------------------------------------------------"
73     exit 1
74 fi
75 
76 # SQL类型检查
77 CheckSQLValidity "${SQL_CONTENT}"
78 
79 # SQL执行
80 mysql -h${MYSQL_HOST_IP} -P${MYSQL_HOST_PORT} -u${MYSQL_USERNAME} -p${MYSQL_PASSWORD} ${MYSQL_DBNAME} -e "${SQL_CONTENT}"
81 HOST_IP=`/sbin/ifconfig eth0 |grep "inet addr"| cut -f 2 -d ":"|cut -f 1 -d " "`
82 LOGIN_USER=`whoami`
83 LOGIN_IP=`who am i | awk {print $5} | sed s/[()]//g`
84 
85 # 记录SQL执行日志
86 echo -e "`date "+%Y-%m-%d %H:%M:%S"`\t${HOST_IP}\t${LOGIN_USER}@${LOGIN_IP}\t[${SQL_CONTENT}]" >> ${MYSQL_LOG_PATH}
mysql_sdbc.sh

 

Jenkins-job创建MavenDeploy Job