@@ -21,8 +21,8 @@ def PIPELINE_CONTROL = [
21
21
build : true ,
22
22
unit_test : true ,
23
23
system_test : true ,
24
- deploy : true ,
25
- ci_skip : false ]
24
+ cd_skip : false
25
+ ]
26
26
27
27
/**
28
28
* The result strings for a build status
@@ -34,10 +34,16 @@ def BUILD_RESULT = [
34
34
]
35
35
36
36
/**
37
- * Test npm registry using for smoke test
37
+ * Test npm registry
38
38
*/
39
39
def TEST_NPM_REGISTRY = " https://eu.artifactory.swg-devops.com/artifactory/api/npm/cicsts-npm-virtual"
40
40
41
+ /**
42
+ * npm registry
43
+ */
44
+ def NPM_REGISTRY = " registry.npmjs.org"
45
+ def NPM_FULL_REGISTRY = " https://registry.npmjs.org"
46
+
41
47
/**
42
48
* The root results folder for items configurable by environmental variables
43
49
*/
@@ -137,6 +143,11 @@ pipeline {
137
143
// other Jenkins jobs or needing root access.
138
144
NPM_CONFIG_PREFIX = " ${ WORKSPACE} /npm-global"
139
145
PATH = " ${ NPM_CONFIG_PREFIX} /bin:${ PATH} "
146
+
147
+ // Credential to publish to npmjs.org
148
+ // NPM_CREDENTIALS_USR is email address
149
+ // NPM_REDENTIALS_PSW is the login token
150
+ NPM_CREDENTIALS = credentials(' ibmcics.npmjs.auth.token' )
140
151
}
141
152
142
153
stages {
@@ -154,45 +165,6 @@ pipeline {
154
165
}
155
166
}
156
167
157
- /* ***********************************************************************
158
- * STAGE
159
- * -----
160
- * Check for CI Skip
161
- *
162
- * TIMEOUT
163
- * -------
164
- * 2 Minutes
165
- *
166
- * EXECUTION CONDITIONS
167
- * --------------------
168
- * - Always
169
- *
170
- * DECRIPTION
171
- * ----------
172
- * Checks for the [ci skip] text in the last commit. If it is present,
173
- * the build is stopped. Needed because the pipeline does do some simple
174
- * git commits on the master branch for the purposes of version bumping.
175
- *
176
- * OUTPUTS
177
- * -------
178
- * PIPELINE_CONTROL.ci_skip will be set to 'true' if [ci skip] is found in the
179
- * commit text.
180
- ************************************************************************/
181
- stage(' Check for CI Skip' ) {
182
- steps {
183
- timeout(time : 2 , unit : ' MINUTES' ) {
184
- script {
185
- // This checks for the [ci skip] text. If found, the status code is 0
186
- def result = sh returnStatus : true , script : ' git log -1 | grep \' .*\\ [ci skip\\ ].*\' '
187
- if (result == 0 ) {
188
- echo ' "ci skip" spotted in the git commit. Aborting.'
189
- PIPELINE_CONTROL . ci_skip = true
190
- }
191
- }
192
- }
193
- }
194
- }
195
-
196
168
/* ***********************************************************************
197
169
* STAGE
198
170
* -----
@@ -204,7 +176,6 @@ pipeline {
204
176
*
205
177
* EXECUTION CONDITIONS
206
178
* --------------------
207
- * - PIPELINE_CONTROL.ci_skip is false
208
179
* - PIPELINE_CONTROL.build is true or PIPELINE_CONTROL.smoke_test is true
209
180
*
210
181
* DESCRIPTION
@@ -219,9 +190,6 @@ pipeline {
219
190
stage(' Install Zowe CLI' ) {
220
191
when {
221
192
allOf {
222
- expression {
223
- return PIPELINE_CONTROL . ci_skip == false
224
- }
225
193
expression {
226
194
return PIPELINE_CONTROL . build || PIPELINE_CONTROL . smoke_test
227
195
}
@@ -251,7 +219,6 @@ pipeline {
251
219
*
252
220
* EXECUTION CONDITIONS
253
221
* --------------------
254
- * - PIPELINE_CONTROL.ci_skip is false
255
222
* - PIPELINE_CONTROL.build is true
256
223
*
257
224
* DESCRIPTION
@@ -265,9 +232,6 @@ pipeline {
265
232
stage(' Install Dependencies' ) {
266
233
when {
267
234
allOf {
268
- expression {
269
- return PIPELINE_CONTROL . ci_skip == false
270
- }
271
235
expression {
272
236
return PIPELINE_CONTROL . build
273
237
}
@@ -293,7 +257,6 @@ pipeline {
293
257
*
294
258
* EXECUTION CONDITIONS
295
259
* --------------------
296
- * - PIPELINE_CONTROL.ci_skip is false
297
260
* - PIPELINE_CONTROL.build is true
298
261
*
299
262
* DESCRIPTION
@@ -307,9 +270,6 @@ pipeline {
307
270
stage(' Build' ) {
308
271
when {
309
272
allOf {
310
- expression {
311
- return PIPELINE_CONTROL . ci_skip == false
312
- }
313
273
expression {
314
274
return PIPELINE_CONTROL . build
315
275
}
@@ -339,7 +299,6 @@ pipeline {
339
299
*
340
300
* EXECUTION CONDITIONS
341
301
* --------------------
342
- * - PIPELINE_CONTROL.ci_skip is false
343
302
* - PIPELINE_CONTROL.unit_test is true
344
303
*
345
304
* ENVIRONMENT VARIABLES
@@ -379,9 +338,6 @@ pipeline {
379
338
stage(' Test: Unit' ) {
380
339
when {
381
340
allOf {
382
- expression {
383
- return PIPELINE_CONTROL . ci_skip == false
384
- }
385
341
expression {
386
342
return PIPELINE_CONTROL . unit_test
387
343
}
@@ -443,7 +399,6 @@ pipeline {
443
399
*
444
400
* EXECUTION CONDITIONS
445
401
* --------------------
446
- * - PIPELINE_CONTROL.ci_skip is false
447
402
* - PIPELINE_CONTROL.system_test is true
448
403
*
449
404
* ENVIRONMENT VARIABLES
@@ -486,9 +441,6 @@ pipeline {
486
441
stage(' Test: System' ) {
487
442
when {
488
443
allOf {
489
- expression {
490
- return PIPELINE_CONTROL . ci_skip == false
491
- }
492
444
expression {
493
445
return PIPELINE_CONTROL . system_test
494
446
}
@@ -523,53 +475,71 @@ pipeline {
523
475
/* ***********************************************************************
524
476
* STAGE
525
477
* -----
526
- * Bump Version
478
+ * Check for CD Skip
527
479
*
528
480
* TIMEOUT
529
481
* -------
530
- * 5 Minutes
482
+ * 2 Minutes
531
483
*
532
484
* EXECUTION CONDITIONS
533
485
* --------------------
534
- * - PIPELINE_CONTROL.ci_skip is false
535
- * - PIPELINE_CONTROL.deploy is true
536
- * - The build is still successful and not unstable
486
+ * - Always
537
487
*
538
- * DESCRIPTION
539
- * -----------
540
- * Bumps the pre-release version in preparation for publishing to an npm
541
- * registry.
488
+ * DECRIPTION
489
+ * ----------
490
+ * Compare the version in package.json with released version. If the same,
491
+ * the build is stopped. Needed because the pipeline does do some simple
492
+ * merge on the master branch for documentation updates
493
+ *
494
+ * OUTPUTS
495
+ * -------
496
+ * PIPELINE_CONTROL.cd_skip will be set to 'true',
497
+ * - if master branch's release version and new version are the same
498
+ * - if there isn't any new commit
542
499
************************************************************************/
543
- stage(' Bump Version ' ) {
500
+ stage(' Check for CD Skip ' ) {
544
501
when {
545
502
allOf {
546
503
expression {
547
- return PIPELINE_CONTROL . ci_skip == false
548
- }
549
- expression {
550
- return PIPELINE_CONTROL . deploy
504
+ return PIPELINE_CONTROL . cd_skip == false
551
505
}
552
506
expression {
553
507
return RELEASE_BRANCHES . contains(BRANCH_NAME )
554
508
}
555
- expression {
556
- return GIT_COMMIT != GIT_PREVIOUS_SUCCESSFUL_COMMIT
557
- }
558
509
}
559
510
}
560
511
steps {
561
- timeout(time : 5 , unit : ' MINUTES' ) {
562
- echo " Bumping Version"
563
-
564
- // This npm command does the version bump
512
+ timeout(time : 2 , unit : ' MINUTES' ) {
565
513
script {
566
- def baseVersion = sh returnStdout : true , script : ' node -e "console.log(require(\' ./package.json\' ).version.split(\' -\' )[0])"'
567
- def preReleaseVersion = baseVersion. trim() + " -next." + new Date (). format(" yyyyMMddHHmm" , TimeZone . getTimeZone(" UTC" ))
568
- sh " npm version ${ preReleaseVersion} --no-git-tag-version"
514
+ // Retrieve new version from package.json
515
+ def NEW_VERSION = sh (
516
+ script : ' echo "console.log(require(\' ./package.json\' ).version);" | node' ,
517
+ returnStdout : true
518
+ ). trim()
519
+ echo " NEW_VERSION: ${ NEW_VERSION} "
520
+ // Retrieve released version from npmjs.org
521
+ def RELEASED_VERSION = sh (
522
+ script : ' npm view "$(echo "console.log(require(\' ./package.json\' ).name);" | node)" version --registry ' + NPM_FULL_REGISTRY + ' || true' ,
523
+ returnStdout : true
524
+ ). trim()
525
+ echo " RELEASED_VERSION: ${ RELEASED_VERSION} "
526
+
527
+ // skip deploying, if version has not changed.
528
+ // However, we deploy dev branch even if version has not changed
529
+ // as long as there is any new commit
530
+ if (NEW_VERSION == RELEASED_VERSION && BRANCH_NAME != DEV_BRANCH ) {
531
+ echo ' New version and released version are the same. Skip deploying.'
532
+ PIPELINE_CONTROL . cd_skip = true
533
+ }
534
+ if (GIT_COMMIT == GIT_PREVIOUS_SUCCESSFUL_COMMIT ) {
535
+ echo ' There is no new commit. Skip deploying'
536
+ PIPELINE_CONTROL . cd_skip = true
537
+ }
569
538
}
570
539
}
571
540
}
572
541
}
542
+
573
543
/* ***********************************************************************
574
544
* STAGE
575
545
* -----
@@ -581,8 +551,6 @@ pipeline {
581
551
*
582
552
* EXECUTION CONDITIONS
583
553
* --------------------
584
- * - PIPELINE_CONTROL.ci_skip is false
585
- * - PIPELINE_CONTROL.deploy is true
586
554
* - The build is still successful and not unstable
587
555
*
588
556
* DESCRIPTION
@@ -598,50 +566,54 @@ pipeline {
598
566
when {
599
567
allOf {
600
568
expression {
601
- return PIPELINE_CONTROL . ci_skip == false
602
- }
603
- expression {
604
- return PIPELINE_CONTROL . deploy
569
+ return PIPELINE_CONTROL . cd_skip == false
605
570
}
606
571
expression {
607
572
return RELEASE_BRANCHES . contains(BRANCH_NAME )
608
573
}
609
- expression {
610
- return GIT_COMMIT != GIT_PREVIOUS_SUCCESSFUL_COMMIT
611
- }
612
574
}
613
575
}
614
576
steps {
615
577
timeout(time : 5 , unit : ' MINUTES' ) {
616
578
echo ' Deploy Binary'
617
- withCredentials([usernamePassword(credentialsId : ARTIFACTORY_CREDENTIALS_ID , usernameVariable : ' USERNAME' , passwordVariable : ' API_KEY' )]) {
618
-
619
- // Set up authentication to Artifactory
579
+ script {
620
580
sh " rm -f .npmrc"
621
- sh ' curl -u $USERNAME:$API_KEY https://eu.artifactory.swg-devops.com/artifactory/api/npm/auth/ >> .npmrc '
622
- sh " echo registry= $T EST_NPM_REGISTRY >> .npmrc"
581
+ // set @zowe registry
582
+ sh " echo always-auth=true >> .npmrc"
623
583
sh " echo @brightside:registry=https://api.bintray.com/npm/ca/brightside/ >> .npmrc"
624
584
sh " echo @brightside:always-auth=false >> .npmrc"
625
-
626
- script {
627
- if (BRANCH_NAME == MASTER_BRANCH ) {
628
- echo " publishing next to $TEST_NPM_REGISTRY "
629
- sh " npm publish --tag alpha"
630
- } else if (BRANCH_NAME == DEV_BRANCH ) {
631
- echo " publishing next to $TEST_NPM_REGISTRY "
632
- sh " npm publish --tag next"
633
- } else {
634
- echo " publishing latest to $TEST_NPM_REGISTRY "
635
- sh " npm publish --tag latest"
585
+ if (BRANCH_NAME == MASTER_BRANCH ) {
586
+ // Set registry
587
+ sh " echo registry=$NPM_FULL_REGISTRY >> .npmrc"
588
+ // Set credential
589
+ sh " echo //$NPM_REGISTRY /:_authToken=${ NPM_CREDENTIALS_PSW} >> .npmrc"
590
+ // deploy
591
+ echo " publishing to $NPM_FULL_REGISTRY "
592
+ sh " npm publish --tag latest"
593
+ } else if (BRANCH_NAME == DEV_BRANCH ) {
594
+ // Set version
595
+ def baseVersion = sh returnStdout : true , script : ' node -e "console.log(require(\' ./package.json\' ).version.split(\' -\' )[0])"'
596
+ def preReleaseVersion = baseVersion. trim() + " -next." + new Date (). format(" yyyyMMddHHmm" , TimeZone . getTimeZone(" UTC" ))
597
+ sh " npm version ${ preReleaseVersion} --no-git-tag-version"
598
+ // Set credential
599
+ withCredentials([usernamePassword(credentialsId : ARTIFACTORY_CREDENTIALS_ID , usernameVariable : ' USERNAME' , passwordVariable : ' API_KEY' )]) {
600
+ sh ' curl -u $USERNAME:$API_KEY https://eu.artifactory.swg-devops.com/artifactory/api/npm/auth/ >> .npmrc'
636
601
}
602
+ // Set registry
603
+ sh " echo registry=$TEST_NPM_REGISTRY >> .npmrc"
604
+ // deploy
605
+ echo " publishing to $TEST_NPM_REGISTRY "
606
+ sh " npm publish --tag alpha"
607
+ } else {
608
+ echo " Only master and dev branch is allowed to deploy the app (current branch: $BRANCH_NAME ). Skip deploying"
637
609
}
638
-
639
- sh " rm -f .npmrc"
640
610
}
641
611
}
642
612
}
643
613
}
644
614
}
615
+
616
+ // Slack notification when fails or back to normal
645
617
post {
646
618
unsuccessful {
647
619
script {
0 commit comments