Commit 67ee9440 authored by 智勇's avatar 智勇

up

parent 6be1525f
package org.qg.ci;
import org.qg.docker_new.Utils;
import groovy.json.JsonOutput
import groovy.json.JsonSlurperClassic;
def _utils() {
return new org.qg.docker_new.Utils();
}
@NonCPS
def jsonParse(def json) {
new groovy.json.JsonSlurperClassic().parseText(json)
}
def project_attr(systemName) {
response = httpRequest "http://qaapi.liangkebang.com/proconfig/get_info?system_name=${systemName}"
def res_json = jsonParse(response.content)
return res_json["data"]
}
def sonar_job(branchHashCode) {
response = httpRequest "http://qaapi.liangkebang.com/sonar/getSonarJob?branchHash=${branchHashCode}"
def res_json = jsonParse(response.content)
return res_json["data"]
}
def checkout(GIT_REPO,BRANCH_NAME){
def projectAttr = project_attr(GIT_REPO)
git_path = projectAttr["git_path"]
git branch: "${BRANCH_NAME}", credentialsId: 'e1ccb1ac-1282-4fb4-b766-530ca1a2a2db', url: "${git_path}"
}
def sonar_check(GIT_REPO,BRANCH_NAME,FORCE_SCAN){
body =[:]
def branchHashCode = sh (script: 'git log -1 --pretty=%H',returnStdout: true).trim()
echo "branchHashCode: ${branchHashCode} with 'git log -1 --pretty=%H'"
def sonarJob = sonar_job(branchHashCode)
if (FORCE_SCAN != 'true' && sonarJob && sonarJob["sonarResult"]) {
body["sonarJob"] = sonarJob
echo "本次扫描的代码曾经扫描过,扫描结果:${sonarJob["sonarResult"]}"
} else {
_utils().beautyEcho("sonar scan +++", "info")
sonarScanner = "/home/quant_group/jenkins_home/tools/hudson.plugins.sonar.SonarRunnerInstallation/sonar/bin/sonar-scanner"
currentPath = sh (script: 'pwd',returnStdout: true).trim()
sh "${sonarScanner} -e \
-Dsonar.host.url=http://sonar.quantgroups.com \
-Dsonar.projectVersion=${BRANCH_NAME} \
-Dsonar.projectKey=${GIT_REPO} \
-Dsonar.java.binaries=. \
-Dsonar.sources=. \
-Dsonar.java.source=1.8 \
-Dsonar.java.target=1.8 \
-Dsonar.projectBaseDir=${currentPath}"
sleep 3
sonarInfo = sh (script: 'cat .sonar/report-task.txt |awk \'{printf $0 "&"}\'',returnStdout: true).trim()
items = sonarInfo.split("&")
def content=[:]
for (def item : items){
itemSplit = item.split("=",2)
content[itemSplit[0]] =itemSplit[1]
}
body["content"] = content
body["branchHash"] = branchHashCode
body["duration"] = currentBuild.duration
}
return body
}
def call_back(body,callbackHost,dingRobotAddr){
body["dingRobotAddr"] = dingRobotAddr
body["project"] = GIT_REPO
body["branch"] = BRANCH_NAME
body["buildId"] = currentBuild.number
body["buildJob"] = env.JOB_NAME
def bodyJson = JsonOutput.toJson(body)
echo bodyJson
response = httpRequest httpMode:"POST",
consoleLogResponseBody:true,
contentType:"APPLICATION_JSON",
requestBody:"${bodyJson}",
url:callbackHost
}
def callback_error(error,callbackHost,dingRobotAddr) {
body =[:]
body["error"] = error.message
body["absoluteUrl"] = currentBuild.absoluteUrl
call_back(body,callbackHost,dingRobotAddr)
}
...@@ -233,7 +233,7 @@ def checkout_luaui(systemName, branchName) { ...@@ -233,7 +233,7 @@ def checkout_luaui(systemName, branchName) {
} else { } else {
echo ">>>>>>> is node ui project" echo ">>>>>>> is node ui project"
def bowerFile = fileExists './bower.json' def bowerFile = fileExists './bower.json'
sh "npm install" sh "sudo npm install"
if (bowerFile) { if (bowerFile) {
sh "bower install --allow-root" sh "bower install --allow-root"
} }
...@@ -256,7 +256,7 @@ def checkout_luaui(systemName, branchName) { ...@@ -256,7 +256,7 @@ def checkout_luaui(systemName, branchName) {
sh "chmod +x .git/hooks/post-checkout" sh "chmod +x .git/hooks/post-checkout"
git branch: branchName, credentialsId: 'e1ccb1ac-1282-4fb4-b766-530ca1a2a2db', url: gitPath git branch: branchName, credentialsId: 'e1ccb1ac-1282-4fb4-b766-530ca1a2a2db', url: gitPath
sh "npm install" sh "sudo npm install"
} }
} }
......
...@@ -121,7 +121,7 @@ def update_microservice_qke(namespace, name, image, tier, domain, cluster) { ...@@ -121,7 +121,7 @@ def update_microservice_qke(namespace, name, image, tier, domain, cluster) {
} }
def ding_talk(buildNumber,flags) { def ding_talk(buildNumber,flags) {
dest_url = "http://172.30.220.22:3003/pipeline/dingTalk" dest_url = "http://qaapi.liangkebang.com/pipeline/dingTalk"
response = httpRequest httpMode:"POST", response = httpRequest httpMode:"POST",
consoleLogResponseBody:true, consoleLogResponseBody:true,
...@@ -492,6 +492,7 @@ def build_java(systemName, branchName,contextDir) { ...@@ -492,6 +492,7 @@ def build_java(systemName, branchName,contextDir) {
sh "mkdir ${contextDir}/lib ${contextDir}/config;touch ${contextDir}/lib/lib.txt;touch ${contextDir}/config/config.txt" sh "mkdir ${contextDir}/lib ${contextDir}/config;touch ${contextDir}/lib/lib.txt;touch ${contextDir}/config/config.txt"
sh 'mvn -v' sh 'mvn -v'
sh 'env'
sh buildCmd sh buildCmd
sh "mv ${jarFilePath}/*.jar ${contextDir}/app.jar" sh "mv ${jarFilePath}/*.jar ${contextDir}/app.jar"
...@@ -601,7 +602,7 @@ def ding_talk_back(buildNumber,flags,image,cluster,tier,systemName) { ...@@ -601,7 +602,7 @@ def ding_talk_back(buildNumber,flags,image,cluster,tier,systemName) {
echo flags echo flags
echo image echo image
echo cluster echo cluster
dest_url = "http://172.30.220.22:3003/pipeline/dingTalk" dest_url = "http://qaapi.liangkebang.com/pipeline/dingTalk"
response = httpRequest httpMode:"POST", response = httpRequest httpMode:"POST",
consoleLogResponseBody:true, consoleLogResponseBody:true,
contentType:"APPLICATION_JSON", contentType:"APPLICATION_JSON",
......
This diff is collapsed.
def call(body) {
def _stage = new org.qg.ci.SonarStageBucketTke()
def _utils = new org.qg.docker_new.Utils()
def env = body.env
def GIT_REPO = env.GIT_REPO
def BRANCH_NAME = env.BRANCH_NAME
def FORCE_SCAN = env.FORCE_SCAN
def GIT_TRIGGER_USER = env.GIT_TRIGGER_USER
def config = [:]
def data
body.resolveStrategy = Closure.DELEGATE_FIRST
body.delegate = config
body()
def callbackHost = config.callbackHost
def dingRobotAddr = config.dingRobotAddr
def schemaInfo = ""+
"\033[32m############################################\n"+
"# GIT_REPO:${GIT_REPO}\n"+
"# BRANCH_NAME:${BRANCH_NAME}\n"+
"# FORCE_SCAN:${FORCE_SCAN}\n"+
"# GIT_TRIGGER_USER:${GIT_TRIGGER_USER}\n"+
"# COMMIT_MESSAGE:${COMMIT_MESSAGE}\n"+
"# CallbackHost:${callbackHost}\n"+
"# DingRobotAddr:${dingRobotAddr}\n"+
"############################################\033[0m"
ansiColor('xterm') {
echo schemaInfo
node {
dir(GIT_REPO){
try {
stage("Checkout"){
_utils.beautyEcho("Checkout +++", "stage")
_stage.checkout(GIT_REPO,BRANCH_NAME)
}
stage("Sonar scan"){
_utils.beautyEcho("Sonar scan +++", "stage")
data = _stage.sonar_check(GIT_REPO,BRANCH_NAME,FORCE_SCAN)
}
stage("Callback sonar analysis"){
_utils.beautyEcho("Callback sonar analysis +++", "stage")
_stage.call_back(data,callbackHost,dingRobotAddr)
}
} catch (err) {
_stage.callback_error(err,callbackHost,,dingRobotAddr)
throw err
}
}
}
}
}
...@@ -47,6 +47,11 @@ def call(body) { ...@@ -47,6 +47,11 @@ def call(body) {
try { try {
echo config.buildType echo config.buildType
environment {
CLASSPATH = '.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/sa-jdi.jar'
}
/* 1 */ /* 1 */
stage('Init') { stage('Init') {
_utils.beautyEcho("Init", "stage") _utils.beautyEcho("Init", "stage")
...@@ -57,6 +62,7 @@ def call(body) { ...@@ -57,6 +62,7 @@ def call(body) {
/* 2 */ /* 2 */
echo originSystemName echo originSystemName
echo "test ${CLASSPATH}"
withDockerServer([uri: "tcp://192.168.4.96:2375/"]) { withDockerServer([uri: "tcp://192.168.4.96:2375/"]) {
_utils.beautyEcho("checkout & build < ${originSystemName} : ${originBranchName} >", "stage") _utils.beautyEcho("checkout & build < ${originSystemName} : ${originBranchName} >", "stage")
for(def i = 0; i<systemNames.length; i++){ for(def i = 0; i<systemNames.length; i++){
...@@ -78,7 +84,13 @@ def call(body) { ...@@ -78,7 +84,13 @@ def call(body) {
imageTagInfos = _stage.imageTag(harborGroup,k8sSystemName,safeBranchName,timeStemp) imageTagInfos = _stage.imageTag(harborGroup,k8sSystemName,safeBranchName,timeStemp)
for (imageTagInfo in imageTagInfos){ for (imageTagInfo in imageTagInfos){
_stage.dockerbuild_and_push(imageTagInfo,buildNumber,originSystemName,originBranchName,timeStemp,contextDir,branchHashCode,config.buildType) try {
_stage.dockerbuild_and_push(imageTagInfo,buildNumber,originSystemName,originBranchName,timeStemp,contextDir,branchHashCode,config.buildType)
}
catch(err) {
_utils.beautyEcho(err, "fail")
_stage.ding_talk_back(buildNumber,"fail",imageTagInfos[0]["imageTag"],cluster,config.tier,originSystemName)
}
} }
_stage.deploy(namespace, originSystemName, imageTagInfos[0]["imageTag"], config.tier, isDeploy, cluster) _stage.deploy(namespace, originSystemName, imageTagInfos[0]["imageTag"], config.tier, isDeploy, cluster)
} }
......
def call(body) {
ansiColor('xterm') {
def _stage = new org.qg.docker_new.StageBucketTke2()
def _sonarStage = new org.qg.ci.SonarStageBucketTke()
def _utils = new org.qg.docker_new.Utils()
def config = [:]
def timeStemp = new Date().format("yyyyMMddHHmmssSSS")
def env = body.env
def systemName = env.GIT_REPO
def branchName = env.BRANCH_NAME
def namespace = env.NAMESPACE
def isDeploy = env.DEPLOY
def buildNumber = env.BUILD_NUMBER
def cluster = env.CLUSTER
def contextDir
def imageTagInfos
def branchHashCode
def imageTagInfo = [:]
def sonarJob
body.resolveStrategy = Closure.DELEGATE_FIRST
body.delegate = config
body()
def sonarCallback = config.sonarCallback
def pipesCallback = config.pipesCallback
def dingRobotAddr = config.dingRobotAddr
if(config.imageRepo != null){
imageRepo = config.imageRepo
}
node {
try {
echo config.buildType
/* 1 */
stage('Init') {
_utils.beautyEcho("Init", "stage")
contextDir = _stage.contextMkdir("${systemName}-${timeStemp}")
_stage.init_dependency()
// _stage.init_image_dependency(config.buildType,systemName,contextDir)
}
/* 2 */
echo systemName
withDockerServer([uri: "tcp://192.168.4.96:2375/"]) {
_utils.beautyEcho("checkout & build < ${systemName} : ${branchName} >", "stage")
dir(systemName){
branchHashCode = _stage.check_and_build(config.buildType, systemName, branchName, contextDir)
}
_utils.beautyEcho("build over", "info")
}
stage("Sonar Check"){
_utils.beautyEcho("sonar check +++", "stage")
dir(systemName){
_stage.get_sonar_check(systemName,branchName,pipesCallback,sonarCallback,dingRobotAddr,branchHashCode)
}
_utils.beautyEcho("sonar check over", "info")
}
/* 3 */
withDockerServer([uri: "tcp://192.168.4.96:2375/"]) {
_utils.beautyEcho("make docker image", "stage")
def regex = "[`,./;\\[\\]&<>?:\"()|-]+"
def k8sSystemName = systemName.replaceAll("_","-").toLowerCase()
def safeBranchName = branchName.replaceAll(regex,"_").toLowerCase()
imageTagInfo = _stage.imageTag(imageRepo,k8sSystemName,safeBranchName,timeStemp)
_stage.dockerbuild_and_push(imageTagInfo,buildNumber,systemName,branchName,timeStemp,contextDir)
_stage.deploy(namespace, systemName, imageTagInfo["imageTag"], config.tier, isDeploy, cluster)
}
/* 4 */
stage('Clean'){
_utils.beautyEcho("Clear Cache Tmp", "stage")
_stage.clean_images(imageTagInfo["imageTag"],contextDir)
_stage.ding_talk_suc(pipesCallback,"success",dingRobotAddr,systemName,imageTagInfo["imageTag"],cluster,config.tier)
}
} catch (err) {
_utils.beautyEcho(err, "fail")
_stage.ding_talk_error(pipesCallback,"runError",dingRobotAddr,systemName,branchName,err.message,sonarJob)
_stage.clean_images(imageTagInfo["imageTag"],contextDir)
throw err
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment