@@ -21,7 +21,7 @@ def PIPELINE_CONTROL = [
21
21
build : true ,
22
22
unit_test : true ,
23
23
system_test : true ,
24
- deploy : true ,
24
+ cd_skip : false ,
25
25
ci_skip : false ]
26
26
27
27
/**
@@ -34,10 +34,15 @@ 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 = " https://registry.npmjs.org/"
45
+
41
46
/**
42
47
* The root results folder for items configurable by environmental variables
43
48
*/
@@ -137,6 +142,9 @@ pipeline {
137
142
// other Jenkins jobs or needing root access.
138
143
NPM_CONFIG_PREFIX = " ${ WORKSPACE} /npm-global"
139
144
PATH = " ${ NPM_CONFIG_PREFIX} /bin:${ PATH} "
145
+
146
+ // Credential to publish to npmjs.org
147
+ NPM_CREDENTIALS = credentials(' ibmcics.npmjs.auth.token' )
140
148
}
141
149
142
150
stages {
@@ -523,53 +531,74 @@ pipeline {
523
531
/* ***********************************************************************
524
532
* STAGE
525
533
* -----
526
- * Bump Version
534
+ * Check for CD Skip
527
535
*
528
536
* TIMEOUT
529
537
* -------
530
- * 5 Minutes
538
+ * 2 Minutes
531
539
*
532
540
* EXECUTION CONDITIONS
533
541
* --------------------
534
- * - PIPELINE_CONTROL.ci_skip is false
535
- * - PIPELINE_CONTROL.deploy is true
536
- * - The build is still successful and not unstable
542
+ * - Always
537
543
*
538
- * DESCRIPTION
539
- * -----------
540
- * Bumps the pre-release version in preparation for publishing to an npm
541
- * registry.
544
+ * DECRIPTION
545
+ * ----------
546
+ * Compare the version in package.json with released version. If the same,
547
+ * the build is stopped. Needed because the pipeline does do some simple
548
+ * merge on the master branch for documentation updates
549
+ *
550
+ * OUTPUTS
551
+ * -------
552
+ * PIPELINE_CONTROL.cd_skip will be set to 'true',
553
+ * - if master branch's release version and new version are the same
554
+ * - if there isn't any new commit
542
555
************************************************************************/
543
- stage(' Bump Version ' ) {
556
+ stage(' Check for CD Skip ' ) {
544
557
when {
545
558
allOf {
546
559
expression {
547
560
return PIPELINE_CONTROL . ci_skip == false
548
561
}
549
562
expression {
550
- return PIPELINE_CONTROL . deploy
563
+ return PIPELINE_CONTROL . cd_skip == false
551
564
}
552
565
expression {
553
566
return RELEASE_BRANCHES . contains(BRANCH_NAME )
554
567
}
555
- expression {
556
- return GIT_COMMIT != GIT_PREVIOUS_SUCCESSFUL_COMMIT
557
- }
558
568
}
559
569
}
560
570
steps {
561
- timeout(time : 5 , unit : ' MINUTES' ) {
562
- echo " Bumping Version"
563
-
564
- // This npm command does the version bump
571
+ timeout(time : 2 , unit : ' MINUTES' ) {
565
572
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"
573
+ // Retrieve new version from package.json
574
+ def NEW_VERSION = sh (
575
+ script : ' echo "console.log(require(\' ./package.json\' ).version);" | node' ,
576
+ returnStdout : true
577
+ ). trim()
578
+ echo " NEW_VERSION: ${ NEW_VERSION} "
579
+ // Retrieve released version from npmjs.org
580
+ def RELEASED_VERSION = sh (
581
+ script : ' npm view "$(echo "console.log(require(\' ./package.json\' ).name);" | node)" version || true' ,
582
+ returnStdout : true
583
+ ). trim()
584
+ echo " RELEASED_VERSION: ${ RELEASED_VERSION} "
585
+
586
+ // skip deploying, if version has not changed.
587
+ // However, we deploy dev branch even if version has not changed
588
+ // as long as there is any new commit
589
+ if (NEW_VERSION == RELEASED_VERSION && BRANCH_NAME != DEV_BRANCH ) {
590
+ echo ' New version and released version are the same. Skip deploying.'
591
+ PIPELINE_CONTROL . cd_skip = true
592
+ }
593
+ if (GIT_COMMIT == GIT_PREVIOUS_SUCCESSFUL_COMMIT ) {
594
+ echo ' There is no new commit. Skip deploying'
595
+ PIPELINE_CONTROL . cd_skip = true
596
+ }
569
597
}
570
598
}
571
599
}
572
600
}
601
+
573
602
/* ***********************************************************************
574
603
* STAGE
575
604
* -----
@@ -582,7 +611,6 @@ pipeline {
582
611
* EXECUTION CONDITIONS
583
612
* --------------------
584
613
* - PIPELINE_CONTROL.ci_skip is false
585
- * - PIPELINE_CONTROL.deploy is true
586
614
* - The build is still successful and not unstable
587
615
*
588
616
* DESCRIPTION
@@ -601,47 +629,54 @@ pipeline {
601
629
return PIPELINE_CONTROL . ci_skip == false
602
630
}
603
631
expression {
604
- return PIPELINE_CONTROL . deploy
632
+ return PIPELINE_CONTROL . cd_skip == false
605
633
}
606
634
expression {
607
635
return RELEASE_BRANCHES . contains(BRANCH_NAME )
608
636
}
609
- expression {
610
- return GIT_COMMIT != GIT_PREVIOUS_SUCCESSFUL_COMMIT
611
- }
612
637
}
613
638
}
614
639
steps {
615
640
timeout(time : 5 , unit : ' MINUTES' ) {
616
641
echo ' Deploy Binary'
617
- withCredentials([usernamePassword(credentialsId : ARTIFACTORY_CREDENTIALS_ID , usernameVariable : ' USERNAME' , passwordVariable : ' API_KEY' )]) {
618
-
619
- // Set up authentication to Artifactory
642
+ script {
620
643
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"
644
+ // set @zowe registry
645
+ sh " echo always-auth=true >> .npmrc"
623
646
sh " echo @brightside:registry=https://api.bintray.com/npm/ca/brightside/ >> .npmrc"
624
647
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"
648
+ if (BRANCH_NAME == MASTER_BRANCH ) {
649
+ // Set credential
650
+ sh " echo _auth=${ NPM_CREDENTIALS} >> .npmrc"
651
+ // Set registry
652
+ sh " echo registry=$NPM_REGISTRY >> .npmrc"
653
+ // deploy
654
+ echo " publishing to $NPM_REGISTRY "
655
+ sh " npm publish --tag latest"
656
+ } else if (BRANCH_NAME == DEV_BRANCH ) {
657
+ // Set version
658
+ def baseVersion = sh returnStdout : true , script : ' node -e "console.log(require(\' ./package.json\' ).version.split(\' -\' )[0])"'
659
+ def preReleaseVersion = baseVersion. trim() + " -next." + new Date (). format(" yyyyMMddHHmm" , TimeZone . getTimeZone(" UTC" ))
660
+ sh " npm version ${ preReleaseVersion} --no-git-tag-version"
661
+ // Set credential
662
+ withCredentials([usernamePassword(credentialsId : ARTIFACTORY_CREDENTIALS_ID , usernameVariable : ' USERNAME' , passwordVariable : ' API_KEY' )]) {
663
+ sh ' curl -u $USERNAME:$API_KEY https://eu.artifactory.swg-devops.com/artifactory/api/npm/auth/ >> .npmrc'
636
664
}
665
+ // Set registry
666
+ sh " echo registry=$TEST_NPM_REGISTRY >> .npmrc"
667
+ // deploy
668
+ echo " publishing to $TEST_NPM_REGISTRY "
669
+ sh " npm publish --tag alpha"
670
+ } else {
671
+ echo " Only master and dev branch is allowed to deploy the app (current branch: $BRANCH_NAME ). Skip deploying"
637
672
}
638
-
639
- sh " rm -f .npmrc"
640
673
}
641
674
}
642
675
}
643
676
}
644
677
}
678
+
679
+ // Slack notification when fails or back to normal
645
680
post {
646
681
unsuccessful {
647
682
script {
0 commit comments