-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathJenkinsfile
146 lines (127 loc) Β· 5.42 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
List<String> defineFlavor() {
//check if the pipeline has the custom flavor env variable set
def overwrite = env.CUSTOM_FLAVOR
if (overwrite != null) {
return overwrite
}
def branchName = env.BRANCH_NAME
if (branchName == "main") {
return ['Beta']
} else if (branchName == "develop") {
return ['Staging', 'Dev']
} else if (branchName == "prod") {
return ['Prod', 'Fdroid']
} else if (branchName == "internal") {
return ['Internal']
}
return ['Staging']
}
String defineBuildType(String flavor) {
def overwrite = env.CUSTOM_BUILD_TYPE
if (overwrite != null) {
return overwrite
}
// internal is used for wire beta builds
if (flavor == 'Beta') {
return 'Release'
} else if (flavor == 'Prod') {
return "Compatrelease"
}
// use the scala client signing keys for testing upgrades.
return "Compat"
}
String shellQuote(String s) {
// Quote a string so it's suitable to pass to the shell
return "'" + s.replaceAll("'", "'\"'\"'") + "'"
}
def postGithubComment(String changeId, String body) {
def authHeader = shellQuote("Authorization: token ${env.GITHUB_API_TOKEN}")
def apiUrl = shellQuote("https://api.github.com/repos/wireapp/wire-android/issues/${changeId}/comments")
// The comment body must be quoted for embedding into a JSON string,
// and the JSON string must be quoted for embedding into the shell command
// line. Note well: the backslash character has a special meaning in
// both the first argument (regular expression pattern) and the second
// (Matcher.replaceAll() escaping character) of String.replaceAll(); hence,
// yet another level of escaping is required here!
def payload = body.replaceAll('\\\\', '\\\\\\\\').replaceAll('"', '\\\\"').replaceAll('\n', '\\\\n')
def json = shellQuote('{"body":"' + payload + '"}')
// Note the interpolated variables here come from Groovy -- the command
// line which the shell interpreter executes is fully rendered, and contains
// no unsubstituted variables
sh "curl -s -H ${authHeader} -X POST -d ${json} ${apiUrl}"
}
/**
* Checks if the parameter is defined, otherwise sets it to the BRANCH_NAME env var
*
* @param changeBranch env var to use as the branch name if the changeBranch is not empty
*/
String handleChangeBranch(String changeBranch) {
if (changeBranch?.trim()) {
return changeBranch
}
return env.BRANCH_NAME
}
pipeline {
agent {
node {
label 'spawner'
}
}
options { disableConcurrentBuilds(abortPrevious: true) }
stages {
stage("check builder file") {
steps {
readTrusted "AR-builder.groovy"
}
}
stage("run pipeline") {
steps {
script {
def dynamicStages = [:]
List<String> flavorList = defineFlavor()
for (x in flavorList) {
String flavor = x
String buildType = defineBuildType(flavor)
String stageName = "Build $flavor$buildType"
String definedChangeBranch = handleChangeBranch(env.CHANGE_BRANCH)
dynamicStages[stageName] = {
node {
stage(stageName) {
build(
job: 'AR-build-pipeline',
parameters: [
string(name: 'SOURCE_BRANCH', value: env.BRANCH_NAME),
string(name: 'CHANGE_BRANCH', value: definedChangeBranch),
string(name: 'BUILD_TYPE', value: buildType),
string(name: 'FLAVOR', value: flavor),
booleanParam(name: 'UPLOAD_TO_S3', value: true),
booleanParam(name: 'UPLOAD_TO_PLAYSTORE_ENABLED', value: true),
booleanParam(name: 'RUN_UNIT_TEST', value: true),
booleanParam(name: 'RUN_ACCEPTANCE_TESTS', value: true),
booleanParam(name: 'RUN_STATIC_CODE_ANALYSIS', value: true),
string(name: 'GITHUB_CHANGE_ID', value: env.CHANGE_ID)]
)
}
}
}
}
parallel dynamicStages
}
}
}
}
post {
failure {
script {
if (env.BRANCH_NAME.startsWith('PR-')) {
def payload = "Build [${env.BUILD_NUMBER}](${env.BUILD_URL}) **failed**."
postGithubComment(env.CHANGE_ID, payload)
}
}
wireSend(secret: env.WIRE_BOT_SECRET, message: "**[#${BUILD_NUMBER} Link](${BUILD_URL})** [${BRANCH_NAME}] - β FAILED ($last_started) π")
}
aborted {
wireSend(secret: env.WIRE_BOT_SECRET, message: "**[#${BUILD_NUMBER} Link](${BUILD_URL})** [${BRANCH_NAME}] - β ABORTED ($last_started) ")
}
}
}