Skip to content

Commit c5edf89

Browse files
matthewpwilsonpcoop
authored andcommitted
Deploy with Jenkins (#22)
* First attempt at deploying to Artifactory * Fix syntx error & add creditials ID * Allow groovy variable for TEST_NPM_REGISTRY to resolve * Add smoke test * Fiddle with .npmrc * Do auth in smoke test too * tweak registry * debug for npm auth failure * More debug * Yet more debugging * Still trying to npminstall * More npm install debug * Auth for brightside scope * Another go at registry config * Give up on smoke test * Explicitly set default registry * Reset master branch * Remove logout step as no longer needed
1 parent 4e9d4bd commit c5edf89

File tree

2 files changed

+75
-116
lines changed

2 files changed

+75
-116
lines changed

.npmrc

Lines changed: 0 additions & 4 deletions
This file was deleted.

Jenkinsfile

Lines changed: 75 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* SPDX-License-Identifier: EPL-2.0 *
77
* *
88
* Copyright Contributors to the Zowe Project. *
9+
* Copyright IBM Corp, 2019.
910
* *
1011
*/
1112

@@ -23,11 +24,9 @@ def RELEASE_BRANCHES = ["master"]
2324
*/
2425
def PIPELINE_CONTROL = [
2526
build: true,
26-
unit_test: true,
27+
unit_test: true,
2728
system_test: true,
28-
deploy: false,
29-
smoke_test: false,
30-
create_bundle: false,
29+
deploy: true,
3130
ci_skip: false ]
3231

3332
/**
@@ -42,7 +41,7 @@ def BUILD_RESULT = [
4241
/**
4342
* Test npm registry using for smoke test
4443
*/
45-
def TEST_NPM_REGISTRY = "...."
44+
def TEST_NPM_REGISTRY = "https://eu.artifactory.swg-devops.com/artifactory/api/npm/cicsts-npm-virtual"
4645

4746
/**
4847
* The root results folder for items configurable by environmental variables
@@ -81,6 +80,8 @@ def PRODUCT_NAME = "zowe-cli-cics-deploy-plugin"
8180
*/
8281
def ZOWE_CLI_INSTALL_DIR = "/.npm-global/lib/node_modules/@brightside/core"
8382

83+
def ARTIFACTORY_CREDENTIALS_ID = "c8e3aa62-5eef-4e6b-8a3f-aa1006a7ef01"
84+
8485
// Setup conditional build options. Would have done this in the options of the declarative pipeline, but it is pretty
8586
// much impossible to have conditional options based on the branch :/
8687
def opts = []
@@ -198,6 +199,7 @@ pipeline {
198199
steps('Install Zowe CLI') {
199200
timeout(time: 10, unit: 'MINUTES') {
200201
echo "Install Zowe CLI globaly"
202+
sh("npm set registry https://registry.npmjs.org")
201203
sh("npm set @brightside:registry https://api.bintray.com/npm/ca/brightside/")
202204
sh("npm install -g @brightside/core@next")
203205
sh("zowe --version")
@@ -503,49 +505,35 @@ pipeline {
503505
* DESCRIPTION
504506
* -----------
505507
* Bumps the pre-release version in preparation for publishing to an npm
506-
* registry. It will clean out any pending changes and switch to the real
507-
* branch that was published (currently the pipeline would be in a
508-
* detached HEAD at the commit) before executing the npm command to bump
509-
* the version.
510-
*
511-
* The step does checking against the commit that was checked out and
512-
* the BUILD_REVISION that was retrieved earlier. If they do not match,
513-
* the commit will not be pushed and the build will fail. This handles
514-
* the condition where the current build made it to this step but another
515-
* change had been pushed to the master branch. This means that we would
516-
* have to bump the version of a future commit to the one we just built
517-
* and tested, which is a big no no. A corresponding email will be sent
518-
* out in this situation to explain how this condition could have occurred.
519-
*
520-
* OUTPUTS
521-
* -------
522-
* GitHub: A commit containing the bumped version in the package.json.
523-
*
524-
* Commit Message:
525-
* Bumped pre-release version <VERSION_HERE> [ci skip]
508+
* registry.
526509
************************************************************************/
527-
// stage('Bump Version') {
528-
// when {
529-
// allOf {
530-
// expression {
531-
// return PIPELINE_CONTROL.ci_skip == false
532-
// }
533-
// expression {
534-
// return PIPELINE_CONTROL.deploy
535-
// }
536-
// expression {
537-
// return currentBuild.resultIsBetterOrEqualTo(BUILD_RESULT.success)
538-
// }
539-
// }
540-
// }
541-
// steps {
542-
// timeout(time: 5, unit: 'MINUTES') {
543-
// echo "Bumping Version"
544-
545-
// echo 'Perform version bump for the branch'
546-
// }
547-
// }
548-
// }
510+
stage('Bump Version') {
511+
when {
512+
allOf {
513+
expression {
514+
return PIPELINE_CONTROL.ci_skip == false
515+
}
516+
expression {
517+
return PIPELINE_CONTROL.deploy
518+
}
519+
expression {
520+
return BRANCH_NAME == MASTER_BRANCH
521+
}
522+
}
523+
}
524+
steps {
525+
timeout(time: 5, unit: 'MINUTES') {
526+
echo "Bumping Version"
527+
528+
// This npm command does the version bump
529+
script {
530+
def baseVersion = sh returnStdout: true, script: 'node -e "console.log(require(\'./package.json\').version.split(\'-\')[0])"'
531+
def preReleaseVersion = baseVersion.trim() + "-next." + new Date().format("yyyyMMddHHmm", TimeZone.getTimeZone("UTC"))
532+
sh "npm version ${preReleaseVersion} --no-git-tag-version"
533+
}
534+
}
535+
}
536+
}
549537
/************************************************************************
550538
* STAGE
551539
* -----
@@ -570,70 +558,45 @@ pipeline {
570558
* -------
571559
* npm: A package to an npm registry
572560
************************************************************************/
573-
// stage('Deploy') {
574-
// when {
575-
// allOf {
576-
// expression {
577-
// return PIPELINE_CONTROL.ci_skip == false
578-
// }
579-
// expression {
580-
// return PIPELINE_CONTROL.deploy
581-
// }
582-
// expression {
583-
// return currentBuild.resultIsBetterOrEqualTo(BUILD_RESULT.success)
584-
// }
585-
// }
586-
// }
587-
// steps {
588-
// timeout(time: 5, unit: 'MINUTES') {
589-
// echo 'Deploy Binary'
590-
591-
// echo 'Perform binary deployment'
592-
// }
593-
// }
594-
// }
595-
/************************************************************************
596-
* STAGE
597-
* -----
598-
* Smoke Test
599-
*
600-
* TIMEOUT
601-
* -------
602-
* 5 Minutes
603-
*
604-
* EXECUTION CONDITIONS
605-
* --------------------
606-
* - PIPELINE_CONTROL.ci_skip is false
607-
* - PIPELINE_CONTROL.smoke_test is true
608-
* - The build is still successful and not unstable
609-
*
610-
* DESCRIPTION
611-
* -----------
612-
* Install the new pulished plugin and run some simple command to validate
613-
*
614-
************************************************************************/
615-
// stage('Smoke Test') {
616-
// when {
617-
// allOf {
618-
// expression {
619-
// return PIPELINE_CONTROL.ci_skip == false
620-
// }
621-
// expression {
622-
// return PIPELINE_CONTROL.smoke_test
623-
// }
624-
// expression {
625-
// return currentBuild.resultIsBetterOrEqualTo(BUILD_RESULT.success)
626-
// }
627-
// }
628-
// }
629-
// steps {
630-
// timeout(time: 5, unit: 'MINUTES') {
631-
// echo "Smoke Test"
632-
633-
// echo 'Perform smoke test here'
634-
// echo 'Record test reports artifacts'
635-
// }
636-
// }
637-
// }
561+
stage('Deploy') {
562+
when {
563+
allOf {
564+
expression {
565+
return PIPELINE_CONTROL.ci_skip == false
566+
}
567+
expression {
568+
return PIPELINE_CONTROL.deploy
569+
}
570+
expression {
571+
return BRANCH_NAME == MASTER_BRANCH
572+
}
573+
}
574+
}
575+
steps {
576+
timeout(time: 5, unit: 'MINUTES') {
577+
echo 'Deploy Binary'
578+
withCredentials([usernamePassword(credentialsId: ARTIFACTORY_CREDENTIALS_ID, usernameVariable: 'USERNAME', passwordVariable: 'API_KEY')]) {
579+
580+
// Set up authentication to Artifactory
581+
sh "rm -f .npmrc"
582+
sh 'curl -u $USERNAME:$API_KEY https://eu.artifactory.swg-devops.com/artifactory/api/npm/auth/ >> .npmrc'
583+
sh "echo registry=$TEST_NPM_REGISTRY >> .npmrc"
584+
sh "echo @brightside:registry=https://api.bintray.com/npm/ca/brightside/ >> .npmrc"
585+
sh "echo @brightside:always-auth=false >> .npmrc"
586+
587+
script {
588+
if (BRANCH_NAME == MASTER_BRANCH) {
589+
echo "publishing next to $TEST_NPM_REGISTRY"
590+
sh "npm publish --tag next"
591+
}
592+
else {
593+
echo "publishing latest to $TEST_NPM_REGISTRY"
594+
sh "npm publish --tag latest"
595+
}
596+
}
597+
}
598+
}
599+
}
600+
}
638601
}
639602
}

0 commit comments

Comments
 (0)