-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathJenkinsfileMacOS
343 lines (317 loc) · 16.8 KB
/
JenkinsfileMacOS
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
@Library('gematik-jenkins-shared-library') _
def BRANCH = 'master'
def JIRA_PROJECT_ID = 'AUTHCL'
def REPORT_DIR = 'reports'
def CREDENTIAL_ID_GEMATIK_GIT = 'svc_gitlab_prod_credentials'
def TARGET = 'macOS'
def currentStage = ''
def KONNEKTOR_LOCKS = [ 'Koco': 'authenticator-k10',
'Rise': 'authenticator-k12',
'Secunet': 'authenticator-k23' ]
pipeline {
options {
disableConcurrentBuilds()
}
agent { label 'IOSDEV2' }
triggers {
cron(env.BRANCH_NAME == 'master' ? '00 05 * * *' : '')
}
environment {
GH_TOKEN = credentials('GITHUB.API.Token')
IDP_DEV_API_KEY = credentials('IDP_DEV_GEMATIK_SOLUTIONS_API_KEY')
CONNECTOR_CREDS = credentials('CONNECTOR_23')
SNYK_TOKEN = credentials('snyk_authenticator_account')
SNYK_API ='https://app.eu.snyk.io/'
APP_STORE_CONNECT = credentials('APPSTORE-CONNECT_NOTARIZATION_KEY')
APP_STORE_CONNECT_API_KEY_KEY_ID = "${APP_STORE_CONNECT_USR}"
APP_STORE_CONNECT_API_KEY_KEY = "${APP_STORE_CONNECT_PSW}"
KEYCHAIN_PASSWORD = credentials('KEYCHAIN_PASSWORD')
MATCH_PASSWORD = credentials('MATCH_PASSWORD')
}
parameters {
booleanParam(name: 'MOCK_BUILD', defaultValue: false, description: 'Build the Mock-Version from the Authenticator but do not archive it')
booleanParam(name: 'ARCHIVE_ARTIFACTS', defaultValue: false, description: 'Should the artifacts be archived? releases/*, release & master will be archived in anyway')
booleanParam(name: 'SIGN_ARTIFACTS', defaultValue: false, description: 'Should the artifacts be signed? Only Tags can be signed')
booleanParam(name: 'E2E', defaultValue: false, description: 'E2E Testsuite')
booleanParam(name: 'TEAMS_NOTIFICATION', defaultValue: false, description: 'Send Teams Notification about this build. Always true for Master and Release Branches.')
choice(name: 'CONNECTOR_CHOICE', choices: ['Rise', 'Secunet', 'Koco' ], description: 'Pick the connector for the "Integration Tests"-step.')
}
stages {
stage('Install Brewfile') {
steps {
script {
currentStage = env.STAGE_NAME
}
sh 'brew bundle install --file=Brewfile'
}
}
stage('Build Node.js WebApp') {
steps {
script {
currentStage = env.STAGE_NAME
}
gitSetIdentity()
sh 'node --version'
sh 'npm -version'
sh 'cat ~/.npmrc || true'
// Actual CI Build, Tests, Demo App
sh label: 'starting ios test run', script: '''#!/bin/bash -l
set -ev
ELECTRON_GET_USE_PROXY=true GLOBAL_AGENT_HTTPS_PROXY=$https_proxy npm ci
'''
// copy LICENSE.txt into ./src/assets/license_de.txt to add it to the DMG file
sh 'iconv -f windows-1250 -t utf-8 LICENSE.txt > ./src/assets/license_de.txt'
}
}
stage('Set BUILD_VERSION') {
steps {
script {
currentStage = env.STAGE_NAME
def packageJson = readFile(file: 'package.json')
def parsedJson = new groovy.json.JsonSlurper().parseText(packageJson)
env.BUILD_VERSION = parsedJson.version
echo "Build version: ${env.BUILD_VERSION}"
}
}
}
stage('Tests & Linting') {
parallel {
stage('Linting Node.js WebApp') {
steps {
script {
currentStage = env.STAGE_NAME
}
sh 'echo Start Linting'
sh "npm run lint:ci"
//stash name: 'linting-report', includes: 'reports/eslint-report.xml'
}
}
stage('Unit Tests') {
steps {
script {
currentStage = env.STAGE_NAME
try {
sh 'npm run test:unit -- --silent'
} catch (Exception e) {
echo 'Running additional unit tests for failures...'
sh 'npm run jest:base -- --onlyFailures tests/unit -- --silent'
} finally {
sh """
if [ ! -d "./${REPORT_DIR}" ]; then
mkdir "./${REPORT_DIR}"
fi
# Move the test report to the reports directory
mv jenkins-jest-test-report.xml ./${REPORT_DIR}/jenkins-jest-unit-test-report.xml
# Move the coverage report to the reports directory
mv ./coverage/lcov.info ./${REPORT_DIR}/unit-lcov.info
"""
// stash name: 'unit-test-reports', includes: 'reports/jenkins-jest-unit-test-report.xml,reports/unit-lcov.info'
}
}
}
}
stage('Integration Tests') {
steps {
script {
currentStage = env.STAGE_NAME
def connectorEnvFile = "${params.CONNECTOR_CHOICE}.env"
sh "cp ${connectorEnvFile} .env"
lock(resource: KONNEKTOR_LOCKS[params.CONNECTOR_CHOICE]) { // get lockable resources for every Konnektor (For now only Secunet is available) [SWF-542]
sh 'npm run test:integration -- --silent'
sh """
if [ ! -d "./${REPORT_DIR}" ]; then
mkdir "./${REPORT_DIR}"
fi
mv jenkins-jest-test-report.xml ./${REPORT_DIR}/jenkins-jest-integration-test-report.xml
mv ./coverage/lcov.info ./${REPORT_DIR}/integration-lcov.info
"""
// stash name: 'integration-test-reports', includes: 'reports/jenkins-jest-integration-test-report.xml,reports/integration-lcov.info'
}
}
}
}
}
}
stage('Mock Mode: Build Electron Desktop App') {
when {
expression { params.MOCK_BUILD }
}
steps {
script {
// set the environment variable NPM_SCRIPT to electron:build, this will be used in the Fastfile
env.NPM_SCRIPT = 'mock:build'
currentStage = env.STAGE_NAME
}
sh label: 'Build and Notarize Authenticator for macos', script: '''#!/bin/bash -l
if [ -f $HOME/.bash_profile ]; then source $HOME/.bash_profile; fi
set -ev
security -v unlock-keychain -p "${KEYCHAIN_PASSWORD}" ~/Library/Keychains/login.keychain
bundle install
bundle exec fastlane build_authenticator
'''
// move the artifacts to the releaseCI folder
sh 'mkdir -p releaseCI'
sh "mv 'release/gematik Authenticator - Mock Version ${env.BUILD_VERSION}.dmg' 'releaseCI/gematik-Authenticator-Mock-Version-${env.BUILD_VERSION}.dmg'"
}
}
stage('Remove unnecessary certificates') {
when {
anyOf {
expression { params.SIGN_ARTIFACTS }
}
}
steps {
script {
currentStage = env.STAGE_NAME
sh 'rm -rf src/assets/certs-konnektor/ru'
}
}
}
stage('Build Electron Desktop App') {
steps {
script {
// set the environment variable NPM_SCRIPT to electron:build, this will be used in the Fastfile
env.NPM_SCRIPT = 'electron:build'
currentStage = env.STAGE_NAME
}
sh label: 'Build and Notarize Authenticator for macos', script: '''#!/bin/bash -l
if [ -f $HOME/.bash_profile ]; then source $HOME/.bash_profile; fi
set -ev
security -v unlock-keychain -p "${KEYCHAIN_PASSWORD}" ~/Library/Keychains/login.keychain
bundle install
bundle exec fastlane build_authenticator
'''
// move the artifacts to the releaseCI folder
sh 'mkdir -p releaseCI'
sh "mv 'release/gematik Authenticator ${env.BUILD_VERSION}.dmg' 'releaseCI/gematik-Authenticator-${env.BUILD_VERSION}.dmg'"
sh "mv 'release/gematik Authenticator ${env.BUILD_VERSION}.dmg.blockmap' 'releaseCI/gematik-Authenticator-${env.BUILD_VERSION}.dmg.blockmap'"
sh "mv 'release/gematik Authenticator ${env.BUILD_VERSION}.zip' 'releaseCI/gematik-Authenticator-${env.BUILD_VERSION}.zip'"
sh "mv 'release/latest-mac.yml' 'releaseCI/latest-mac.yml'"
}
}
stage('Compute SHA256 Hash') {
steps {
script {
currentStage = env.STAGE_NAME
def filePath = "releaseCI/gematik-Authenticator-${env.BUILD_VERSION}.dmg"
// Compute SHA256 hash with a given Jenkins function
def sha256Hash = sha256 file: filePath
writeFile file: "sha256Hash.txt", text: "" + sha256Hash
echo "SHA256 Hash for Prod-Version: " + sha256Hash
sh 'cp sha256Hash.txt releaseCI/'
if (params.MOCK_BUILD == true) {
def filePathMock = "releaseCI/gematik-Authenticator-Mock-Version-${env.BUILD_VERSION}.dmg"
def sha256HashMock = sha256 file: filePathMock
writeFile file: "sha256HashMock.txt", text: "" + sha256HashMock
echo "SHA256 Hash for Mock-Version: " + sha256HashMock
sh 'cp sha256HashMock.txt releaseCI/'
}
}
}
}
stage('Nexus Upload: Snapshot') {
when {
anyOf {
branch 'release'
branch 'master'
expression { params.ARCHIVE_ARTIFACTS == true }
buildingTag()
}
}
steps {
script {
currentStage = env.STAGE_NAME
nexusFileUpload("./releaseCI/gematik-Authenticator-${env.BUILD_VERSION}.dmg", "de/gematik/authenticator/snapshot/macOS/gematik-Authenticator-${env.BUILD_VERSION}.dmg", "gematik_snapshots_raw")
nexusFileUpload("./releaseCI/gematik-Authenticator-${env.BUILD_VERSION}.dmg.blockmap", "de/gematik/authenticator/snapshot/macOS/gematik-Authenticator-${env.BUILD_VERSION}.dmg.blockmap", "gematik_snapshots_raw")
nexusFileUpload("./releaseCI/gematik-Authenticator-${env.BUILD_VERSION}.zip", "de/gematik/authenticator/snapshot/macOS/gematik-Authenticator-${env.BUILD_VERSION}.zip", "gematik_snapshots_raw")
nexusFileUpload("./releaseCI/latest-mac.yml", "de/gematik/authenticator/snapshot/macOS/latest-mac.yml", "gematik_snapshots_raw")
nexusFileUpload("releaseCI/sha256Hash.txt", "de/gematik/authenticator/${BUILD_VERSION}/windows/sha256Hash.txt", "gematik_releases_raw")
if (params.MOCK_BUILD == true) {
nexusFileUpload("./releaseCI/gematik-Authenticator-Mock-Version-${env.BUILD_VERSION}.dmg", "de/gematik/authenticator/snapshot/macOS/gematik-Authenticator-Mock-Version-${env.BUILD_VERSION}.dmg", "gematik_snapshots_raw")
nexusFileUpload("releaseCI/sha256HashMock.txt", "de/gematik/authenticator/${BUILD_VERSION}/windows/sha256HashMock.txt", "gematik_releases_raw")
}
}
}
}
stage('Nexus Upload: Releases') {
when {
allOf {
expression { params.SIGN_ARTIFACTS }
branch 'release'
}
}
steps {
script {
currentStage = env.STAGE_NAME
nexusFileUpload("./releaseCI/gematik-Authenticator-${env.BUILD_VERSION}.dmg", "de/gematik/authenticator/snapshot/macOS/gematik-Authenticator-${env.BUILD_VERSION}.dmg", "gematik_releases_raw")
nexusFileUpload("./releaseCI/gematik-Authenticator-${env.BUILD_VERSION}.dmg.blockmap", "de/gematik/authenticator/snapshot/macOS/gematik-Authenticator-${env.BUILD_VERSION}.dmg.blockmap", "gematik_releases_raw")
nexusFileUpload("./releaseCI/gematik-Authenticator-${env.BUILD_VERSION}.zip", "de/gematik/authenticator/snapshot/macOS/gematik-Authenticator-${env.BUILD_VERSION}.zip", "gematik_releases_raw")
nexusFileUpload("./releaseCI/gematik-Authenticator-${env.BUILD_VERSION}.zip", "de/gematik/authenticator/snapshot/macOS/gematik-Authenticator-${env.BUILD_VERSION}.zip", "gematik_releases_raw")
nexusFileUpload("./releaseCI/latest-mac.yml", "de/gematik/authenticator/snapshot/macOS/latest-mac.yml", "gematik_releases_raw")
nexusFileUpload("releaseCI/sha256Hash.txt", "de/gematik/authenticator/${BUILD_VERSION}/windows/sha256Hash.txt", "gematik_releases_raw")
if (params.MOCK_BUILD == true) {
nexusFileUpload("./releaseCI/gematik-Authenticator-Mock-Version-${env.BUILD_VERSION}.dmg", "de/gematik/authenticator/snapshot/macOS/gematik-Authenticator-Mock-Version-${env.BUILD_VERSION}.dmg", "gematik_releases_raw")
nexusFileUpload("releaseCI/sha256HashMock.txt", "de/gematik/authenticator/${BUILD_VERSION}/windows/sha256HashMock.txt", "gematik_releases_raw")
}
}
}
}
stage('Archive Artifacts') {
when {
anyOf {
expression { BRANCH_NAME ==~ /releases\/(.*)+/ }
branch 'release'
branch 'master'
expression { params.ARCHIVE_ARTIFACTS == true }
buildingTag()
}
}
steps {
script {
currentStage = env.STAGE_NAME
}
archiveArtifacts artifacts: "releaseCI/*.dmg,releaseCI/*.dmg.blockmap,releaseCI/*.zip,releaseCI/latest-mac.yml,releaseCI/sha256Hash.txt,releaseCI/sha256HashMock.txt,${REPORT_DIR}/*.*", onlyIfSuccessful: 'true'
}
}
stage('Archive Build Log') {
when {
allOf {
branch 'release'
expression { params.SIGN_ARTIFACTS }
}
}
steps {
script {
currentStage = env.STAGE_NAME
}
build job: 'Authenticator-Authenticator_Archive_Buildlog-Release',
parameters: [
string(name: 'BUILDNUMBER', value: "${BUILD_NUMBER}"),
string(name: 'COMMIT_MESSAGE', value: "Save Log for Build ${BUILD_NUMBER}")
]
}
}
}
post {
always {
script {
node('k8-backend-small') {
def facts = [
'Version': "${env.BUILD_VERSION}",
'Branch': "${env.BRANCH_NAME}",
'Integration Tests': "${params.CONNECTOR_CHOICE}",
'Target': "${TARGET}",
]
if (currentBuild.result != 'SUCCESS') {
facts['Error in stage'] = "${currentStage}"
echo "Pipeline failed in stage: ${currentStage}"
}
if(params.TEAMS_NOTIFICATION || env.BRANCH_NAME == "release" || env.BRANCH_NAME.startsWith("releases/") || env.BRANCH_NAME == 'master' ) {
teamsSendNotificationToGroupChat('19:[email protected]', ['facts': facts])
}
echo "Integration Tests via: ${params.CONNECTOR_CHOICE}"
}
}
}
}
}