Jenkinsfile
3.29 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
#!groovy
pipeline {
agent { label 'master' }
parameters {
string(name:'callBack', defaultValue: 'noNeedCallBack', description: '回调服务地址')
choice(name:'clusterId',choices:'aws\nyoho-web-gray\nyoho-java\nyoho-ops\nyoho-web\nyoho-media\nyoho-web-new\n', description: '集群的信息')
string(name:'serviceName', defaultValue: 'yoho-app-web', description: '服务名称 ')
string(name:'containerName', defaultValue: 'yoho-app-web', description: '容器名称')
string(name:'imageInfo', defaultValue: 'yohobuy-core/yohobuywap-node:hotfix-share-20181221134254', description: '镜像版本')
choice(name:'deployEnv',choices:'aws\nqcloud\nall\n', description: '部署的集群信息')
}
//常量参数,初始确定后一般不需更改
environment{
CRED_ID='2cb1761b-b258-4e3b-843f-8f0dab16d770'
QA_EMAIL='bule.mei@yoho.cn'
AWS_IMAGE='860721417875.dkr.ecr.cn-north-1.amazonaws.com.cn'
QCLOUD_IMAGE='ccr.ccs.tencentyun.com'
}
options {
//保持构建的最大个数
buildDiscarder(logRotator(numToKeepStr: '20'))
}
stages {
stage('Define para'){
steps{
script {
echo "print the para callBack is : ${params.callBack}......"
echo "print the para clusterId is : ${params.clusterId}......"
echo "print the para projectGitGroup is : ${params.serviceName}......"
echo "print the para deployName is : ${params.containerName}......"
echo "print the para branch is : ${params.imageInfo}......"
echo "print the para isNeedCdn is : ${params.deployEnv}......"
if(params.deployEnv=='aws'){
error 'no aws env'
}
}
}
}
stage('qcloud deploy'){
steps{
script {
println "begin qcloud deploy"
if(params.deployEnv=='qcloud' || params.deployEnv=='all'){
//切换kubectl的认证
def pyworkdir="${env.WORKSPACE}/Docker-Image-Deplopy/qcloud/qcloudDeploy.py"
sh "python -u ${pyworkdir} ${params.clusterId} ${params.serviceName} ${params.containerName} ${params.imageInfo}"
}else {
println "qcloud this no need deploy"
}
}
}
}
stage('aws deploy'){
steps{
script {
println "begin aws deploy"
if(params.deployEnv=='aws' || params.deployEnv=='all'){
//切换kubectl的认证
def shellworkdir="${env.WORKSPACE}/Docker-Image-Deplopy/aws/awsdeploy.sh"
sh "sh ${shellworkdir} ${params.serviceName} ${params.imageInfo}"
}else {
println "aws this no need deploy"
}
}
}
}
}
post {
always {
script {
echo "clean up our workspace,and send to callBack"
deleteDir() /* clean up our workspace */
if(params.callBack!='noNeedCallBack'){
sh "curl '${params.callBack}&status=${currentBuild.currentResult}&jobID=${JOB_NAME},${BUILD_NUMBER}'"
}
}
}
}
}