forked from folio-org/platform-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
256 lines (233 loc) · 8.58 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
244
245
246
247
248
249
250
251
252
253
254
255
256
@Library ('folio_jenkins_shared_libs') _
pipeline {
environment {
folioPlatform = 'platform-core'
npmConfig = 'jenkins-npm-folio'
sshKeyId = '11657186-f4d4-4099-ab72-2a32e023cced'
folioRegistry = 'http://folio-registry.aws.indexdata.com'
releaseOnly = 'true'
projUrl = "https://github.com/folio-org/${env.folioPlatform}"
}
options {
timeout(30)
buildDiscarder(logRotator(numToKeepStr: '30'))
}
agent {
node {
label 'jenkins-agent-java11'
}
}
stages {
stage('Setup') {
steps {
sendNotifications 'STARTED'
script {
currentBuild.displayName = "#${env.BUILD_NUMBER}-${env.JOB_BASE_NAME}"
// These two variable are set by Github Branch Source plugin
echo "Origin branch: $env.CHANGE_BRANCH"
echo "Target branch: $env.CHANGE_TARGET"
def lastCommit = sh(returnStatus: true,
script: "git log -1 | grep '.*\\[CI SKIP\\].*'")
if (lastCommit == 0) {
echo "CI SKIP detected. Aborting build"
env.skipBuild = 'true'
}
}
}
}
stage('Do Build') {
when {
expression {
env.skipBuild != 'true'
}
}
stages {
stage('Build Stripes Platform') {
when {
not {
branch 'master'
}
}
steps {
script {
if (fileExists('.pr-custom-deps.json')) {
env.okapiUrl = 'https://okapi-preview.ci.folio.org'
}
else {
env.okapiUrl = 'https://okapi-default.ci.folio.org'
}
if (env.CHANGE_ID) {
def tenant = "${env.folioPlatform}_${env.CHANGE_ID}_${env.BUILD_NUMBER}"
def foliociLib = new org.folio.foliociCommands()
env.tenant = foliociLib.replaceHyphen(tenant)
}
else {
env.tenant = 'diku'
}
}
echo "Okapi URL: ${env.okapiUrl}"
echo "Tenant: ${env.tenant}"
// Remove existing .yarnrc on build image for release builds.
// Use repo configuration.
sh 'rm -f /home/jenkins/.yarnrc'
buildStripesPlatform(env.okapiUrl,env.tenant)
}
}
stage('Check Platform Dependencies') {
when {
not {
branch 'master'
}
}
steps {
script {
def foliociLib = new org.folio.foliociCommands()
// Deal with PR Deps for preview mode
if (fileExists('.pr-custom-deps.json')) {
def previewMods = readJSON file: '.pr-custom-deps.json'
// update okapi-install.json
def okapiInstall = readJSON file: 'okapi-install.json'
def newOkapiInstall = foliociLib.subPreviewMods(previewMods,okapiInstall)
writeJSON file: 'okapi-install.json', json: newOkapiInstall, pretty: 2
sh 'cat okapi-install.json'
}
else {
// Add extra backend deps
echo "Creating okapi preseed module list"
sh 'jq -s \'.[0]=([.[]]|flatten)|.[0]\' stripes-install.json install-extras.json > install-pre.json'
def installPreJson = readFile('./install-pre.json')
def okapiVersion = sh(returnStdout: true, script: 'jq -r \'.[].id\' install-extras.json | grep okapi | cut -d - -f 2').trim()
platformDepCheck(env.tenant,installPreJson,okapiVersion)
echo 'Generating backend dependency list to okapi-install.json'
sh 'jq \'map(select(.id | test(\"mod-\"; \"i\")))\' install.json > okapi-install.json'
sh 'cat okapi-install.json'
sh 'mv stripes-install.json stripes-install-pre.json'
sh 'jq \'map(select(.id | test(\"edge-\"; \"i\")))\' install.json > install-edge.json'
sh 'jq -s \'.[0]=([.[]]|flatten)|.[0]\' stripes-install-pre.json install-edge.json > stripes-install.json'
sh 'cat stripes-install.json'
}
}
// archive install.json
sh 'mkdir -p ci'
sh 'cp install.json ci'
publishHTML([allowMissing: false, alwaysLinkToLastBuild: false,
keepAll: true, reportDir: 'ci',
reportFiles: 'install.json',
reportName: "install.json",
reportTitles: "install.json"])
}
}
/*
* stage('Deploy Tenant') {
* when {
* changeRequest()
* }
* steps {
* // set up preview environment
* script {
* if (fileExists('.pr-custom-deps.json')) {
* setupPreviewEnv()
* }
* }
*
* // Enable tenant
* deployTenantK8()
*
* script {
* // Deploy tenant bundle to S3
* withCredentials([[$class: 'AmazonWebServicesCredentialsBinding',
* accessKeyVariable: 'AWS_ACCESS_KEY_ID',
* credentialsId: 'jenkins-aws',
* secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]) {
*
* def s3Opts = [ s3Bucket: "${env.folioPlatform}-${env.CHANGE_ID}",
* s3Tags: "Key=Pr,Value=${env.folioPlatform}-${env.CHANGE_ID}",
* srcPath: "${env.WORKSPACE}/output" ]
*
* def s3Endpoint = s3Upload(s3Opts)
* env.folioUrl = s3Endpoint + '/index.html'
* }
*
* def githubSummary = "Bundle deployed for tenant,${tenant}," +
* "to ${env.folioUrl}"
* @NonCPS
* def comment = pullRequest.comment(githubSummary)
* }
* }
* }
*/
/*
* stage('Run Integration Tests') {
* when {
* changeRequest()
* }
* steps {
* script {
* def testOpts = [ tenant: env.tenant,
* folioUrl: env.folioUrl,
* okapiUrl: env.okapiUrl,
* folioUser: env.tenant + '_admin',
* folioPassword: 'admin']
*
* def testStatus = runIntegrationTests(testOpts)
*
* if (testStatus == 'FAILED') {
* error('UI Integration test failures')
* }
* }
* }
* }
*/
stage('Publish NPM Package') {
when {
buildingTag()
}
steps {
withCredentials([string(credentialsId: 'jenkins-npm-folioci',variable: 'NPM_TOKEN')]) {
withNPM(npmrcConfig: env.npmConfig) {
// clean up generated artifacts before publishing
sh 'rm -rf ci artifacts bundle node_modules'
// don't include these in package
sh 'rm -rf yarn.lock install.json stripes-install.json okapi-install.json'
sh 'npm publish'
}
}
}
}
stage('Update Branch Install Artifacts') {
// Update branch with install artifacts
when {
changeRequest()
}
steps {
script {
def installFiles = ['stripes-install.json',
'okapi-install.json',
'install.json',
'yarn.lock']
sh "git fetch --no-tags ${env.projUrl} " +
"+refs/heads/${env.CHANGE_BRANCH}:refs/remotes/origin/${env.CHANGE_BRANCH}"
sh "git checkout -b ${env.CHANGE_BRANCH} origin/${env.CHANGE_BRANCH}"
for (int i = 0; i < installFiles.size(); i++) {
sh "git add ${env.WORKSPACE}/${installFiles[i]}"
}
commitStatus = sh(returnStatus: true,
script: 'git commit -m "[CI SKIP] Updating install files on branch"')
if (commitStatus == 0) {
sshGitPush(origin: env.folioPlatform, branch: env.CHANGE_BRANCH)
}
else {
echo "No new changes. No push to git origin needed"
}
}
}
}
} // end 'do build' stage
} // end inner stages
} // end outter stages
post {
always {
sendNotifications currentBuild.result
}
}
}