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
d62e561c
Commit
d62e561c
authored
Apr 13, 2018
by
wentao.suo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
99d7a3c5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
182 additions
and
151 deletions
+182
-151
StageBucket.groovy
src/org/qg/docker_new/StageBucket.groovy
+104
-73
qgDockerPiplineWithDockerSlave.groovy
vars/qgDockerPiplineWithDockerSlave.groovy
+78
-78
No files found.
src/org/qg/docker_new/StageBucket.groovy
View file @
d62e561c
...
@@ -14,7 +14,7 @@ def debug() {
...
@@ -14,7 +14,7 @@ def debug() {
def
contextMkdir
(
key
)
{
def
contextMkdir
(
key
)
{
uuid
=
UUID
.
randomUUID
().
toString
()
uuid
=
UUID
.
randomUUID
().
toString
()
contextDir
=
"/home/quant_group/package/${key}"
contextDir
=
"/home/quant_group/package/${key}"
sh
"mkdir -p ${contextDir}"
sh
"mkdir -p ${contextDir}"
return
contextDir
return
contextDir
}
}
...
@@ -64,13 +64,13 @@ def prepare_luaui(systemName, contextDir) {
...
@@ -64,13 +64,13 @@ def prepare_luaui(systemName, contextDir) {
def
isVhFileExist
=
fileExists
"/home/quant_group/config_repository/lua-ui/nginx/${systemName}.vh.conf"
def
isVhFileExist
=
fileExists
"/home/quant_group/config_repository/lua-ui/nginx/${systemName}.vh.conf"
if
(
isVhFileExist
)
{
if
(
isVhFileExist
)
{
sh
"cp -rf /home/quant_group/config_repository/lua-ui/nginx/${systemName}.vh.conf ${contextDir}"
sh
"cp -rf /home/quant_group/config_repository/lua-ui/nginx/${systemName}.vh.conf ${contextDir}"
}
else
{
}
else
{
sh
"cp -rf /home/quant_group/config_repository/lua-ui/nginx/default.vh.conf ${contextDir}"
sh
"cp -rf /home/quant_group/config_repository/lua-ui/nginx/default.vh.conf ${contextDir}"
}
}
sh
"cp -rf /home/quant_group/config_repository/lua-ui/config/${systemName}.js ${systemName}.env.config.js"
sh
"cp -rf /home/quant_group/config_repository/lua-ui/config/${systemName}.js ${systemName}.env.config.js"
}
}
...
@@ -112,20 +112,20 @@ def checkout_nodejs(systemName, branchName) {
...
@@ -112,20 +112,20 @@ def checkout_nodejs(systemName, branchName) {
def
projectAttr
=
project_attr
(
systemName
)
def
projectAttr
=
project_attr
(
systemName
)
def
gitPath
=
projectAttr
[
"gitPath"
]
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"
)
def
folder
=
new
File
(
"${currentPath}/.git/hooks"
)
if
(
!
folder
.
exists
()){
if
(
!
folder
.
exists
()){
git
branch:
branchName
,
credentialsId:
'e1ccb1ac-1282-4fb4-b766-530ca1a2a2db'
,
url:
gitPath
git
branch:
branchName
,
credentialsId:
'e1ccb1ac-1282-4fb4-b766-530ca1a2a2db'
,
url:
gitPath
def
bowerFile
=
fileExists
'./bower.json'
def
bowerFile
=
fileExists
'./bower.json'
if
(
bowerFile
)
{
if
(
bowerFile
)
{
sh
"bower install --allow-root"
sh
"bower install --allow-root"
}
}
sh
"npm install"
sh
"npm install"
}
else
{
}
else
{
sh
"cp -rf /home/quant_group/config_repository/lua-ui/hook/post-checkout .git/hooks/"
sh
"cp -rf /home/quant_group/config_repository/lua-ui/hook/post-checkout .git/hooks/"
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
}
}
...
@@ -195,13 +195,13 @@ def build(buildType,systemName, contextDir){
...
@@ -195,13 +195,13 @@ def build(buildType,systemName, contextDir){
}
}
def
build_java
(
systemName
,
contextDir
)
{
def
build_java
(
systemName
,
contextDir
)
{
def
projectAttr
=
project_attr
(
systemName
)
def
projectAttr
=
project_attr
(
systemName
)
buildCmd
=
projectAttr
[
"buildCmd"
]
buildCmd
=
projectAttr
[
"buildCmd"
]
jarFilePath
=
projectAttr
[
"jarFilePath"
]
jarFilePath
=
projectAttr
[
"jarFilePath"
]
sh
buildCmd
sh
buildCmd
sh
"cp ${jarFilePath}/*.jar ${contextDir}/app.jar"
sh
"cp ${jarFilePath}/*.jar ${contextDir}/app.jar"
}
}
def
build_nodejs
(
systemName
,
contextDir
)
{
def
build_nodejs
(
systemName
,
contextDir
)
{
...
@@ -265,49 +265,69 @@ def update_microservice(namespace, name, image, tier) {
...
@@ -265,49 +265,69 @@ def update_microservice(namespace, name, image, tier) {
return
res_json
return
res_json
}
}
def
getDocketPackageImage
(
buildType
){
echo
"getDocketPackageImage :${buildType}"
def
slaveImageRespority
(
buildEnv
){
def
args
=
""
//envType java8 java9 node7 node8
def
packageImageInfo
=[:]
switch
(
envType
){
catch
"java8"
:
return
"192.168.4.36/baseimg/docker-jenkins-slave:2018041202"
break
catch
"java9"
:
return
null
break
catch
"node7"
:
return
"192.168.4.36/baseimg/jenkins-node7-slave:2018041301"
break
catch
"node8"
:
return
"192.168.4.36/baseimg/jenkins-node8-slave:2018041301"
break
default
:
return
"192.168.4.36/baseimg/docker-jenkins-slave:2018041202"
}
packageImageInfo
[
"image"
]
=
"192.168.4.36/baseimg/docker-jenkins-slave:2018041202"
}
def
slaveImageArgs
(
buildType
){
def
args
=
""
args
+=
"-v /home/quant_group/qg-dockerfiles:/home/quant_group/qg-dockerfiles "
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/config_repository:/home/quant_group/config_repository "
args
+=
"-v /home/quant_group/package/:/home/quant_group/package/ "
args
+=
"-v /home/quant_group/package/:/home/quant_group/package/ "
switch
(
buildType
)
{
switch
(
buildType
)
{
case
"java"
:
case
"java"
:
args
+=
"-v /root/.m2:/root/.m2 "
args
+=
"-v /root/.m2:/root/.m2 "
packageImageInfo
[
"args"
]
=
args
break
break
case
"nodejs"
:
case
"nodejs"
:
args
+=
"-v /root/.npm:/root/.npm:rw "
args
+=
"-v /root/.npm:/root/.npm:rw "
args
+=
"-v /root/.cache:/root/.cache: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 "
packageImageInfo
[
"args"
]
=
args
break
break
case
"python"
:
case
"python"
:
packageImageInfo
[
"args"
]
=
""
break
break
case
"lua-ui"
:
case
"lua-ui"
:
args
+=
"-v /root/.npm:/root/.npm:rw "
args
+=
"-v /root/.npm:/root/.npm:rw "
args
+=
"-v /root/.cache:/root/.cache: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 "
packageImageInfo
[
"image"
]
=
"192.168.4.36/baseimg/docker-jenkins-slave:2018041204"
packageImageInfo
[
"args"
]
=
args
break
break
default:
default:
echo
""
_utils
()
.
beautyEcho
(
"未知的buildType: ${buildType}"
,
"info"
)
packageImageInfo
[
"image"
]
=
""
packageImageInfo
[
"args"
]
=
""
break
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
(
"image :"
+
packageImageInfo
[
"image"
],
"info"
)
_utils
().
beautyEcho
(
"args :"
+
packageImageInfo
[
"args"
],
"info"
)
_utils
().
beautyEcho
(
"args :"
+
packageImageInfo
[
"args"
],
"info"
)
return
packageImageInfo
return
packageImageInfo
...
@@ -315,6 +335,21 @@ def getDocketPackageImage(buildType){
...
@@ -315,6 +335,21 @@ def getDocketPackageImage(buildType){
def
check_and_build
(
buildType
,
systemName
,
branchName
,
contextDir
){
def
check_and_build
(
buildType
,
systemName
,
branchName
,
contextDir
){
def
buildEnv
=
""
switch
(
buildType
){
case
"java"
buildEnv
=
"java8"
break
case
"lua-ui"
buildEnv
=
"node8"
if
(
systemName
==
"xyqb-ui"
){
buildEnv
=
"node7"
}
break
default
:
buildEnv
=
"java8"
}
def
pacegeDockerInfo
=
getDocketPackageImage
(
buildType
)
def
pacegeDockerInfo
=
getDocketPackageImage
(
buildType
)
docker
.
image
(
pacegeDockerInfo
[
"image"
]).
inside
(
pacegeDockerInfo
[
"args"
]){
docker
.
image
(
pacegeDockerInfo
[
"image"
]).
inside
(
pacegeDockerInfo
[
"args"
]){
...
@@ -331,54 +366,50 @@ def check_and_build(buildType,systemName,branchName,contextDir){
...
@@ -331,54 +366,50 @@ def check_and_build(buildType,systemName,branchName,contextDir){
stage
(
'Build'
){
stage
(
'Build'
){
build
(
buildType
,
systemName
,
contextDir
)
build
(
buildType
,
systemName
,
contextDir
)
}
}
}
}
}
}
def
dockerbuild_and_push
(
imageTag
,
buildNumber
,
systemName
,
branchName
,
cluster
,
timeStemp
){
def
dockerbuild_and_push
(
imageTag
,
buildNumber
,
systemName
,
branchName
,
cluster
,
timeStemp
){
//systemName == originSystemName
//systemName == originSystemName
stage
(
'Docker Build And Push'
)
{
stage
(
'Docker Build And Push'
)
{
withDockerRegistry
([
credentialsId:
'harbor-qajenkins'
,
url:
"http://192.168.4.36"
])
{
withDockerRegistry
([
credentialsId:
'harbor-qajenkins'
,
url:
"http://192.168.4.36"
])
{
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}@CLUSTER:${cluster}"
echo
build_schema
echo
build_schema
def
args
=
""
def
args
=
""
args
+=
"--build-arg BUILD_TIME=${timeStemp} "
args
+=
"--build-arg BUILD_TIME=${timeStemp} "
args
+=
"--build-arg BUILD_NUMBER=${buildNumber} "
args
+=
"--build-arg BUILD_NUMBER=${buildNumber} "
args
+=
"--build-arg SYSTEM_NAME=${systemName} "
args
+=
"--build-arg SYSTEM_NAME=${systemName} "
args
+=
"--build-arg BRANCH_NAME=${branchName} "
args
+=
"--build-arg BRANCH_NAME=${branchName} "
args
+=
"--build-arg SAFE_SYSTEM_NAME=${systemName} "
args
+=
"--build-arg SAFE_SYSTEM_NAME=${systemName} "
args
+=
"--build-arg BUILD_SCHEMA=${build_schema} "
args
+=
"--build-arg BUILD_SCHEMA=${build_schema} "
def
image
=
docker
.
build
(
imageTag
,
"${args} ${contextDir}"
)
def
image
=
docker
.
build
(
imageTag
,
"${args} ${contextDir}"
)
image
.
push
()
image
.
push
()
if
(
branchName
==
"master"
||
branchName
==
"master--master"
)
{
if
(
branchName
==
"master"
||
branchName
==
"master--master"
)
{
image
.
push
(
'latest'
)
image
.
push
(
'latest'
)
}
}
_utils
().
beautyEcho
(
"镜像地址:${imageTag}"
,
"info"
)
_utils
().
beautyEcho
(
"镜像地址:${imageTag}"
,
"info"
)
}
}
}
}
}
}
def
deploy
(
namespace
,
systemName
,
imageTag
,
tier
,
isDeploy
)
{
def
deploy
(
namespace
,
systemName
,
imageTag
,
tier
,
isDeploy
)
{
stage
(
'Deploy To K8s Cluster'
){
stage
(
'Deploy To K8s Cluster'
){
def
deploy_job_info
def
deploy_job_info
if
(
isDeploy
==
"true"
)
{
if
(
isDeploy
==
"true"
)
{
_utils
().
beautyEcho
(
"[新集群][deployV2]将镜像更新到到Namespace:"
+
namespace
,
"info"
)
_utils
().
beautyEcho
(
"[新集群][deployV2]将镜像更新到到Namespace:"
+
namespace
,
"info"
)
update_microservice
(
namespace
,
systemName
,
imageTag
,
tier
)
update_microservice
(
namespace
,
systemName
,
imageTag
,
tier
)
}
else
{
}
else
{
_utils
().
beautyEcho
(
"isDeploy == false,不执行deploy"
,
"info"
)
_utils
().
beautyEcho
(
"isDeploy == false,不执行deploy"
,
"info"
)
}
}
}
}
}
}
/*def dockerbuild_and_push(timeNow, buildNumber, branchName, harborGroup, systemName, contextDir) {
/*def dockerbuild_and_push(timeNow, buildNumber, branchName, harborGroup, systemName, contextDir) {
...
...
vars/qgDockerPiplineWithDockerSlave.groovy
View file @
d62e561c
...
@@ -5,98 +5,98 @@ def call(body) {
...
@@ -5,98 +5,98 @@ def call(body) {
ansiColor
(
'xterm'
)
{
ansiColor
(
'xterm'
)
{
def
harborGroup
=
"library"
def
harborGroup
=
"library"
def
_stage
=
new
org
.
qg
.
docker_new
.
StageBucket
()
def
_stage
=
new
org
.
qg
.
docker_new
.
StageBucket
()
def
_utils
=
new
org
.
qg
.
docker_new
.
Utils
()
def
_utils
=
new
org
.
qg
.
docker_new
.
Utils
()
def
config
=
[:]
def
config
=
[:]
def
timeStemp
=
new
Date
().
format
(
"yyyyMMddHHmmss"
)
def
timeStemp
=
new
Date
().
format
(
"yyyyMMddHHmmss"
)
def
env
=
body
.
env
def
env
=
body
.
env
def
gitRepo
=
env
.
GIT_REPO
def
gitRepo
=
env
.
GIT_REPO
def
originBranchName
=
env
.
BRANCH_NAME
def
originBranchName
=
env
.
BRANCH_NAME
def
namespace
=
env
.
NAMESPACE
def
namespace
=
env
.
NAMESPACE
def
isDeploy
=
env
.
IS_DEPLOY
def
isDeploy
=
env
.
IS_DEPLOY
def
buildNumber
=
env
.
BUILD_NUMBER
def
buildNumber
=
env
.
BUILD_NUMBER
def
cluster
=
env
.
CLUSTER
def
cluster
=
env
.
CLUSTER
// QG/XXX or QG--QG/systemName--systemName
// QG/XXX or QG--QG/systemName--systemName
t
=
gitRepo
.
split
(
"/"
)
t
=
gitRepo
.
split
(
"/"
)
def
gitGroup
=
t
[
0
]
def
gitGroup
=
t
[
0
]
// systemName or systemName--systemName
// systemName or systemName--systemName
def
originSystemName
=
t
[
1
]
def
originSystemName
=
t
[
1
]
// ["",""]
// ["",""]
def
systemNames
=
originSystemName
.
split
(
"--"
)
def
systemNames
=
originSystemName
.
split
(
"--"
)
def
branchNames
=
originBranchName
.
split
(
"--"
)
def
branchNames
=
originBranchName
.
split
(
"--"
)
def
contextDir
def
contextDir
def
imageTag
def
imageTag
body
.
resolveStrategy
=
Closure
.
DELEGATE_FIRST
body
.
resolveStrategy
=
Closure
.
DELEGATE_FIRST
body
.
delegate
=
config
body
.
delegate
=
config
body
()
body
()
node
{
node
{
try
{
try
{
echo
config
.
buildType
echo
config
.
buildType
/* 1 */
/* 1 */
stage
(
'Init'
)
{
stage
(
'Init'
)
{
_utils
.
beautyEcho
(
"Init"
,
"stage"
)
_utils
.
beautyEcho
(
"Init"
,
"stage"
)
contextDir
=
_stage
.
contextMkdir
(
"${originSystemName}-${timeStemp}"
)
contextDir
=
_stage
.
contextMkdir
(
"${originSystemName}-${timeStemp}"
)
_stage
.
before_prepare
()
_stage
.
before_prepare
()
}
}
/* 2 */
withDockerServer
([
uri:
"tcp://192.168.4.96:2375/"
])
{
/* 2 */
_utils
.
beautyEcho
(
"checkout & build < ${originSystemName} : ${originBranchName} >"
,
"stage"
)
withDockerServer
([
uri:
"tcp://192.168.4.96:2375/"
])
{
_utils
.
beautyEcho
(
"checkout & build < ${originSystemName} : ${originBranchName} >"
,
"stage"
)
for
(
def
i
=
0
;
i
<
systemNames
.
length
;
i
++){
for
(
def
i
=
0
;
i
<
systemNames
.
length
;
i
++){
dir
(
systemNames
[
i
]){
dir
(
systemNames
[
i
]){
_stage
.
check_and_build
(
config
.
buildType
,
systemNames
[
i
],
branchNames
[
i
],
contextDir
)
_stage
.
check_and_build
(
config
.
buildType
,
systemNames
[
i
],
branchNames
[
i
],
contextDir
)
}
}
}
_utils
.
beautyEcho
(
"build over"
,
"info"
)
}
}
/* 3 */
_utils
.
beautyEcho
(
"build over"
,
"info"
)
withDockerServer
([
uri:
"tcp://192.168.4.96:2375/"
])
{
_utils
.
beautyEcho
(
"make docker image"
,
"stage"
)
}
def
regex
=
"[`,./;\\[\\]&<>?:\"()|-]+"
/* 3 */
withDockerServer
([
uri:
"tcp://192.168.4.96:2375/"
])
{
_utils
.
beautyEcho
(
"make docker image"
,
"stage"
)
def
regex
=
"[`,./;\\[\\]&<>?:\"()|-]+"
def
k8sSystemName
=
originSystemName
.
replaceAll
(
"_"
,
"-"
)
def
k8sSystemName
=
originSystemName
.
replaceAll
(
"_"
,
"-"
)
def
safeBranchName
=
originBranchName
.
replaceAll
(
regex
,
"_"
)
def
safeBranchName
=
originBranchName
.
replaceAll
(
regex
,
"_"
)
imageTag
=
_stage
.
imageTag
(
harborGroup
,
k8sSystemName
,
safeBranchName
,
timeStemp
)
imageTag
=
_stage
.
imageTag
(
harborGroup
,
k8sSystemName
,
safeBranchName
,
timeStemp
)
def
_systemName
=
originSystemName
.
toLowerCase
()
_stage
.
dockerbuild_and_push
(
imageTag
,
buildNumber
,
_systemName
,
originBranchName
,
cluster
,
timeStemp
)
_utils
.
beautyEcho
(
"Deploy To K8s Cluster image: ${imageTag} to:${namespace}"
,
"stage"
)
_stage
.
deploy
(
namespace
,
_systemName
,
imageTag
,
config
.
tier
,
isDeploy
)
}
def
_systemName
=
originSystemName
.
toLowerCase
()
_stage
.
dockerbuild_and_push
(
imageTag
,
buildNumber
,
_systemName
,
originBranchName
,
cluster
,
timeStemp
)
/* 4 */
stage
(
'Clean'
){
_utils
.
beautyEcho
(
"Deploy To K8s Cluster image: ${imageTag} to:${namespace}"
,
"stage"
)
_utils
.
beautyEcho
(
"Clear Cache Tmp"
,
"stage"
)
_stage
.
deploy
(
namespace
,
_systemName
,
imageTag
,
config
.
tier
,
isDeploy
)
_stage
.
clean_images
(
imageTag
,
contextDir
)
}
}
/* 4 */
stage
(
'Clean'
){
_utils
.
beautyEcho
(
"Clear Cache Tmp"
,
"stage"
)
_stage
.
clean_images
(
imageTag
,
contextDir
)
}
}
catch
(
err
)
{
}
catch
(
err
)
{
_utils
.
beautyEcho
(
err
,
"fail"
)
_utils
.
beautyEcho
(
err
,
"fail"
)
_stage
.
clean_images
(
imageTag
,
contextDir
)
_stage
.
clean_images
(
imageTag
,
contextDir
)
throw
err
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