Commit 00247c2c authored by kewei.jia's avatar kewei.jia

发送 执行ID

parent 130d7035
......@@ -3,7 +3,7 @@ package org.qg.docker_new;
import org.qg.docker_new.Utils;
import groovy.json.JsonSlurperClassic;
def _utils() {
def _utils() {
return new org.qg.docker_new.Utils();
}
......@@ -19,14 +19,14 @@ def contextMkdir(key) {
}
def imageTag(harborGroup,k8sSystemName,safeBranchName,tagName){
def imageTag4_4=[:]
def imageTag4_4=[:]
imageTag4_4["harborHost"]="http://192.168.4.4"
imageTag4_4["imageTag"] = "${harborGroup}/${k8sSystemName}:${safeBranchName}-${tagName}"
imageTag4_4["imageTagCode"] = "${harborGroup}/${k8sSystemName}:Code${safeBranchName}-${tagName}"
return [ imageTag4_4 ]
}
def init_dependency() {
def init_dependency() {
sh "cd /home/quant_group/qg-dockerfiles; git pull; cd -"
sh "cd /home/quant_group/config_repository; git pull origin master; cd -"
}
......@@ -35,7 +35,7 @@ def init_image_dependency(buildType,originSystemName,contextDir){
switch (buildType){
case "lua-ui":
sh "cp -rf /home/quant_group/qg-dockerfiles/tke/ui/* ${contextDir}"
def isVhFileExist = fileExists "/home/quant_group/config_repository/lua-ui/nginx/${originSystemName}.vh.conf"
if (isVhFileExist) {
sh "cp -rf /home/quant_group/config_repository/lua-ui/nginx/${originSystemName}.vh.conf ${contextDir}"
......@@ -43,7 +43,7 @@ def init_image_dependency(buildType,originSystemName,contextDir){
sh "cp -rf /home/quant_group/config_repository/lua-ui/nginx/default.vh.conf ${contextDir}"
}
break
default:
default:
break
}
}
......@@ -81,7 +81,7 @@ def update_microservice(namespace, name, image, tier, domain) {
response = httpRequest httpMode:"POST",
consoleLogResponseBody:true,
contentType:"APPLICATION_JSON",
contentType:"APPLICATION_JSON",
requestBody:"""{
"namespace":"${namespace}",
"serviceName":"${name}",
......@@ -92,38 +92,50 @@ def update_microservice(namespace, name, image, tier, domain) {
"debug":0
}""",
url:dest_url
def res_json = jsonParse(response.content)
return res_json
}
def ding_talk(buildNumber,flag) {
dest_url = "http://192.168.29.80:3003/pipeline/dingTalk"
response = httpRequest httpMode:"POST",
consoleLogResponseBody:true,
contentType:"APPLICATION_JSON",
requestBody:"""{
"buildNumber":"${buildNumber}",
"flag":"${flag}",
}""",
url:dest_url
}
def set_image_info(microservice_name, git_commit_hash, image) {
dest_url = "http://eos.quantgroups.com/api/etcd/set_image_info"
response = httpRequest httpMode:"POST",
consoleLogResponseBody:true,
contentType:"APPLICATION_JSON",
contentType:"APPLICATION_JSON",
requestBody:"""{
"microservice_name":"${microservice_name}",
"git_commit_hash":"${git_commit_hash}",
"image": "${image}"
}""",
url:dest_url
def res_json = jsonParse(response.content)
return res_json
}
def slaveImageRespority(buildEnv){
//envType java8 java9 node7 node8
switch(buildEnv){
case "java8":
// return "192.168.4.4/baseimg/jenkins-java-slave:latest"
return "192.168.4.4/baseimg/jenkins-java-slave-new:latest"
break
case "java9":
return null
return null
break
case "node7":
return "192.168.4.4/baseimg/jenkins-node7-slave:latest"
......@@ -143,49 +155,49 @@ def slaveImageArgs(buildType){
args += "-v /home/quant_group/package/:/home/quant_group/package/ "
switch (buildType) {
case "java":
args += "-v /root/.m2:/root/.m2 "
args += "-v /root/.m2:/root/.m2 "
break
case "nodejs":
args += "-v /root/.nvm/versions/node/v8.9.1/bin:/usr/local/node-v8.9.1-linux-x64/bin "
args += "-v /root/.npm:/root/.npm:rw "
args += "-v /root/.cache:/root/.cache:rw "
args += "-v /root/.node-gyp:/root/.node-gyp:rw "
break
break
case "python":
break
case "lua-ui":
args += "-v /root/.nvm/versions/node/v8.9.1/bin:/usr/local/node-v8.9.1-linux-x64/bin "
args += "-v /root/.npm:/root/.npm:rw "
args += "-v /root/.cache:/root/.cache:rw "
args += "-v /root/.node-gyp:/root/.node-gyp:rw "
args += "-v /root/.node-gyp:/root/.node-gyp:rw "
break
default:
default:
break
}
return args
}
def getDocketPackageImage(buildType,buildEnv){
echo "getDocketPackageImage :${buildType}"
def packageImageInfo=[:]
def packageImageInfo=[:]
packageImageInfo["image"] = slaveImageRespority(buildEnv)
packageImageInfo["args"] = slaveImageArgs(buildType)
_utils().beautyEcho("image :"+ packageImageInfo["image"], "info")
_utils().beautyEcho("args :"+ packageImageInfo["args"], "info")
return packageImageInfo
}
def check_and_build(buildType,systemName,branchName,contextDir){
def branchHashCode = null
def buildEnv =""
switch(buildType){
case "java":
......@@ -198,28 +210,28 @@ def check_and_build(buildType,systemName,branchName,contextDir){
}
break
case "nodejs":
buildEnv = "node8"
buildEnv = "node8"
break
default :
buildEnv ="java8"
}
def pacegeDockerInfo = getDocketPackageImage(buildType,buildEnv)
if (buildType in ["nodejs","lua-ui"]){
branchHashCode = cpb(buildType,systemName,branchName,contextDir)
} else {
} else {
docker.image(pacegeDockerInfo["image"]).inside(pacegeDockerInfo["args"]){
branchHashCode = cpb(buildType,systemName,branchName,contextDir)
}
}
}
return branchHashCode
}
def cpb(buildType,systemName,branchName,contextDir){
/*checkout code*/
stage('Checkout') {
branchHashCode = checkout(buildType, systemName, branchName)
}
......@@ -244,7 +256,7 @@ def checkout(buildType,systemName, branchName) {
switch(buildType){
case "java":
checkout_java(systemName, branchName)
break
break
case "nodejs":
checkout_nodejs(systemName, branchName)
break
......@@ -253,17 +265,17 @@ def checkout(buildType,systemName, branchName) {
break
case "lua-ui":
checkout_luaui(systemName, branchName)
break
break
default:
echo "未知的buildType: ${buildType}"
break
}
def brahHashCode = sh (script: 'git log -1 --pretty=%H',returnStdout: true).trim()
brahHashCode = brahHashCode.substring(0,16)
echo "brahHashCode:${brahHashCode} with 'git log -1 --pretty=%H'"
return brahHashCode
}
def checkout_java(systemName, branchName) {
......@@ -281,13 +293,13 @@ def checkout_python(systemName, branchName) {
def checkout_nodejs(systemName, branchName) {
sh "cp -rf /home/quant_group/qg-dockerfiles/tke/ui/npmrc/common-npmrc /root/.npmrc"
def projectAttr = project_attr(systemName)
def gitPath =projectAttr["gitPath"]
currentPath = sh (script: 'pwd',returnStdout: true).trim()
currentPath = sh (script: 'pwd',returnStdout: true).trim()
def folder = new File( "${currentPath}/.git/hooks" )
echo "${currentPath}/.git/hooks"
echo "${currentPath}/.git/hooks"
if( !folder.exists()){
echo ">>>>>>>>> first git clone"
git branch: branchName, credentialsId: 'e1ccb1ac-1282-4fb4-b766-530ca1a2a2db', url: gitPath
......@@ -295,47 +307,47 @@ def checkout_nodejs(systemName, branchName) {
if (bowerFile) {
sh "bower install --allow-root"
}
} else {
echo ">>>>>>>>> not first git clone"
// sh "cp -rf /home/quant_group/config_repository/lua-ui/hook/post-checkout .git/hooks/"
// 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"
}
def checkout_luaui(systemName, branchName) {
currentPath = sh (script: 'pwd',returnStdout: true).trim()
currentPath = sh (script: 'pwd',returnStdout: true).trim()
echo "- ${currentPath} -"
sh "whoami"
echo "----------------------------"
// def npmrcPath = "/home/quant_group/config_repository/lua-ui/npmrc/${systemName}-npmrc"
// def specialNpmrc = new File( npmrcPath )
// if(specialNpmrc.exists()){
// sh "cp -rf ${npmrcPath} .npmrc"
// sh "cp -rf ${npmrcPath} .npmrc"
// }
_utils().beautyEcho("ui project : ${systemName}" , "info")
projectAttr = project_attr(systemName)
gitPath = projectAttr["gitPath"]
//0 if project is simple ui not run npm install
def hookfolder = new File( "${currentPath}/.git/hooks" )
def packejson = new File( "${currentPath}/package.json" )
sh "cp -rf /home/quant_group/qg-dockerfiles/tke/ui/npmrc/common-npmrc /root/.npmrc"
if(!hookfolder.exists()){
echo ">>>>>>> first checkout project ${systemName}"
git branch: branchName, credentialsId: 'e1ccb1ac-1282-4fb4-b766-530ca1a2a2db', url: gitPath
def bowerResult = ext_bower_install()
def npmResult = ext_npm_intall()
def resultNum = bowerResult +npmResult
if(resultNum ==0){
echo ">>>>>>> is simple ui project"
def dist = fileExists './dist'
......@@ -346,12 +358,12 @@ def checkout_luaui(systemName, branchName) {
} else {
echo ">>>>>>> is node ui project"
def bowerFile = fileExists './bower.json'
sh "npm install"
sh "npm install"
if (bowerFile) {
sh "bower install --allow-root"
}
}
}
}else{
if(!packejson.exists()){
echo ">>>>>>> is simple ui project"
......@@ -365,11 +377,11 @@ def checkout_luaui(systemName, branchName) {
echo ">>>>>>> is node ui project"
// sh "cp -rf /home/quant_group/config_repository/lua-ui/hook/post-checkout .git/hooks/"
// sh "chmod +x .git/hooks/post-checkout"
git branch: branchName, credentialsId: 'e1ccb1ac-1282-4fb4-b766-530ca1a2a2db', url: gitPath
sh "npm install"
sh "npm install"
}
}
}
}
def prepare_config(buildType,systemName, contextDir) {
......@@ -395,9 +407,9 @@ def prepare_config(buildType,systemName, contextDir) {
def prepare_java(systemName, contextDir) {
sh "cp -rf /home/quant_group/qg-dockerfiles/tke/java/* ${contextDir}"
def existProperties = fileExists "/home/quant_group/config_repository/tke/java/${systemName}.properties"
echo "------ java properties exist :$existProperties ------"
if(existProperties){
sh "cp -rf /home/quant_group/config_repository/tke/java/${systemName}.properties ${contextDir}/application.properties"
......@@ -413,7 +425,7 @@ def prepare_nodejs(systemName, contextDir) {
// sh "cp -rf /home/quant_group/qg-dockerfiles/tke/ui/npmrc/common-npmrc /root/.npmrc"
}
def prepare_luaui(systemName, contextDir) {
def prepare_luaui(systemName, contextDir) {
sh "cp -rf /home/quant_group/qg-dockerfiles/tke/ui/npmrc/common-npmrc /root/.npmrc"
}
......@@ -429,7 +441,7 @@ def build(buildType,systemName, branchName,contextDir){
switch(buildType){
case "java":
build_java(systemName, branchName,contextDir)
break
break
case "nodejs":
sh "which node"
sh "node -v"
......@@ -444,31 +456,31 @@ def build(buildType,systemName, branchName,contextDir){
sh "node -v"
sh "npm -v"
build_luaui( systemName, branchName,contextDir)
break
break
default:
echo "未知的buildType: ${buildType}"
break
}
}
}
def build_java(systemName, branchName,contextDir) {
def projectAttr = project_attr(systemName)
buildCmd = projectAttr["buildCmd"]
jarFilePath = projectAttr["jarFilePath"]
sh "mkdir ${contextDir}/lib ${contextDir}/config;touch ${contextDir}/lib/lib.txt;touch ${contextDir}/config/config.txt"
sh 'mvn -v'
sh buildCmd
sh "mv ${jarFilePath}/*.jar ${contextDir}/app.jar"
currentPath = sh (script: 'pwd',returnStdout: true).trim()
currentPath = sh (script: 'pwd',returnStdout: true).trim()
def libfolder = new File( "${currentPath}/target/lib" )
echo "${currentPath}/target/lib is exist : ${libfolder.exists()}"
if (libfolder.exists()){
sh "mv ${jarFilePath}/lib/* ${contextDir}/lib"
}
def configfolder = new File( "${currentPath}/target/config" )
echo "${currentPath}/target/config is exist : ${configfolder.exists()}"
if (configfolder.exists()){
......@@ -476,13 +488,13 @@ def build_java(systemName, branchName,contextDir) {
}
}
def build_nodejs( systemName, branchName,contextDir) {
def build_nodejs( systemName, branchName,contextDir) {
def projectAttr = project_attr(systemName)
configPath = projectAttr["configPath"]
buildCmd = projectAttr["buildCmd"]
configName = systemName
sh "mv -f ./${systemName}.env.config ${configPath}"
sh "tar zcf ${contextDir}/dist.tgz ./* "
sh "cp -rf package.json ${contextDir}"
......@@ -492,31 +504,31 @@ def build_nodejs( systemName, branchName,contextDir) {
def build_python( systemName, branchName,contextDir) {
// sh "cp -rf ${contextDir}/config.ini server/config/release/config.ini"
// sh "cp -rf ${contextDir}/config.ini server/config/beta/config.ini"
def projectAttr = project_attr(systemName)
configPath = projectAttr["configPath"]
sh "cp -rf ${contextDir}/config.ini ${configPath}"
sh "tar zcf ${contextDir}/dist.tgz ./*"
// sh "mv dist.tgz ${contextDir}"
}
def build_luaui( systemName, branchName,contextDir) {
def build_luaui( systemName, branchName,contextDir) {
def projectAttr = project_attr(systemName)
configPath = projectAttr["configPath"]
buildCmd = projectAttr["buildCmd"]
configName = systemName
currentPath = sh (script: 'pwd',returnStdout: true).trim()
if(systemName=='xjd-ui' && branchName == 'apollo'){
sh "npm run build"
} else {
// sh "mv -f ./${systemName}.env.config ${configPath}"
sh buildCmd
}
}
sh "tar zcf ${systemName}.tgz dist/"
sh "mv ${systemName}.tgz ${contextDir}"
}
......@@ -575,7 +587,7 @@ def dockerbuild_and_push(imageTagInfo,buildNumber,systemName,branchName,cluster,
def deploy(namespace, systemName, imageTag, tier, isDeploy) {
stage('Deploy To K8s Cluster'){
_utils().beautyEcho("Deploy To K8S Cluster image: ${imageTag} to:${namespace}", "info")
_utils().beautyEcho("Deploy To K8S Cluster image: ${imageTag} to:${namespace}", "info")
if (isDeploy=="true") {
def projectAttr = project_attr(systemName)
......
......@@ -3,17 +3,17 @@
*/
def call(body) {
ansiColor('xterm') {
// def harborGroup = "library"
def _stage = new org.qg.docker_new.StageBucketTke()
def _utils = new org.qg.docker_new.Utils()
def config = [:]
def timeStemp = new Date().format("yyyyMMddHHmmssSSS")
def env = body.env
def env = body.env
def gitRepo = env.GIT_REPO
def originBranchName = env.BRANCH_NAME
def namespace = env.NAMESPACE
......@@ -27,26 +27,26 @@ def call(body) {
t = gitRepo.split("/")
def gitGroup = t[0]
// systemName or systemName--systemName
def originSystemName = t[1]
def originSystemName = t[1]
// ["",""]
def systemNames = originSystemName.split("--")
def branchNames = originBranchName.split("--")
def contextDir
def imageTagInfos
def branchHashCode
def branchHashCode
body.resolveStrategy = Closure.DELEGATE_FIRST
body.delegate = config
body()
if(config.harborGroup != null){
harborGroup = config.harborGroup
}
node {
try {
node {
try {
echo config.buildType
/* 1 */
stage('Init') {
......@@ -55,7 +55,7 @@ def call(body) {
_stage.init_dependency()
_stage.init_image_dependency(config.buildType,originSystemName,contextDir)
}
/* 2 */
echo originSystemName
withDockerServer([uri: "tcp://192.168.4.96:2375/"]) {
......@@ -65,17 +65,17 @@ def call(body) {
branchHashCode = _stage.check_and_build(config.buildType, systemNames[i], branchNames[i], contextDir)
}
}
_utils.beautyEcho("build over", "info")
_utils.beautyEcho("build over", "info")
}
/* 3 */
withDockerServer([uri: "tcp://192.168.4.96:2375/"]) {
_utils.beautyEcho("make docker image", "stage")
_utils.beautyEcho("make docker image", "stage")
/*def _systemName = originSystemName.toLowerCase()*/
def regex = "[`,./;\\[\\]&<>?:\"()|-]+"
def k8sSystemName = originSystemName.replaceAll("_","-").toLowerCase()
def safeBranchName = originBranchName.replaceAll(regex,"_").toLowerCase()
imageTagInfos = _stage.imageTag(harborGroup,k8sSystemName,safeBranchName,timeStemp)
for (imageTagInfo in imageTagInfos){
......@@ -83,20 +83,22 @@ def call(body) {
}
_stage.deploy(namespace, originSystemName, imageTagInfos[0]["imageTag"], config.tier, isDeploy)
}
/* 4 */
stage('Clean'){
_utils.beautyEcho("Clear Cache Tmp", "stage")
_stage.clean_images(imageTagInfos[0]["imageTag"],imageTagInfos[0]["imageTagCode"],contextDir,config.buildType)
_stage.ding_talk(buildNumber,"success")
}
} catch (err) {
_utils.beautyEcho(err, "fail")
_stage.ding_talk(buildNumber,"fail")
if(imageTagInfos != null){
_stage.clean_images(imageTagInfos[0]["imageTag"],imageTagInfos[0]["imageTagCode"],contextDir,config.buildType)
}
throw err
}
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