This repository has been archived by the owner on Mar 11, 2022. It is now read-only.
forked from iriscouch/follow
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Jenkinsfile
109 lines (102 loc) · 3.9 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
#!groovy
// Copyright © 2017, 2019 IBM Corp. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
def setupNodeAndTest(version, couchDbVersion='latest') {
node {
// To get the docker sidecar run to default to docker-in-docker we must
// unset the DOCKER_HOST variable.
withEnv(["DOCKER_HOST="]){
// Install CouchDB
docker.image("couchdb:${couchDbVersion}").withRun('-p 5984:5984') {
// Install NVM
sh 'wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash'
// Unstash the built content
unstash name: 'built'
// Run tests using creds
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'couchdb', usernameVariable: 'user', passwordVariable: 'pass']]) {
withEnv(["NVM_DIR=${env.HOME}/.nvm", "TAP_TIMEOUT=300", "COUCHDB_VERSION=${couchDbVersion}"]) {
// Actions:
// 1. Install NVM
// 2. Install required Node.js version
// 3. Wait for CouchDB
// 4. Put _global_changes DB for CouchDB > 1.x
// 5. Use required Node.js version
// 6. Run tests
sh """
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
nvm install ${version}
wget --retry-connrefused http://localhost:5984
"""
// Create _global_changes DB if newer CouchDB versions
if (couchDbVersion != '1') {
sh 'curl -X PUT http://localhost:5984/_global_changes'
}
// Run tests
sh """
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
nvm use ${version}
npm test && npm run unreliable-feed-test
"""
}
}
}
}
}
}
stage('Build') {
// Checkout, build
node {
checkout scm
sh 'npm install'
stash name: 'built'
}
}
stage('QA') {
def axes = [
// Using latest CouchDB @1.x:
CouchDb1Node14: { setupNodeAndTest('14', '1') },
// Using latest CouchDB @2.X:
CouchDb2Node14: { setupNodeAndTest('14', '2') }
]
parallel(axes) // Run the required axes in parallel
}
// Publish the master branch
stage('Publish') {
if (env.BRANCH_NAME == "master") {
node {
unstash 'built'
def v = com.ibm.cloudant.integrations.VersionHelper.readVersion(this, 'package.json')
String version = v.version
boolean isReleaseVersion = v.isReleaseVersion
// Upload using the NPM creds
withCredentials([string(credentialsId: 'npm-mail', variable: 'NPM_EMAIL'),
usernamePassword(credentialsId: 'npm-creds', passwordVariable: 'NPM_TOKEN', usernameVariable: 'NPM_USER')]) {
// Actions:
// 1. create .npmrc file for publishing
// 2. add the build ID to any snapshot version for uniqueness
// 3. publish the build to NPM adding a snapshot tag if pre-release
sh """
echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' > .npmrc
${isReleaseVersion ? '' : ('npm version --no-git-tag-version ' + version + '.' + env.BUILD_ID)}
npm publish ${isReleaseVersion ? '' : '--tag snapshot'}
"""
}
}
}
// Run the gitTagAndPublish which tags/publishes to github for release builds
gitTagAndPublish {
versionFile='package.json'
releaseApiUrl='https://api.github.com/repos/cloudant-labs/cloudant-follow/releases'
}
}