Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
global-jenkinsfile
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
QA
global-jenkinsfile
Commits
67ee9440
Commit
67ee9440
authored
Nov 23, 2019
by
智勇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
up
parent
6be1525f
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
966 additions
and
5 deletions
+966
-5
SonarStageBucketTke.groovy
src/org/qg/ci/SonarStageBucketTke.groovy
+93
-0
StageBucket.groovy
src/org/qg/docker_new/StageBucket.groovy
+2
-2
StageBucketTke.groovy
src/org/qg/docker_new/StageBucketTke.groovy
+3
-2
StageBucketTke2.groovy
src/org/qg/docker_new/StageBucketTke2.groovy
+708
-0
qgCiSonarTke.groovy
vars/qgCiSonarTke.groovy
+55
-0
qgDockerPiplineWithDockerSlaveTke.groovy
vars/qgDockerPiplineWithDockerSlaveTke.groovy
+13
-1
qgDockerPiplineWithDockerSlaveTke2.groovy
vars/qgDockerPiplineWithDockerSlaveTke2.groovy
+92
-0
No files found.
src/org/qg/ci/SonarStageBucketTke.groovy
0 → 100644
View file @
67ee9440
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
)
}
src/org/qg/docker_new/StageBucket.groovy
View file @
67ee9440
...
@@ -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"
}
}
}
}
...
...
src/org/qg/docker_new/StageBucketTke.groovy
View file @
67ee9440
...
@@ -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"
,
...
...
src/org/qg/docker_new/StageBucketTke2.groovy
0 → 100644
View file @
67ee9440
// src/org/foo/Stage.groovy
package
org.qg.docker_new
;
import
org.qg.docker_new.Utils
;
import
groovy.json.JsonOutput
import
groovy.json.JsonSlurperClassic
;
def
_sonarStage
()
{
return
new
org
.
qg
.
ci
.
SonarStageBucketTke
();
}
def
_utils
()
{
return
new
org
.
qg
.
docker_new
.
Utils
();
}
def
debug
()
{
_utils
().
beautyEcho
(
"debug"
,
"info"
)
}
def
contextMkdir
(
key
)
{
uuid
=
UUID
.
randomUUID
().
toString
()
contextDir
=
"/home/quant_group/package/${key}"
sh
"mkdir -p ${contextDir}"
return
contextDir
}
def
imageTag
(
harborGroup
,
k8sSystemName
,
safeBranchName
,
tagName
){
def
imageTag4_4
=[:]
imageTag4_4
[
"harborHost"
]=
"http://192.168.4.4"
imageTag4_4
[
"imageTag"
]
=
"${harborGroup}/${k8sSystemName}:${safeBranchName}-${tagName}"
return
imageTag4_4
}
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 -"
}
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}"
}
else
{
sh
"cp -rf /home/quant_group/config_repository/lua-ui/nginx/default.vh.conf ${contextDir}"
}
break
default:
break
}
}
def
ext_bower_install
(){
def
bowerFile
=
fileExists
'./bower.json'
if
(
bowerFile
){
sh
"bower install --allow-root"
return
1
}
return
0
}
def
ext_npm_intall
(){
def
packageFile
=
fileExists
'./package.json'
if
(
packageFile
){
// sh "npm install"
return
1
}
return
0
}
@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
pipeline_job
(
branchHashCode
)
{
response
=
httpRequest
"http://qaapi.liangkebang.com/pipeline/getBuildInfoByHooks?buildId=${currentBuild.number}&buildJob=${env.JOB_NAME}"
def
res_json
=
jsonParse
(
response
.
content
)
return
res_json
[
"data"
]
}
def
update_microservice
(
namespace
,
name
,
image
,
tier
,
domain
,
cluster
)
{
dest_url
=
"http://qaapi.liangkebang.com/k8s/service/modifyImage"
response
=
httpRequest
httpMode:
"POST"
,
consoleLogResponseBody:
true
,
contentType:
"APPLICATION_JSON"
,
customHeaders:
[[
name:
'cluster'
,
value:
"${cluster}"
]],
requestBody:
"""{
"namespace":"${namespace}",
"serviceName":"${name}",
"image":"${image}",
"label":"${tier}",
"type":"${tier}",
"domain":"${domain}",
"debug":0
}"""
,
url:
dest_url
def
res_json
=
jsonParse
(
response
.
content
)
return
res_json
}
// for test
def
update_microservice_qke
(
namespace
,
name
,
image
,
tier
,
domain
,
cluster
)
{
dest_url
=
"http://qaapi.liangkebang.com/k8s/service/modifyImage"
response
=
httpRequest
httpMode:
"POST"
,
consoleLogResponseBody:
true
,
contentType:
"APPLICATION_JSON"
,
customHeaders:
[[
name:
'cluster'
,
value:
"${cluster}"
]],
requestBody:
"""{
"namespace":"${namespace}",
"serviceName":"${name}",
"image":"${image}",
"label":"${tier}",
"type":"${tier}",
"domain":"${domain}",
"debug":0
}"""
,
url:
dest_url
def
res_json
=
jsonParse
(
response
.
content
)
return
res_json
}
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"
,
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
break
case
"node7"
:
return
"192.168.4.4/baseimg/jenkins-node7-slave:latest"
break
case
"node8"
:
return
"192.168.4.4/baseimg/jenkins-node8-slave:latest"
break
default
:
return
"192.168.4.4/baseimg/jenkins-slave:latest"
}
}
def
slaveImageArgs
(
buildType
){
def
args
=
""
args
+=
"-v /home/quant_group/qg-dockerfiles:/home/quant_group/qg-dockerfiles "
args
+=
"-v /home/quant_group/config_repository:/home/quant_group/config_repository "
args
+=
"-v /home/quant_group/package/:/home/quant_group/package/ "
switch
(
buildType
)
{
case
"java"
:
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
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 "
break
default:
break
}
return
args
}
def
getDocketPackageImage
(
buildType
,
buildEnv
){
echo
"getDocketPackageImage :${buildType}"
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"
:
buildEnv
=
"java8"
break
case
"python"
:
buildEnv
=
"python"
break
case
"lua-ui"
:
buildEnv
=
"node8"
if
(
systemName
in
[
"xyqb-ui"
]){
buildEnv
=
"node7"
}
break
case
"nodejs"
:
buildEnv
=
"node8"
break
default
:
buildEnv
=
"java8"
}
def
pacegeDockerInfo
=
getDocketPackageImage
(
buildType
,
buildEnv
)
if
(
buildType
in
[
"nodejs"
,
"lua-ui"
]){
branchHashCode
=
cpb
(
buildType
,
systemName
,
branchName
,
contextDir
)
}
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
)
}
/*prepare config*/
stage
(
'Prepare'
)
{
if
(
systemName
==
'xjd-ui'
&&
branchName
==
'apollo'
){
_utils
().
beautyEcho
(
"xjd-ui : apollo not exec prepare_config"
,
"info"
)
}
else
{
prepare_config
(
buildType
,
systemName
,
contextDir
)
}
}
/*build*/
stage
(
'Build'
){
build
(
buildType
,
systemName
,
branchName
,
contextDir
)
}
return
branchHashCode
}
def
checkout
(
buildType
,
systemName
,
branchName
)
{
_utils
().
beautyEcho
(
"CheckOut +++ type:${buildType} systemName:${systemName} branchName:${branchName}"
,
"info"
)
switch
(
buildType
){
case
"java"
:
checkout_java
(
systemName
,
branchName
)
break
case
"nodejs"
:
checkout_nodejs
(
systemName
,
branchName
)
break
case
"python"
:
checkout_python
(
systemName
,
branchName
)
break
case
"lua-ui"
:
checkout_luaui
(
systemName
,
branchName
)
break
default:
echo
"未知的buildType: ${buildType}"
break
}
def
branchHashCode
=
sh
(
script:
'git log -1 --pretty=%H'
,
returnStdout:
true
).
trim
()
echo
"branchHashCode : ${branchHashCode} with 'git log -1 --pretty=%H'"
return
branchHashCode
}
def
checkout_java
(
systemName
,
branchName
)
{
def
projectAttr
=
project_attr
(
systemName
)
def
gitPath
=
projectAttr
[
"git_path"
]
def
configPath
=
projectAttr
[
"config_path"
]
git
branch:
branchName
,
credentialsId:
'e1ccb1ac-1282-4fb4-b766-530ca1a2a2db'
,
url:
gitPath
}
def
checkout_python
(
systemName
,
branchName
)
{
def
projectAttr
=
project_attr
(
systemName
)
def
gitPath
=
projectAttr
[
"git_path"
]
git
branch:
branchName
,
credentialsId:
'e1ccb1ac-1282-4fb4-b766-530ca1a2a2db'
,
url:
gitPath
}
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
[
"git_path"
]
currentPath
=
sh
(
script:
'pwd'
,
returnStdout:
true
).
trim
()
def
folder
=
new
File
(
"${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
def
bowerFile
=
fileExists
'./bower.json'
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
}
// sh "npm install"
}
def
checkout_luaui
(
systemName
,
branchName
)
{
currentPath
=
sh
(
script:
'pwd'
,
returnStdout:
true
).
trim
()
echo
"- ${currentPath} -"
sh
"whoami"
// 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"
// }
_utils
().
beautyEcho
(
"ui project : ${systemName}"
,
"info"
)
projectAttr
=
project_attr
(
systemName
)
gitPath
=
projectAttr
[
"git_path"
]
//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'
if
(!
dist
){
sh
"mkdir dist"
}
return
}
else
{
echo
">>>>>>> is node ui project"
def
bowerFile
=
fileExists
'./bower.json'
sh
"npm install"
if
(
bowerFile
)
{
sh
"bower install --allow-root"
}
}
}
else
{
if
(!
packejson
.
exists
()){
echo
">>>>>>> is simple ui project"
git
branch:
branchName
,
credentialsId:
'e1ccb1ac-1282-4fb4-b766-530ca1a2a2db'
,
url:
gitPath
def
dist
=
fileExists
'./dist'
if
(!
dist
){
sh
"mkdir dist"
}
return
}
else
{
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"
}
}
}
def
prepare_config
(
buildType
,
systemName
,
contextDir
)
{
_utils
().
beautyEcho
(
"Prepare Config +++ type:${buildType} systemName:${systemName}"
,
"info"
)
switch
(
buildType
)
{
case
"java"
:
prepare_java
(
systemName
,
contextDir
)
break
case
"nodejs"
:
prepare_nodejs
(
systemName
,
contextDir
)
break
case
"python"
:
prepare_python
(
systemName
,
contextDir
)
break
case
"lua-ui"
:
prepare_luaui
(
systemName
,
contextDir
)
break
default:
_utils
().
beautyEcho
(
"未知的buildType: ${buildType}"
,
"fail"
)
break
}
}
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"
}
else
{
sh
"cp -rf /home/quant_group/config_repository/tke/java/null.properties ${contextDir}/application.properties"
}
}
def
prepare_nodejs
(
systemName
,
contextDir
)
{
sh
"cp -rf /home/quant_group/qg-dockerfiles/tke/nodejs/* ${contextDir}"
sh
"cp -rf /home/quant_group/config_repository/tke/nodejs/${systemName}.js ${systemName}.env.config"
sh
"cp -rf /home/quant_group/qg-dockerfiles/tke/ui/npmrc/common-npmrc ${contextDir}/.npmrc"
// sh "cp -rf /home/quant_group/qg-dockerfiles/tke/ui/npmrc/common-npmrc /root/.npmrc"
}
def
prepare_luaui
(
systemName
,
contextDir
)
{
sh
"cp -rf /home/quant_group/qg-dockerfiles/tke/ui/npmrc/common-npmrc /root/.npmrc"
}
def
prepare_python
(
systemName
,
contextDir
)
{
// sh "rm -rf ${contextDir}"
sh
"cp -rf /home/quant_group/qg-dockerfiles/tke/python/* ${contextDir}"
sh
"cp -rf /home/quant_group/config_repository/python/${systemName}.ini ${contextDir}/config.ini"
}
def
build
(
buildType
,
systemName
,
branchName
,
contextDir
){
sh
'echo $PATH'
_utils
().
beautyEcho
(
"Build +++ type:${buildType} systemName:${systemName}"
,
"info"
)
switch
(
buildType
){
case
"java"
:
build_java
(
systemName
,
branchName
,
contextDir
)
break
case
"nodejs"
:
sh
"which node"
sh
"node -v"
sh
"npm -v"
build_nodejs
(
systemName
,
branchName
,
contextDir
)
break
case
"python"
:
build_python
(
systemName
,
branchName
,
contextDir
)
break
case
"lua-ui"
:
sh
"which node"
sh
"node -v"
sh
"npm -v"
build_luaui
(
systemName
,
branchName
,
contextDir
)
break
default:
echo
"未知的buildType: ${buildType}"
break
}
}
def
build_java
(
systemName
,
branchName
,
contextDir
)
{
def
projectAttr
=
project_attr
(
systemName
)
buildCmd
=
projectAttr
[
"build_command"
]
jarFilePath
=
projectAttr
[
"jar_path"
]
sh
"mkdir ${contextDir}/lib ${contextDir}/config;touch ${contextDir}/lib/lib.txt;touch ${contextDir}/config/config.txt"
sh
'mvn -v'
sh
'env'
sh
buildCmd
sh
"mv ${jarFilePath}/*.jar ${contextDir}/app.jar"
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
()){
sh
"mv ${jarFilePath}/config/* ${contextDir}/config"
}
}
def
build_nodejs
(
systemName
,
branchName
,
contextDir
)
{
def
projectAttr
=
project_attr
(
systemName
)
configPath
=
projectAttr
[
"config_path"
]
buildCmd
=
projectAttr
[
"build_command"
]
configName
=
systemName
sh
"mv -f ./${systemName}.env.config ${configPath}"
sh
"tar zcf ${contextDir}/dist.tgz ./* "
sh
"cp -rf package.json ${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
[
"config_path"
]
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
projectAttr
=
project_attr
(
systemName
)
configPath
=
projectAttr
[
"config_path"
]
buildCmd
=
projectAttr
[
"build_command"
]
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}"
}
def
dockerbuild_and_push
(
imageTagInfo
,
buildNumber
,
systemName
,
branchName
,
timeStemp
,
contextDir
){
def
harbor_host
=
imageTagInfo
[
"harborHost"
]
def
imageTag
=
imageTagInfo
[
"imageTag"
]
stage
(
'Docker Build And Push'
)
{
withDockerRegistry
([
credentialsId:
'harbor-qajenkins'
,
url:
harbor_host
])
{
def
build_schema
=
"BUILD_TIME:${timeStemp}@BUILD_NUMBER:${buildNumber}@SYSTEM_NAME:${systemName}@BRANCH_NAME:${branchName}"
echo
build_schema
def
args
=
""
args
+=
"--build-arg BUILD_TIME=${timeStemp} "
args
+=
"--build-arg BUILD_NUMBER=${buildNumber} "
args
+=
"--build-arg SYSTEM_NAME=${systemName} "
args
+=
"--build-arg BRANCH_NAME=${branchName} "
args
+=
"--build-arg SAFE_SYSTEM_NAME=${systemName} "
args
+=
"--build-arg BUILD_SCHEMA=${build_schema} "
def
image
if
(
systemName
==
"smart-recruitment"
||
systemName
==
"smart-recruitment-spyder"
){
image
=
docker
.
build
(
imageTag
,
"${args} -f ${contextDir}/smart.Dockerfile ${contextDir}"
)
}
else
{
image
=
docker
.
build
(
imageTag
,
"${args} ${contextDir}"
)
}
image
.
push
()
if
(
branchName
==
"master"
||
branchName
==
"master--master"
)
{
image
.
push
(
'latest'
)
}
_utils
().
beautyEcho
(
"镜像地址:${imageTag}"
,
"info"
)
}
}
}
def
deploy
(
namespace
,
systemName
,
imageTag
,
tier
,
isDeploy
,
cluster
)
{
stage
(
'Deploy To K8s Cluster'
){
_utils
().
beautyEcho
(
"Deploy To K8S Cluster image: ${imageTag} to:${namespace}"
,
"info"
)
if
(
isDeploy
==
"true"
)
{
def
projectAttr
=
project_attr
(
systemName
)
def
host
=
projectAttr
[
"host_name"
]
def
hostArray
=
host
.
split
(
"\\."
)
imageTag
=
imageTag
.
replaceAll
(
"ccr.ccs.tencentyun.com/"
,
""
)
_utils
().
beautyEcho
(
"[新集群][deployV2]将镜像更新到到Namespace:"
+
namespace
,
"info"
)
// update_microservice(namespace, systemName, imageTag, tier, hostArray[0], cluster)
// for test
if
(
cluster
==
'qke'
){
update_microservice_qke
(
namespace
,
systemName
,
imageTag
,
tier
,
hostArray
[
0
],
cluster
)
}
else
{
update_microservice
(
namespace
,
systemName
,
imageTag
,
tier
,
hostArray
[
0
],
'qa'
)
}
}
else
{
_utils
().
beautyEcho
(
"isDeploy == false,不执行deploy"
,
"info"
)
}
}
}
def
ding_talk_error
(
pipesCallback
,
flag
,
dingRobotAddr
,
projectName
,
branchName
,
msg
,
sonarJob
)
{
// 如果不是sonar exit
if
(
msg
!=
'script returned exit code 111'
){
body
=[:]
body
[
"flag"
]
=
flag
body
[
"dingRobotAddr"
]
=
dingRobotAddr
body
[
"projectName"
]
=
projectName
body
[
"branchName"
]
=
branchName
body
[
"msg"
]
=
msg
body
[
"sonarJob"
]
=
sonarJob
send_req
(
body
,
pipesCallback
)
}
}
def
ding_talk_suc
(
pipesCallback
,
flag
,
dingRobotAddr
,
projectName
,
image
,
cluster
,
tier
)
{
image
=
image
.
replaceAll
(
"ccr.ccs.tencentyun.com/"
,
""
)
def
projectAttr
=
project_attr
(
projectName
)
def
host
=
projectAttr
[
"host_name"
]
def
hostArray
=
host
.
split
(
"\\."
)
body
=[:]
body
[
"flag"
]
=
flag
body
[
"dingRobotAddr"
]
=
dingRobotAddr
body
[
"domain"
]
=
hostArray
[
0
]
body
[
"image"
]
=
image
body
[
"cluster"
]
=
cluster
body
[
"tier"
]
=
tier
send_req
(
body
,
pipesCallback
)
}
def
send_req
(
body
,
pipesCallback
){
body
[
"buildId"
]
=
currentBuild
.
number
body
[
"buildJob"
]
=
env
.
JOB_NAME
body
[
"absoluteUrl"
]
=
currentBuild
.
absoluteUrl
bodyJson
=
JsonOutput
.
toJson
(
body
)
response
=
httpRequest
httpMode:
"POST"
,
consoleLogResponseBody:
true
,
contentType:
"APPLICATION_JSON"
,
// customHeaders: [[name:'cluster', value:"${cluster}"]],
requestBody:
"${bodyJson}"
,
url:
pipesCallback
}
def
get_sonar_check
(
systemName
,
branchName
,
pipesCallback
,
sonarCallback
,
dingRobotAddr
,
branchHashCode
)
{
def
projectAttr
=
project_attr
(
systemName
)
if
(
projectAttr
[
"sonar"
]){
_utils
().
beautyEcho
(
"sonar check +++"
,
"info"
)
def
sonarJob
def
pipelineJob
=
pipeline_job
()
if
(!
pipelineJob
){
echo
"手动触发的job"
// 手动触发一次sonar
data
=
_sonarStage
().
sonar_check
(
systemName
,
branchName
,
'true'
)
_sonarStage
().
call_back
(
data
,
sonarCallback
,
dingRobotAddr
)
}
// 等待200s,cash-loan-flow的sonar需要三分半
for
(
int
i
=
0
;
i
<
40
;
i
++){
sonarJob
=
sonar_job
(
branchHashCode
)
echo
"sonarJob : ${sonarJob}"
if
(
sonarJob
&&
sonarJob
[
"sonarResult"
]){
if
(
sonarJob
[
"sonarResult"
]
!=
'OK'
){
echo
">>>>>>> sonar check fail : ${sonarJob["
sonarResult
"]}"
_utils
().
beautyEcho
(
"没有通过Sonar质量阀,退出Jenkins build"
,
"fail"
)
ding_talk_error
(
pipesCallback
,
"notOK"
,
dingRobotAddr
,
systemName
,
branchName
,
"没有通过Sonar质量阀,退出流水线"
,
sonarJob
)
sh
'exit 111'
}
else
{
echo
">>>>>>> sonar check pass"
break
}
}
echo
"等待sonar扫描执行结果,一般服务在1分钟内,个别大服务需要等待3分钟左右,比如cash-loan-flow、clotho等"
sleep
5
}
if
(!
sonarJob
[
"sonarResult"
]){
echo
">>>>>>> sonar check fail : ${sonarJob}"
_utils
().
beautyEcho
(
"获取sonar分析结果超时,退出Jenkins build"
,
"fail"
)
ding_talk_error
(
pipesCallback
,
"timeout"
,
dingRobotAddr
,
systemName
,
branchName
,
"获取sonar分析结果超时,退出流水线"
,
sonarJob
)
sh
'exit 111'
}
}
else
{
echo
"不执行sonar,跳过扫描"
}
}
def
clean_images
(
imageTag
,
contextDir
)
{
sh
"rm -rf ${contextDir}"
if
(
imageTag
){
sh
"docker rmi -f \$(docker images -q ${imageTag})"
}
}
vars/qgCiSonarTke.groovy
0 → 100644
View file @
67ee9440
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
}
}
}
}
}
vars/qgDockerPiplineWithDockerSlaveTke.groovy
View file @
67ee9440
...
@@ -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
)
}
}
...
...
vars/qgDockerPiplineWithDockerSlaveTke2.groovy
0 → 100644
View file @
67ee9440
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
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment