Jenkinsfile
4.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!groovy
pipeline {
agent { label 'master' }
parameters {
string(name:'projectName', defaultValue: 'yohoblk-wap', description: 'GITLAB应用名称')
string(name:'projectGitGroup', defaultValue: 'fe', description: 'GITLAB所在的组')
string(name:'projectBranch', defaultValue: 'feature/docker', description: 'git分支名称')
string(name:'deployName', defaultValue: 'node-yohoblk-wap', description: '应用名称')
string(name:'imageSource', defaultValue: 'yoho-online', description: '镜像存储的仓库')
string(name:'imageVersion', defaultValue: '20180714999', description: '镜像存储的版本')
string(name:'isNeedCdn',defaultValue:'NO', description: '是否需要上传CDN')
}
//常量参数,初始确定后一般不需更改
environment{
CRED_ID='2cb1761b-b258-4e3b-843f-8f0dab16d770'
QA_EMAIL='jimi.ji@yoho.cn'
}
options {
//保持构建的最大个数
buildDiscarder(logRotator(numToKeepStr: '50'))
}
stages {
stage('Define para && clean workdir'){
steps{
script {
def workdir="${env.WORKSPACE}/$params.projectName"
echo "print the para projectName is : ${params.projectName}......"
echo "print the para workdir is : ${workdir}......"
echo "print the para projectGitGroup is : ${params.projectGitGroup}......"
echo "print the para deployName is : ${params.deployName}......"
echo "print the para branch is : ${params.projectBranch}......"
echo "print the para isNeedCdn is : ${params.isNeedCdn}......"
echo "print the para imageSource is : ${params.imageSource}......"
echo "print the para imageVersion is : ${params.imageVersion}......"
def localdir = "${workdir}/docker.sh"
def qcloudimage = "ccr.ccs.tencentyun.com/${params.imageSource}/${params.deployName}:${params.imageVersion}"
def awsimage = "860721417875.dkr.ecr.cn-north-1.amazonaws.com.cn/${params.imageSource}/${params.deployName}:${params.imageVersion}"
if(fileExists("$localdir")){
echo "starting delete the dir ${workdir}"
sh "rm -rf ${workdir}"
}
}
}
}
stage('git clone project'){
steps{
script {
sh "git clone -b ${params.projectBranch} git@git.yoho.cn:${params.projectGitGroup}/${params.projectName}.git ${workdir}"
}
}
}
stage('build project'){
steps{
script {
sh "cd ${workdir} && sh ${workdir}/docker.sh ${params.isNeedCdn} ${workdir}"
}
}
}
stage('upload to CDN and nfs'){
steps{
script {
if(params.isNeedCdn=='YES'){
def olddir = "/data/var-lib/jenkins/workspace/replace"
def repalceDir = "${workdir}/public/dist"
println repalceDir
sh "sed -i 's?${olddir}?${repalceDir}?g' ${env.WORKSPACE}/Docker-Node-Build/LocalUploadConfig"
// sh "/home/soft/qshell qupload 3 ${env.WORKSPACE}/Docker-Node-Build/LocalUploadConfig"
// sh "cp -r ${repalceDir} /nfs-ops/Data/app/node-ci/data"
}else {
println "params.isNeedCdn is not yes,no upload"
}
}
}
}
stage('build and push images to qcloud') {
steps {
script {
echo "begin bake image......"
sh "docker build -t ${qcloudimage} ${workdir}"
sh "docker push ${qcloudimage}"
echo "end bake qcloud image......"
}
}
}
stage('build and push images to aws') {
steps {
script {
if(check_push_aws_images(params.projectName)){
sh "docker tag ${qcloudimage} ${awsimage} "
sh "docker push ${awsimage}"
echo "upload images to aws : ${params.projectName}"
}else {
println "there is no need to upload images to aws : ${params.projectName}"
}
}
}
}
}
post {
always {
echo "clean up our workspace"
/* deleteDir() clean up our workspace */
}
}
}
def check_push_aws_images(project_name){
println "begin check push aws images";
def lst = [];
lst.add("yohobuywap-node");
lst.add("yohobuy-node");
return lst.contains(project_name);
}