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
24579acb
Commit
24579acb
authored
Sep 03, 2019
by
智勇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
格式化
parent
2d254821
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
503 additions
and
511 deletions
+503
-511
StageBucketTke.groovy
src/org/qg/docker_new/StageBucketTke.groovy
+499
-507
qgDockerPiplineWithDockerSlaveTke.groovy
vars/qgDockerPiplineWithDockerSlaveTke.groovy
+4
-4
No files found.
src/org/qg/docker_new/StageBucketTke.groovy
View file @
24579acb
...
...
@@ -22,7 +22,6 @@ def imageTag(harborGroup,k8sSystemName,safeBranchName,tagName){
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
]
}
...
...
@@ -35,11 +34,10 @@ 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
{
}
else
{
sh
"cp -rf /home/quant_group/config_repository/lua-ui/nginx/default.vh.conf ${contextDir}"
}
break
...
...
@@ -56,6 +54,7 @@ def ext_bower_install(){
}
return
0
}
def
ext_npm_intall
(){
def
packageFile
=
fileExists
'./package.json'
if
(
packageFile
){
...
...
@@ -76,12 +75,36 @@ def project_attr(systemName) {
return
res_json
}
def
update_microservice
(
namespace
,
name
,
image
,
tier
,
domain
)
{
def
update_microservice
(
namespace
,
name
,
image
,
tier
,
domain
,
cluster
)
{
dest_url
=
"http://172.30.220.22:3003/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://192.168.28.179:3003/k8s/service/modifyImage"
response
=
httpRequest
httpMode:
"POST"
,
consoleLogResponseBody:
true
,
contentType:
"APPLICATION_JSON"
,
customHeaders:
[[
name:
'cluster'
,
value:
"${cluster}"
]],
requestBody:
"""{
"namespace":"${namespace}",
"serviceName":"${name}",
...
...
@@ -96,6 +119,7 @@ def update_microservice(namespace, name, image, tier, domain) {
def
res_json
=
jsonParse
(
response
.
content
)
return
res_json
}
def
ding_talk
(
buildNumber
,
flags
)
{
dest_url
=
"http://172.30.220.22:3003/pipeline/dingTalk"
...
...
@@ -107,8 +131,8 @@ def ding_talk(buildNumber,flags) {
"flag":"${flags}"
}"""
,
url:
dest_url
}
def
set_image_info
(
microservice_name
,
git_commit_hash
,
image
)
{
dest_url
=
"http://eos.quantgroups.com/api/etcd/set_image_info"
...
...
@@ -166,7 +190,6 @@ def slaveImageArgs(buildType){
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 "
...
...
@@ -195,9 +218,7 @@ def getDocketPackageImage(buildType,buildEnv){
}
def
check_and_build
(
buildType
,
systemName
,
branchName
,
contextDir
){
def
branchHashCode
=
null
def
buildEnv
=
""
switch
(
buildType
){
case
"java"
:
...
...
@@ -220,10 +241,8 @@ def check_and_build(buildType,systemName,branchName,contextDir){
}
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
)
...
...
@@ -234,7 +253,6 @@ def check_and_build(buildType,systemName,branchName,contextDir){
def
cpb
(
buildType
,
systemName
,
branchName
,
contextDir
){
/*checkout code*/
stage
(
'Checkout'
)
{
branchHashCode
=
checkout
(
buildType
,
systemName
,
branchName
)
}
...
...
@@ -278,7 +296,6 @@ def checkout(buildType,systemName, branchName) {
brahHashCode
=
brahHashCode
.
substring
(
0
,
16
)
echo
"brahHashCode:${brahHashCode} with 'git log -1 --pretty=%H'"
return
brahHashCode
}
def
checkout_java
(
systemName
,
branchName
)
{
...
...
@@ -318,10 +335,9 @@ def checkout_nodejs(systemName, branchName) {
git
branch:
branchName
,
credentialsId:
'e1ccb1ac-1282-4fb4-b766-530ca1a2a2db'
,
url:
gitPath
}
// sh "npm install"
}
def
checkout_luaui
(
systemName
,
branchName
)
{
def
checkout_luaui
(
systemName
,
branchName
)
{
currentPath
=
sh
(
script:
'pwd'
,
returnStdout:
true
).
trim
()
echo
"- ${currentPath} -"
sh
"whoami"
...
...
@@ -537,15 +553,14 @@ def build_luaui( systemName, branchName,contextDir) {
}
def
dockerbuild_and_push
(
imageTagInfo
,
buildNumber
,
systemName
,
branchName
,
cluster
,
timeStemp
,
contextDir
,
branchHashCode
,
buildType
){
def
dockerbuild_and_push
(
imageTagInfo
,
buildNumber
,
systemName
,
branchName
,
timeStemp
,
contextDir
,
branchHashCode
,
buildType
){
//systemName == originSystemName
def
harbor_host
=
imageTagInfo
[
"harborHost"
]
def
imageTag
=
imageTagInfo
[
"imageTag"
]
def
imageTagCode
=
imageTagInfo
[
"imageTagCode"
]
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}@CLUSTER:${cluster
}"
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} "
...
...
@@ -554,12 +569,7 @@ def dockerbuild_and_push(imageTagInfo,buildNumber,systemName,branchName,cluster,
args
+=
"--build-arg BRANCH_NAME=${branchName} "
args
+=
"--build-arg SAFE_SYSTEM_NAME=${systemName} "
args
+=
"--build-arg BUILD_SCHEMA=${build_schema} "
args
+=
"--build-arg FROM_IMAGE=${imageTagCode} "
if
(
buildType
==
"java"
){
if
(
cluster
==
"pro"
){
def
imageCode
=
docker
.
build
(
imageTagCode
,
"-f ${contextDir}/Code.Dockerfile ${contextDir}"
)
imageCode
.
push
()
}
else
if
(
cluster
==
"test"
)
{
def
image
if
(
systemName
==
"smart-recruitment"
||
systemName
==
"smart-recruitment-spyder"
){
image
=
docker
.
build
(
imageTag
,
"${args} -f ${contextDir}/smart.Dockerfile ${contextDir}"
)
...
...
@@ -571,20 +581,6 @@ def dockerbuild_and_push(imageTagInfo,buildNumber,systemName,branchName,cluster,
if
(
branchName
==
"master"
||
branchName
==
"master--master"
)
{
image
.
push
(
'latest'
)
}
}
}
else
{
if
(
buildType
==
'lua-ui'
){
def
imageCode
=
docker
.
build
(
imageTagCode
,
"-f ${contextDir}/Code.Dockerfile ${contextDir}"
)
imageCode
.
push
()
}
def
image
=
docker
.
build
(
imageTag
,
"${args} ${contextDir}"
)
image
.
push
()
if
(
branchName
==
"master"
||
branchName
==
"master--master"
)
{
image
.
push
(
'latest'
)
}
}
_utils
().
beautyEcho
(
"镜像地址:${imageTag}"
,
"info"
)
}
...
...
@@ -593,7 +589,7 @@ def dockerbuild_and_push(imageTagInfo,buildNumber,systemName,branchName,cluster,
// set_image_info(systemName, branchHashCode, imageTag)
}
def
deploy
(
namespace
,
systemName
,
imageTag
,
tier
,
isDeploy
)
{
def
deploy
(
namespace
,
systemName
,
imageTag
,
tier
,
isDeploy
,
cluster
)
{
stage
(
'Deploy To K8s Cluster'
){
_utils
().
beautyEcho
(
"Deploy To K8S Cluster image: ${imageTag} to:${namespace}"
,
"info"
)
...
...
@@ -603,7 +599,13 @@ def deploy(namespace, systemName, imageTag, tier, isDeploy) {
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
])
// 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
],
cluster
)
}
}
else
{
_utils
().
beautyEcho
(
"isDeploy == false,不执行deploy"
,
"info"
)
}
...
...
@@ -611,17 +613,7 @@ def deploy(namespace, systemName, imageTag, tier, isDeploy) {
}
def
clean_images
(
imageTag
,
imageTagCode
,
contextDir
,
buildType
)
{
def
clean_images
(
imageTag
,
contextDir
,
buildType
)
{
sh
"rm -rf ${contextDir}"
if
(
buildType
==
"java"
){
if
(
cluster
==
"pro"
){
sh
"docker rmi -f \$(docker images -q ${imageTagCode})"
}
else
if
(
cluster
==
"test"
)
{
sh
"docker rmi -f \$(docker images -q ${imageTag})"
}
}
else
{
// sh "docker rmi -f \$(docker images -q ${imageTagCode})"
sh
"docker rmi -f \$(docker images -q ${imageTag})"
}
}
vars/qgDockerPiplineWithDockerSlaveTke.groovy
View file @
24579acb
...
...
@@ -79,22 +79,22 @@ def call(body) {
imageTagInfos
=
_stage
.
imageTag
(
harborGroup
,
k8sSystemName
,
safeBranchName
,
timeStemp
)
for
(
imageTagInfo
in
imageTagInfos
){
_stage
.
dockerbuild_and_push
(
imageTagInfo
,
buildNumber
,
originSystemName
,
originBranchName
,
cluster
,
timeStemp
,
contextDir
,
branchHashCode
,
config
.
buildType
)
_stage
.
dockerbuild_and_push
(
imageTagInfo
,
buildNumber
,
originSystemName
,
originBranchName
,
timeStemp
,
contextDir
,
branchHashCode
,
config
.
buildType
)
}
_stage
.
deploy
(
namespace
,
originSystemName
,
imageTagInfos
[
0
][
"imageTag"
],
config
.
tier
,
isDeploy
)
_stage
.
deploy
(
namespace
,
originSystemName
,
imageTagInfos
[
0
][
"imageTag"
],
config
.
tier
,
isDeploy
,
cluster
)
}
/* 4 */
stage
(
'Clean'
){
_utils
.
beautyEcho
(
"Clear Cache Tmp"
,
"stage"
)
_stage
.
clean_images
(
imageTagInfos
[
0
][
"imageTag"
],
imageTagInfos
[
0
][
"imageTagCode"
],
contextDir
,
config
.
buildType
)
_stage
.
clean_images
(
imageTagInfos
[
0
][
"imageTag"
],
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
)
_stage
.
clean_images
(
imageTagInfos
[
0
][
"imageTag"
],
contextDir
,
config
.
buildType
)
}
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