@@ -63,20 +63,10 @@ def setupNodeAndTest(version, testSuite='test') {
6363 }
6464}
6565
66- String getVersionFromPackageJson () {
67- packageInfo = readJSON file : ' package.json'
68- return packageInfo. version
69- }
70-
71- String version = null ;
72- boolean isReleaseVersion = false ;
73-
7466stage(' Build' ) {
7567 // Checkout, build
7668 node {
7769 checkout scm
78- version = getVersionFromPackageJson();
79- isReleaseVersion = ! version. toUpperCase(Locale . ENGLISH ). contains(' SNAPSHOT' )
8070 sh ' npm install'
8171 stash name : ' built'
8272 }
@@ -98,9 +88,13 @@ stage('QA: Node') {
9888stage(' Publish' ) {
9989 if (env. BRANCH_NAME == " master" ) {
10090 node {
101- checkout scm // re-checkout to be able to git tag
91+ unstash ' built'
92+
93+ def v = com.ibm.cloudant.integrations.VersionHelper . readVersion(this , ' package.json' )
94+ String version = v. version
95+ boolean isReleaseVersion = v. isReleaseVersion
10296
103- // Upload using the ossrh creds (upload destination logic is in build.gradle)
97+ // Upload using the NPM creds
10498 withCredentials([string(credentialsId : ' npm-mail' , variable : ' NPM_EMAIL' ),
10599 usernamePassword(credentialsId : ' npm-creds' , passwordVariable : ' NPM_PASS' , usernameVariable : ' NPM_USER' )]) {
106100 // Actions:
@@ -115,37 +109,12 @@ stage('Publish') {
115109 npm publish ${ isReleaseVersion ? '' : '--tag snapshot'}
116110 """
117111 }
118-
119- // if it is a release build then do the git tagging
120- if (isReleaseVersion) {
121-
122- // Read the CHANGES.md to get the tag message
123- tagMessage = ' '
124- for (line in readFile(' CHANGES.md' ). readLines()) {
125- if (! ' ' . equals(line)) {
126- // append the line to the tagMessage
127- tagMessage = " ${ tagMessage}${ line} \n "
128- } else {
129- break
130- }
131- }
132-
133- // Use git to tag the release at the version
134- try {
135- // Awkward workaround until resolution of https://issues.jenkins-ci.org/browse/JENKINS-28335
136- withCredentials([[$class : ' UsernamePasswordMultiBinding' , credentialsId : ' github-token' , usernameVariable : ' GIT_USERNAME' , passwordVariable : ' GIT_PASSWORD' ]]) {
137- sh
" git config user.email \" [email protected] \" " 138- sh " git config user.name \" Jenkins CI\" "
139- sh " git config credential.username ${ env.GIT_USERNAME} "
140- sh " git config credential.helper '!echo password=\$ GIT_PASSWORD; echo'"
141- sh " git tag -a ${ version} -m '${ tagMessage} '"
142- sh " git push origin ${ version} "
143- }
144- } finally {
145- sh " git config --unset credential.username"
146- sh " git config --unset credential.helper"
147- }
148- }
149112 }
150113 }
114+
115+ // Run the gitTagAndPublish which tags/publishes to github for release builds
116+ gitTagAndPublish {
117+ versionFile= ' package.json'
118+ releaseApiUrl= ' https://api.github.com/repos/cloudant/nodejs-cloudant/releases'
119+ }
151120}
0 commit comments