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
119162e6
Commit
119162e6
authored
Feb 09, 2018
by
daidekun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add eos
parent
2e06fd83
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
225 additions
and
0 deletions
+225
-0
StageBucket.groovy
src/org/qg/tools/StageBucket.groovy
+71
-0
Utils.groovy
src/org/qg/tools/Utils.groovy
+53
-0
qgToolsPipeline.groovy
vars/qgToolsPipeline.groovy
+101
-0
No files found.
src/org/qg/tools/StageBucket.groovy
0 → 100644
View file @
119162e6
// src/org/foo/Stage.groovy
package
org.qg.tools
;
import
org.qg.tools.Utils
;
import
groovy.json.JsonSlurperClassic
;
def
_utils
(){
def
_utils
=
new
org
.
qg
.
tools
.
Utils
();
return
_utils
}
def
before_eos
(
contextDir
)
{
sh
"rm -rf ${contextDir}"
sh
"cd /home/quant_group/qg-dockerfiles; git pull; cd -"
sh
"cd /home/quant_group/config_repository; git pull origin master; cd -"
}
def
prepare_eos
(
contextDir
)
{
sh
"rm -rf ${contextDir}"
sh
"cp -rf /home/quant_group/qg-dockerfiles/tools/python/eos ${contextDir}"
}
def
checkout_eos
()
{
git
branch:
branchName
,
credentialsId:
'e1ccb1ac-1282-4fb4-b766-530ca1a2a2db'
,
url:
"git@git.quantgroup.cn:QA/eos.git"
}
def
build_eos
(
contextDir
)
{
sh
'tar zcf dist.tgz .'
sh
"mv dist.tgz ${contextDir}"
}
def
dockerbuild_and_push
(
buildNumber
,
branchName
,
harborGroup
,
systemName
,
contextDir
)
{
regex
=
"[`,./;\\[\\]&<>?:\"()|-]+"
safeBranchName
=
branchName
.
replaceAll
(
regex
,
"_"
)
safeSystemName
=
"project"
imageTag
=
"192.168.4.36/${harborGroup}/${systemName}:${safeBranchName}-${buildNumber}"
withDockerServer
([
uri:
"tcp://192.168.4.96:2375/"
])
{
withDockerRegistry
([
credentialsId:
'harbor-qajenkins'
,
url:
"http://192.168.4.36"
])
{
def
image
=
docker
.
build
(
imageTag
,
"--build-arg SYSTEM_NAME=${systemName} ${contextDir}"
)
image
.
push
()
}
}
_utils
().
beautyEcho
(
"镜像地址:${imageTag}"
,
"info"
)
return
imageTag
}
def
deploy
(
systemName
,
imageTag
,
tier
)
{
def
deploy_job_info
namespace
=
"default"
_utils
().
beautyEcho
(
"将镜像更新到到Namespace:"
+
namespace
,
"info"
)
deploy_job_info
=
build
job:
'3.deployer.Updater'
,
parameters:
[
string
(
name:
'namespace'
,
value:
namespace
),
string
(
name:
'name'
,
value:
"${systemName}"
),
string
(
name:
'image'
,
value:
"${imageTag}"
),
string
(
name:
'tier'
,
value:
"tools"
)]
log
=
Jenkins
.
getInstance
().
getItemByFullName
(
'3.deployer.Updater'
).
getBuildByNumber
(
deploy_job_info
.
getNumber
()).
logFile
.
text
return
log
}
def
clean_images
(
imageTag
)
{
sh
"docker rmi -f \$(docker images -q ${imageTag})"
}
@NonCPS
def
jsonParse
(
def
json
)
{
new
groovy
.
json
.
JsonSlurperClassic
().
parseText
(
json
)
}
\ No newline at end of file
src/org/qg/tools/Utils.groovy
0 → 100644
View file @
119162e6
// src/org/qg/docker/Utils.groovy
package
org.qg.tools
;
def
contextDir
(
workspace
)
{
uuid
=
UUID
.
randomUUID
().
toString
()
contextDir
=
"tmp-context"
return
contextDir
}
def
beautyEcho
(
content
,
type
)
{
red
=
"31"
green
=
"32"
blue
=
"34"
purple
=
"35"
darkgreen
=
"36"
result
=
""
switch
(
type
)
{
case
"info"
:
content
=
" ➢➢➢➢➢ ${content}"
result
=
"\033[${blue}m${content}\033[0m"
break
case
"success"
:
content
=
" ✔✔✔✔✔ ${content}"
result
=
"\033[${green}m${content}\033[0m"
break
case
"fail"
:
content
=
" ✘✘✘✘✘ ${content}"
result
=
"\033[${red}m${content}\033[0m"
break
case
"stage"
:
content
=
" ✩✩✩✩✩✩✩✩✩✩✩✩✩✩✩✩✩✩✩✩ ${content} ✩✩✩✩✩✩✩✩✩✩✩✩✩✩✩✩✩✩✩✩"
result
=
"\033[${purple}m${content}\033[0m"
break
default:
result
=
content
break
}
echo
result
}
def
copyDockerFiles
()
{
}
def
copyConfigFiles
()
{
}
return
this
;
\ No newline at end of file
vars/qgToolsPipeline.groovy
0 → 100644
View file @
119162e6
import
org.qg.tools.*
def
call
(
body
)
{
def
config
=
[:]
def
env
=
body
.
env
def
workspace
=
"/home/quant_group/jenkins_home/workspace/${env.JOB_NAME}"
def
imageTag
def
_stage
=
new
org
.
qg
.
docker
.
StageBucket
()
def
_utils
=
new
org
.
qg
.
docker
.
Utils
()
body
.
resolveStrategy
=
Closure
.
DELEGATE_FIRST
body
.
delegate
=
config
body
()
def
systemName
=
config
.
systemName
def
branchName
=
"master"
def
harborGroup
=
"tools"
def
buildNumber
=
env
.
BUILD_NUMBER
node
{
try
{
ansiColor
(
'xterm'
)
{
dir
(
systemName
)
{
timestamps
{
stage
(
'Init'
)
{
_utils
.
beautyEcho
(
"Init"
,
"stage"
)
}
stage
(
'Checkout'
)
{
_utils
.
beautyEcho
(
"Checkout"
,
"stage"
)
switch
(
systemName
)
{
case
"eos"
:
_stage
.
checkout_eos
()
break
default:
echo
"Stage_Checkout: 未知的系统: ${systemName}"
break
}
}
stage
(
'Prepare'
)
{
_utils
.
beautyEcho
(
"Prepare"
,
"stage"
)
_stage
.
before_prepare
(
contextDir
)
switch
(
systemName
)
{
case
"eos"
:
_stage
.
prepare_eos
(
contextDir
)
break
default:
echo
"Stage_Prepare: 未知的系统: ${systemName}"
break
}
}
stage
(
'Build'
)
{
_utils
.
beautyEcho
(
"Build"
,
"stage"
)
switch
(
config
.
buildType
)
{
case
"eos"
:
_stage
.
build_eos
(
contextDir
)
break
default:
echo
"Stage_Build: 未知的系统: ${systemName}"
break
}
}
stage
(
'Docker Build And Push'
)
{
_utils
.
beautyEcho
(
"Docker Build And Push"
,
"stage"
)
if
(
config
.
buildType
==
"java"
)
{
_stage
.
copy_files_java
(
systemName
)
}
imageTag
=
_stage
.
dockerbuild_and_push
(
buildNumber
,
branchName
,
harborGroup
,
systemName
,
contextDir
)
}
stage
(
'Deploy To K8s Cluster'
)
{
_utils
.
beautyEcho
(
"Deploy To K8s Cluster"
,
"stage"
)
def
deploy_log
=
_stage
.
deploy
(
namespace
,
systemName
,
imageTag
,
config
.
tier
,
isDeploy
)
_utils
.
beautyEcho
(
deploy_log
,
"info"
)
}
stage
(
"Clean"
)
{
_utils
.
beautyEcho
(
"Clean"
,
"stage"
)
_stage
.
clean_images
(
imageTag
)
}
}
}
}
}
catch
(
err
)
{
ansiColor
(
'xterm'
)
{
if
(
imageTag
)
{
_stage
.
clean_images
(
imageTag
)
}
currentBuild
.
result
=
'FAILED'
_utils
.
beautyEcho
(
err
,
"fail"
)
throw
err
}
}
}
}
\ No newline at end of file
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