-
Notifications
You must be signed in to change notification settings - Fork 47
/
Jenkinsfile
243 lines (211 loc) · 5.84 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
@Library('pipeline-library')
import com.genesys.jenkins.Service
def notifications = null
String[] mailingList = [
]
def isActiveReleaseBranch() {
return env.SHORT_BRANCH.equals('master');
}
def isMaintenanceReleaseBranch() {
return env.SHORT_BRANCH.startsWith('maintenance/');
}
def isFeatureBranch() {
return env.SHORT_BRANCH.startsWith('feature/');
}
def isReleaseBranch() {
return isActiveReleaseBranch() || isMaintenanceReleaseBranch();
}
def isPublicBranch() {
isReleaseBranch() || isFeatureBranch();
}
def uploadVersionOverride() {
if (isFeatureBranch()) {
return "--version ${env.SHORT_BRANCH}"
} else {
return ""
}
}
pipeline {
agent { label 'dev_mesos_v2' }
options {
quietPeriod(480)
disableConcurrentBuilds()
}
environment {
NPM_UTIL_PATH = "npm-utils"
REPO_DIR = "repo"
SHORT_BRANCH = env.GIT_BRANCH.replaceFirst(/^origin\//, '');
}
tools {
nodejs "NodeJS 12.13.0"
}
stages {
stage('Import notifications lib') {
steps {
script {
// clone pipelines repo
dir('pipelines') {
git branch: 'master',
url: '[email protected]:inindca/pipeline-library.git',
changelog: false
notifications = load 'src/com/genesys/jenkins/Notifications.groovy'
}
}
}
}
stage('Checkout') {
steps {
deleteDir()
dir(env.REPO_DIR) {
checkout scm
// Make a local branch so we can work with history and push (there's probably a better way to do this)
sh "git checkout -b ${env.SHORT_BRANCH}"
}
}
}
stage('Avoid Build Loop') {
steps {
script {
dir(env.REPO_DIR) {
def lastCommit = sh(script: 'git log -n 1 --format=%s', returnStdout: true).trim()
if (lastCommit.startsWith('chore(release)')) {
currentBuild.description = 'Skipped'
currentBuild.result = 'ABORTED'
error('Last commit was a release, exiting build process.')
}
}
}
}
}
stage('Prep') {
steps {
sh "git clone --single-branch -b master --depth=1 [email protected]:inindca/npm-utils.git ${env.NPM_UTIL_PATH}"
dir(env.REPO_DIR) {
sh "${env.WORKSPACE}/${env.NPM_UTIL_PATH}/scripts/jenkins-create-npmrc.sh"
sh "cp .npmrc docs/.npmrc"
sh "npm ci"
sh "npm i --no-save @purecloud/web-app-deploy@latest"
}
}
}
stage('Check') {
steps {
dir(env.REPO_DIR) {
sh "npm run lint"
sh "npm run test.ci"
}
}
}
stage('Bump Version') {
when {
expression { isReleaseBranch() }
}
steps {
dir(env.REPO_DIR) {
script {
sh "npm run release"
}
}
}
}
stage('Build') {
steps {
dir(env.REPO_DIR) {
// Generate manifest file with deployment metadata
sh './scripts/generate-manifest'
// Generate the CDN_URL for use in the docs and build everything.
sh """
export DOCS_CDN_URL=\$(npx cdn ${uploadVersionOverride()} --ecosystem pc --manifest docs-manifest.json)
export CDN_URL=\$(npx cdn ${uploadVersionOverride()} --ecosystem pc --manifest library-manifest.json)
npm run build
"""
// Re-generate manifest file after building docs - required to find *.html in docs
sh './scripts/generate-manifest'
}
}
}
stage('Upload Assets') {
when {
expression { isPublicBranch() }
}
steps {
dir(env.REPO_DIR) {
sh "echo Uploading static assets!"
sh """
npx upload \
${uploadVersionOverride()} \
--ecosystem pc \
--manifest library-manifest.json \
--source-dir ./dist/genesys-webcomponents
"""
}
}
}
stage('Publish Library') {
when {
expression { isReleaseBranch() }
}
steps {
dir(env.REPO_DIR) {
script {
sh "npm publish"
sshagent(credentials: ['3aa16916-868b-4290-a9ee-b1a05343667e']) {
sh "git push --follow-tags -u origin ${env.SHORT_BRANCH}"
}
}
script {
publishedVersion = sh(script: 'node -e "console.log(require(\'./package.json\').version)"', returnStdout: true).trim()
currentBuild.description = publishedVersion
}
}
}
}
stage('Upload Docs') {
when {
expression { isPublicBranch() }
}
steps {
sh "echo Uploading release!"
dir (env.REPO_DIR) {
sh './scripts/generate-versions-file'
sh """
npx upload \
${uploadVersionOverride()} \
--ecosystem pc \
--manifest docs-manifest.json \
--source-dir ./docs/dist
"""
}
}
}
stage('Deploy Docs') {
when {
expression { isActiveReleaseBranch() }
}
steps {
dir (env.REPO_DIR) {
sh '''
npx deploy \
--ecosystem pc \
--manifest docs-manifest.json \
--dest-env dev
'''
}
}
}
}
post {
fixed {
script {
notifications.emailResults(mailingList.join(" "))
}
}
failure {
script {
notifications.emailResults(mailingList.join(" "))
}
}
}
}