-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathJenkinsfile
198 lines (159 loc) · 5.12 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
@Library('pipeline-library') _
def isBitbucket = false
def MAIN_BRANCH = 'main'
def DEVELOP_BRANCH = 'develop'
def isRelease = {
env.BRANCH_NAME.startsWith('release/')
}
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 getDeployConfig = {
def deployConfig = [:]
if (isMainline()) {
deployConfig['dev'] = 'always'
deployConfig['test'] = 'always'
}
if (isMain()) {
deployConfig['prod'] = 'always'
deployConfig['fedramp-use2-core'] = 'always'
}
return deployConfig;
}
def npmFunctions = new com.genesys.jenkins.Npm()
def gitFunctions = new com.genesys.jenkins.Git()
def notifications = new com.genesys.jenkins.Notifications()
def chatGroupId = 'adhoc-60e40c95-3d9c-458e-a48e-ca4b29cf486d'
webappPipeline {
team = 'Client Streaming and Signaling'
projectName = 'client-auth'
jiraProjectKey = 'STREAM'
nodeVersion = '14.x'
mailer = 'GcMediaStreamSignal@genesys.com'
buildType = getBranchType
manifest = staticManifest([
'index.html',
'robots.txt',
'genesys-cloud-client-auth.browser.min.js',
'genesys-cloud-client-auth.browser.min.js.map'
])
testJob = 'no-tests'
deployConfig = getDeployConfig()
chatGroupId = chatGroupId
autoSubmitCm = true
snykConfig = {
return [
organization: 'genesys-client-media-webrtc',
wait: true
]
}
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 run install:all
npm run test
""")
}
buildStep = {cdnUrl ->
sh("""
CDN_URL='${cdnUrl}'
echo 'CDN_URL ${cdnUrl}'
npm run install:all && PUBLIC_URL=\$CDN_URL 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
}