-
Notifications
You must be signed in to change notification settings - Fork 7
/
Jenkinsfile
162 lines (138 loc) · 3.92 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
pipeline {
agent {
kubernetes {
inheritFrom "build-go build-docker"
}
}
stages {
stage('Prepare') {
environment {
GOPROXY = "https://goproxy.cn,direct"
}
steps {
container('golang') {
sh "sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories"
sh "apk --no-cache add make"
}
container('docker') {
sh "sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories"
sh "apk --no-cache add make"
}
container('golang') {
sh "make dep-backend"
}
}
}
stage('UnitTest') {
parallel {
stage("Backend UnitTest") {
steps {
container('golang') {
sh "make test-backend"
}
}
}
}
}
stage('Build Backend') {
steps {
container('golang') {
sh "make build-backend"
}
}
}
stage('Build Image') {
parallel {
stage('build qucheng') {
steps {
container('docker') {
sh "make build-qucheng"
}
}
}
stage('build api') {
when {
anyOf {
tag ''
branch 'test'
}
}
steps {
container('docker') {
sh "make build-api"
}
}
}
}
} // end Build Image
stage("Publish Image") {
parallel {
stage('qucheng image') {
steps {
container('docker') {
withDockerRegistry(credentialsId: 'hub-qucheng-push', url: 'https://hub.qucheng.com') {
sh "make push-qucheng"
}
}
}
}
stage('cne-api image') {
when {
anyOf {
tag ''
branch 'test'
}
}
steps {
container('docker') {
withDockerRegistry(credentialsId: 'hub-qucheng-push', url: 'https://hub.qucheng.com') {
sh "make push-api"
}
}
}
}
} // end parallel
} // end Publish Image
stage("Deploy") {
when {
branch 'test'
}
environment {
CNE_API_TOKEN = credentials('dev-haogs-cn-token')
CNE_API_HOST = "https://console.dev.haogs.cn"
}
stages {
stage("Deploy Qucheng") {
steps {
script{
def body = ["namespace": "cne-system", "name": "qucheng", "channel": "test", "chart": "qucheng"]
def response = httpRequest \
httpMode: 'POST' ,
ignoreSslErrors: true,
contentType: 'APPLICATION_JSON',
requestBody: groovy.json.JsonOutput.toJson(body),
customHeaders: [[name: 'X-Auth-Token', value: env.CNE_API_TOKEN]],
url: env.CNE_API_HOST + "/api/cne/app/restart"
println("Content: "+response.content)
}
}
}
stage("Deploy Cne-api") {
steps {
script{
def body = ["namespace": "cne-system", "name": "cne-api", "channel": "test", "chart": "cne-api"]
def response = httpRequest \
httpMode: 'POST' ,
ignoreSslErrors: true,
contentType: 'APPLICATION_JSON',
requestBody: groovy.json.JsonOutput.toJson(body),
customHeaders: [[name: 'X-Auth-Token', value: env.CNE_API_TOKEN]],
url: env.CNE_API_HOST + "/api/cne/app/restart"
println("Content: "+response.content)
}
}
}
}
} // end Deploy
}
}