-
Notifications
You must be signed in to change notification settings - Fork 6
/
Jenkinsfile
275 lines (245 loc) · 7.48 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#!groovy
def artUploadServer = Artifactory.server('devcloud')
def Snapshot = 'APM-AWS'
def imageName = 'apphub-microapp-seed'
def orgName = 'predix-apphub'
/**
*
*/
pipeline {
agent none
environment {
DEBUG = ''
ORG_NAME = 'Predix-Apphub'
APP_NAME = 'apphub-microapp-seed'
}
stages {
stage('Build & Test') {
agent {
docker {
//image 'registry.gear.ge.com/dig-propel/predixci-node6.9-base'
image 'node:10'
label 'dind'
}
}
steps {
echo 'Running ${BUILD_ID} on ${JENKINS_URL}'
sh 'printenv'
echo 'Setting npm config'
sh """
node -v
npm -v
npm config set strict-ssl false
npm config ls
"""
echo 'Installing...'
sh 'npm ci'
echo 'Testing...'
sh 'npm test -- --ci'
echo 'Building...'
sh 'npm run dist; cp apphub-microapp-seed-1.0.0.zip apphub-microapp-seed-${BUILD_ID}.zip'
}
post {
success {
echo 'Build and Test stage completed'
stash includes: '*.zip', name: 'artifact'
}
failure {
echo 'Build and unit stage failed'
}
}
}
stage('Publish Artifacts') {
agent {
docker {
image 'registry.gear.ge.com/dig-propel/jfrog-cli-go'
label 'dind'
}
}
steps {
script {
echo 'Publishing Artifacts to Artifactory'
unstash 'artifact'
def uploadSpec = """{
"files": [{
"pattern": "*.zip",
"target": "${Snapshot}/build/${ORG_NAME}/${APP_NAME}/${BRANCH_NAME}/${BUILD_NUMBER}/"
}]
}"""
def buildInfo = artUploadServer.upload(uploadSpec)
artUploadServer.publishBuildInfo(buildInfo)
}
}
post {
success {
echo 'Deploy Artifact to Artifactory stage completed'
}
failure {
echo 'Deploy Artifact to Artifactory stage failed'
}
}
}
stage ('Publish docker to registry') {
agent {
label "dind"
}
when {
anyOf {
branch 'develop'
branch 'master'
}
}
environment {
DTR_CREDS = credentials('JS_DTR_CREDENTIALS')
}
steps {
script{
checkout scm
if(env.BRANCH_NAME == 'develop'){
sh 'docker login https://registry.gear.ge.com -u $DTR_CREDS_USR -p $DTR_CREDS_PSW'
sh "docker build -t registry.gear.ge.com/${orgName}/${imageName}:dev --build-arg NODE_TLS_REJECT_UNAUTHORIZED=0 ."
sh "docker push registry.gear.ge.com/${orgName}/${imageName}:dev"
}
if(env.BRANCH_NAME == 'master'){
sh 'docker login https://registry.gear.ge.com -u $DTR_CREDS_USR -p $DTR_CREDS_PSW'
sh "docker build -t registry.gear.ge.com/${orgName}/${imageName}:latest --build-arg NODE_TLS_REJECT_UNAUTHORIZED=0 ."
sh "docker push registry.gear.ge.com/${orgName}/${imageName}:latest"
}
}
}
post {
success {
echo "Build Docker Image stage completed"
}
failure {
echo "Build Docker Image stage failed"
}
}
}
stage('Deploy to CF3 Dev'){
when {
branch 'master'
}
agent {
docker {
image 'registry.gear.ge.com/spartans/spartans-cicd'
label 'dind'
}
}
environment {
DEVLOGIN = credentials('CF3Dev_Credentials')
GIT_TOKEN = credentials('GITTOKEN');
CF_ENV='dev';
CF_REGION='aws-usw02';
CF_SPACE='dev';
CF_DOMAIN="https://api.system.aws-usw02-${CF_ENV}.ice.predix.io";
CF_RUN_DOMAIN="run.${CF_REGION}-${CF_ENV}.ice.predix.io";
CF_ORG='predix-apphub';
//APP_NAME='ui-app-hub';
APP_VERSION='1.0.0';
APP_PATH="${APP_NAME}-${BUILD_NUMBER}.zip";
PUBLISHED_HOST="${APP_NAME}";
DOMAIN="run.${CF_REGION}-${CF_ENV}.ice.predix.io";
INSTANCES='2';
DISK_QUOTA='512M';
MEMORY='1G';
SERVICES='predix-logging';
BUILD_PACK='https://github.com/heroku/heroku-buildpack-nodejs';
WILD_CARD=''
TO_ENV='DEV';
}
steps {
dir('build-scripts') {
git url: "https://$GIT_TOKEN_PSW:x-oauth-basic@github.build.ge.com/predix-apphub/build-scripts.git"
}
cfDeploy("${CF_DOMAIN}","$DEVLOGIN_USR","$DEVLOGIN_PSW","${CF_ORG}","${CF_SPACE}")
}
post {
success {
echo "Deploy stage completed"
}
failure {
echo "Deploy stage failed"
}
}
}
stage('Deploy to Stage'){
when {
branch 'master'
}
agent {
docker {
image 'registry.gear.ge.com/spartans/spartans-cicd'
label 'dind'
}
}
environment {
STAGELOGIN = credentials('CF3Stage_Credentials')
GIT_TOKEN = credentials('GITTOKEN');
CF_ENV='dev';
CF_REGION='aws-usw02';
CF_SPACE='predix-apphub-stage';
CF_DOMAIN="https://api.system.aws-usw02-${CF_ENV}.ice.predix.io";
CF_RUN_DOMAIN="run.${CF_REGION}-${CF_ENV}.ice.predix.io";
CF_ORG='predix-apphub-stage';
//APP_NAME='ui-app-hub';
APP_VERSION='1.0.0';
APP_PATH="${APP_NAME}-${BUILD_NUMBER}.zip";
PUBLISHED_HOST="${APP_NAME}-stage";
DOMAIN="run.${CF_REGION}-${CF_ENV}.ice.predix.io";
INSTANCES='2';
DISK_QUOTA='512M';
MEMORY='1G';
SERVICES='';
BUILD_PACK='https://github.com/heroku/heroku-buildpack-nodejs';
WILD_CARD=''
TO_ENV='STAGE';
}
steps {
dir('build-scripts') {
git url: "https://$GIT_TOKEN_PSW:x-oauth-basic@github.build.ge.com/predix-apphub/build-scripts.git"
}
cfDeploy("${CF_DOMAIN}","$STAGELOGIN_USR","$STAGELOGIN_PSW","${CF_ORG}","${CF_SPACE}")
}
post {
success {
echo "Deploy stage completed"
}
failure {
echo "Deploy stage failed"
}
}
}
stage('Clean Up') {
agent {
label 'dind'
}
steps {
step([$class: 'WsCleanup'])
}
post {
success {
echo 'Clean up stage completed'
}
failure {
echo 'Clean up stage failed'
}
}
}
}
/**
* Steps to always run.
*/
post {
always {
echo 'Done.'
}
}
}
def cfDeploy(String domain, String user, String password, String org, String space) {
echo "Pushing to ORG: ${org} SPACE: ${space}"
unstash 'artifact'
sh "cf login -a ${domain} -u ${user} -p ${password} -o ${org} -s ${space}"
sh("chmod +x ./build-scripts/script/deploy_sequence.sh")
sh("./build-scripts/script/deploy_sequence.sh")
}