-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
177 lines (148 loc) · 4.02 KB
/
Jenkinsfile
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# 定义一个公共的方法
def deploy = {
sh '''
make env
path=$(pwd)
echo PROJECT_PATH="${path}" >> .env
echo LOG_PATH="${HOME}" >> .env
cat .env
hostname -I
inner_ip=$(hostname -I | awk '{print$1}')
sudo bash ./jenkins.sh $inner_ip $DOCKER_TAG $BRANCH_ENV
make "${SERVICES}-start"
make clean-docker
'''
}
pipeline {
options { skipDefaultCheckout() }
agent none
parameters {
string (name: 'HUB_DOMAIN', defaultValue: 'hub.docker.com', description: 'docker-hub仓库地址')
string (name: 'PROJECT', defaultValue: 'my-project', description: '项目')
string (name: 'DOCKER_TAG', defaultValue: 'latest', description: 'docker镜像tag,默认latest')
string (name: 'PROJECT_PATH', defaultValue: '/home/ubuntu', description: '项目位置')
string (name: 'LOG_PATH', defaultValue: '/home/ubuntu/logs', description: '日志落地位置')
choice (
name: 'BRANCH_ENV',
choices: ['.dev', '.test', '.pre', '.pro'],
description: '环境变量'
)
choice (
name: 'SERVICES',
choices: [
'all', 'access-rpc', 'access-api',
'users-rpc', 'users-api',
'admin-api', 'server-api',
'audit-api', 'task-api'
],
description: '请选择需要发布的服务'
)
}
stages {
stage('Check on Controller') {
agent { label 'HOST' }
stages {
stage('Cleaning workspace') {
steps {
sh 'ls -l'
sh 'sudo rm -rf ./*'
}
}
stage('SCE Checkout') {
steps {
checkout scm
}
}
stage('Stash artifacts') {
steps {
stash name: 'source', includes: '**', excludes: '**/.git,**/.git/**'
}
}
stage('Build Image') {
environment {
HUB_DOMAIN = "${params.HUB_DOMAIN}"
DOCKER_TAG = "${params.DOCKER_TAG}"
PROJECT = "${params.PROJECT}"
BRANCH_ENV = "${params.BRANCH_ENV}"
SERVICES = "${params.SERVICES}"
LOG_PATH = "${params.LOG_PATH}"
PROJECT_PATH = "${params.PROJECT_PATH}"
}
steps {
sh '''
make ${SERVICES}
make clean-docker
make env
'''
}
}
}
}
stage ('Deploy on Dev') {
when { branch 'dev' }
agent { label 'PROJECT-V2-TEST' }
stages {
stage('Cleaning workspace') {
steps {
sh 'ls -l'
sh 'sudo rm -rf ./*'
}
}
stage('Unstash artifacts') {
steps {
unstash 'source'
}
}
stage('Starting containers') {
steps {
script {deploy ()}
}
}
}
}
stage ('Deploy on TEST') {
when { branch 'QA.TEST' }
agent { label 'TEST-PROJECT-V2' }
stages {
stage('Cleaning workspace') {
steps {
sh 'ls -l'
sh 'sudo rm -rf ./*'
}
}
stage('Unstash artifacts') {
steps {
unstash 'source'
}
}
stage('Starting containers') {
steps {
script {deploy ()}
}
}
}
}
stage ('Deploy on RELEASE') {
when { branch 'release' }
agent { label 'PRE-RELEASE' }
stages {
stage('Cleaning workspace') {
steps {
sh 'ls -l'
sh 'sudo rm -rf ./*'
}
}
stage('Unstash artifacts') {
steps {
unstash 'source'
}
}
stage('Starting containers') {
steps {
script {deploy ()}
}
}
}
}
}
}