-
Notifications
You must be signed in to change notification settings - Fork 8
/
Jenkinsfile
225 lines (179 loc) · 5.83 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
@Library('pipeline-library') _
def MAIN_BRANCH = 'master'
def DEVELOP_BRANCH = 'develop'
def isBitbucket = false
def isMain = {
env.BRANCH_NAME == MAIN_BRANCH
}
def isRelease = {
env.BRANCH_NAME.startsWith('release/')
}
def isDevelop = {
env.BRANCH_NAME == DEVELOP_BRANCH
}
def isMainline = {
isMain() || isDevelop() || isRelease()
}
def getBranchType = {
isMainline() ? 'MAINLINE' : 'FEATURE'
}
def hasRunSpigotTests = false
def testSpigotByEnv = { environment, branch ->
stage("Spigot test '${environment}'") {
script {
println("Scheduling spigot test for: { env: '${environment}', branch: '${branch}' }")
build(job: 'spigot-tests-streaming-client-entry',
parameters: [
string(name: 'ENVIRONMENT', value: environment),
string(name: 'BRANCH_TO_TEST', value: branch)
],
propagate: true,
wait: true // wait for the test job to finish
)
}
}
}
def getDeployConfig = {
def deployConfig = [:]
if (isMainline()) {
deployConfig['dev'] = 'always'
deployConfig['test'] = 'always'
}
if (isMain()) {
deployConfig['prod'] = 'always'
deployConfig['fedramp-use2-core'] = 'always'
}
return deployConfig;
}
def getMailerAddresses = {
def mailer = '[email protected]'
if (isMain()) {
return mailer + ', [email protected]'
}
return mailer
}
def npmFunctions = new com.genesys.jenkins.Npm()
def gitFunctions = new com.genesys.jenkins.Git()
def notifications = new com.genesys.jenkins.Notifications()
// PCM – Just Send It
def chatGroupId = 'adhoc-60e40c95-3d9c-458e-a48e-ca4b29cf486d'
webappPipeline {
nodeVersion = '14.x'
projectName = 'developercenter-cdn/streaming-client'
team = 'Client Streaming and Signaling'
jiraProjectKey = 'STREAM'
mailer = getMailerAddresses()
chatGroupId = chatGroupId
nodeVersion = '14.x'
buildType = getBranchType
manifest = customManifest('dist') {
sh('node ./create-manifest.js')
readJSON(file: 'dist/manifest.json')
}
testJob = 'no-tests' // see buildStep to spigot tests
snykConfig = {
return [
organization: 'genesys-client-media-webrtc',
wait: true
]
}
autoSubmitCm = true
deployConfig = getDeployConfig()
ciTests = {
println("""
========= BUILD VARIABLES =========
ENVIRONMENT : ${env.ENVIRONMENT}
BUILD_NUMBER : ${env.BUILD_NUMBER}
BUILD_ID : ${env.BUILD_ID}
BRANCH_NAME : ${env.BRANCH_NAME}
APP_NAME : ${env.APP_NAME}
VERSION : ${env.VERSION}
===================================
""")
sh("""
npm i -g npm@7
npm ci
npm run test
""")
}
buildStep = {cdnUrl ->
sh("""
echo 'CDN_URL ${cdnUrl}'
npm --versions
npm run build
""")
}
onSuccess = {
sh("""
echo "=== root folder ==="
ls -als ./
echo "=== Printing manifest.json ==="
cat ./manifest.json
echo "=== Printing package.json ==="
cat ./package.json
echo "=== dist folder ==="
ls -als dist/
echo "=== Printing dist/deploy-info.json ==="
cat ./dist/deploy-info.json
# echo "=== Printing dist/package.json ==="
# cat ./dist/package.json
""")
// NOTE: this version only applies to the npm version published and NOT the cdn publish url/version
def version = env.VERSION
def packageJsonPath = "./package.json"
def tag = ""
// save a copy of the original package.json
// sh("cp ${packageJsonPath} ${packageJsonPath}.orig")
// if not MAIN branch, then we need to adjust the verion in the package.json
if (!isMain()) {
// load the package.json version
def packageJson = readJSON(file: packageJsonPath)
def featureBranch = env.BRANCH_NAME
// all feature branches default to --alpha
tag = "alpha"
if (isRelease()) {
tag = "next"
featureBranch = "release"
}
if (isDevelop()) {
tag = "beta"
featureBranch = "develop"
}
version = "${packageJson.version}-${featureBranch}.${env.BUILD_NUMBER}".toString()
}
stage('Publish to NPM') {
script {
dir(pwd()) {
npmFunctions.publishNpmPackage([
tag: tag, // optional
useArtifactoryRepo: isBitbucket, // optional, default `true`
version: version, // optional, default is version in package.json
dryRun: false // dry run the publish, default `false`
])
}
def message = "**${env.APP_NAME}** ${version} (Build [#${env.BUILD_NUMBER}](${env.BUILD_URL})) has been published to **npm**"
if (!tag) {
message = ":loudspeaker: ${message}"
}
notifications.requestToGenericWebhooksWithMessage(chatGroupId, message);
}
} // end publish to npm
if (isMain()) {
stage('Tag commit and merge back') {
script {
gitFunctions.tagCommit(
"v${version}",
gitFunctions.getCurrentCommit(),
isBitbucket
)
gitFunctions.mergeBackAndPrep(
MAIN_BRANCH,
DEVELOP_BRANCH,
'patch',
isBitbucket
)
}
} // end tag commit and merge back
} // isMain()
} // onSuccess
} // end