forked from ghostery/user-agent-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
241 lines (197 loc) · 8.26 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
#!/bin/env groovy
def apps = [
'Cliqz': [
'name': 'Cliqz',
'sentryDSN': 'c21d2e60-e4b9-4f75-bad7-6736398a1a05',
],
'CliqzNightly': [
'name': 'CliqzNightly',
'sentryDSN': '9da58d1c-e7ce-4b2d-a99e-7ded5b130a20',
],
]
def triggers = []
def app
if("$BRANCH_NAME" == 'develop' || "$BRANCH_NAME" == 'jenkins') {
triggers << cron('H H(18-20) * * *')
app = apps['CliqzNightly']
} else {
app = apps['Cliqz']
}
@Library('cliqz-shared-library@vagrant') _
properties([
disableConcurrentBuilds(),
[$class: 'JobRestrictionProperty'],
pipelineTriggers(triggers),
])
def vagrantfile = '''
require 'uri'
node_id = URI::encode(ENV['NODE_ID'] || '')
name = "xcode12-#{ENV['BRANCH_NAME'] || ''}"
Vagrant.configure("2") do |config|
config.vm.box = "xcode12"
config.vm.synced_folder ".", "/vagrant", disabled: true
config.vm.define "xcode12" do |image|
image.vm.hostname = "xcode12"
image.ssh.forward_agent = true
config.vm.provider "parallels" do |prl|
prl.name = name
prl.memory = ENV["NODE_MEMORY"] || 8000
prl.cpus = ENV["NODE_CPU_COUNT"] || 2
end
image.vm.provision "shell", privileged: false, run: "always", inline: <<-SHELL#!/bin/bash -l
set -e
set -x
sudo mkdir -p /Users/vagrant/jenkins
sudo chown vagrant /Users/vagrant/jenkins
brew -v
brew tap adoptopenjdk/openjdk
# `which java` does not work as MacOS try to be smart and request jave installation
java -version &>/dev/null || brew cask install adoptopenjdk8
java -version
curl -LO #{ENV['JENKINS_URL']}/jnlpJars/agent.jar
nohup java -jar agent.jar -jnlpUrl #{ENV['JENKINS_URL']}/computer/#{node_id}/slave-agent.jnlp -secret #{ENV["NODE_SECRET"]} > agent.log 2> agent.log &
SHELL
end
end
'''
node('gideon') {
stage('Start VM')
writeFile file: 'Vagrantfile', text: vagrantfile
vagrant.inside(
'Vagrantfile',
'/Users/vagrant/jenkins',
4, // CPU
8192, // MEMORY
12000, // VNC port
false, // rebuild image
) { nodeId ->
node(nodeId) {
stage('Checkout') {
checkout scm
}
stage('Bootstrap') {
timeout(40) {
ansiColor('xterm') {
sh '''#!/bin/bash -l
set -e
set -x
# For Cocoapods and Fastlane
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
sudo systemsetup -setharddisksleep Off
sudo systemsetup -setcomputersleep Never
sudo xcode-select --switch /Applications/Xcode.app/
xcodebuild -version
pkgutil --pkg-info=com.apple.pkg.CLTools_Executables
sudo xcodebuild -license accept
# sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
sudo gem install which bundler || gem install bundler
which sentry-cli || curl -sL https://sentry.io/get-cli/ | bash
./bootstrap.sh
'''
}
}
}
stage('Build') {
withCredentials([
[
$class : 'UsernamePasswordMultiBinding',
credentialsId : '85859bba-4927-4b14-bfdf-aca726009962',
passwordVariable: 'GITHUB_PASSWORD',
usernameVariable: 'GITHUB_USERNAME',
],
string(credentialsId: '8b4f7459-c446-4058-be61-3c3d98fe72e2', variable: 'ITUNES_USER'),
string(credentialsId: '05be12cd-5177-4adf-9812-809f01451fa0', variable: 'FASTLANE_PASSWORD'),
string(credentialsId: 'ea8c47ad-1de8-4300-ae93-ec9ff4b68f39', variable: 'MATCH_PASSWORD'),
string(credentialsId: 'ab91f92a-4588-4034-8d7f-c1a741fa31ab', variable: 'FASTLANE_ITC_TEAM_ID'),
string(credentialsId: app.sentryDSN, variable: 'SENTRY_DSN'),
]) {
timeout(40) {
ansiColor('xterm') {
sh """#!/bin/bash -l
set -x
set -e
# For Cocoapods and Fastlane
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export FASTLANE_HIDE_CHANGELOG=true
rm -rf /Users/vagrant/Library/Keychains/ios-build.keychain*
export MATCH_KEYCHAIN_NAME=ios-build.keychain
nodenv exec npm run update-content-blocker
rbenv exec bundle exec fastlane Build app:${app.name}
"""
}
}
}
}
stage('Upload') {
def allBuilds = getAllBuilds(currentBuild)
def newChangelog = getChangeString(allBuilds)
def changelog = readFile 'CHANGELOG.md'
writeFile file: 'CHANGELOG.md', text: """${changelog}
## [Unreleased]
${newChangelog}"""
withCredentials([
string(credentialsId: '8b4f7459-c446-4058-be61-3c3d98fe72e2', variable: 'ITUNES_USER'),
string(credentialsId: '05be12cd-5177-4adf-9812-809f01451fa0', variable: 'FASTLANE_PASSWORD'),
string(credentialsId: 'f206e880-e09a-4369-a3f6-f86ee94481f2', variable: 'SENTRY_AUTH_TOKEN'),
string(credentialsId: 'ab91f92a-4588-4034-8d7f-c1a741fa31ab', variable: 'FASTLANE_ITC_TEAM_ID'),
]) {
timeout(120) {
ansiColor('xterm') {
sh """#!/bin/bash -l
set -x
set -e
# For Cocoapods and Fastlane
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export FASTLANE_HIDE_CHANGELOG=true
rbenv exec bundle exec fastlane Upload app:${app.name}
"""
}
}
}
withCredentials([
string(credentialsId: 'f206e880-e09a-4369-a3f6-f86ee94481f2', variable: 'SENTRY_AUTH_TOKEN'),
]) {
withEnv(['SENTRY_ORG=cliqz']) {
sh '''#!/bin/bash -l
set -x
set -e
VERSION=$(sentry-cli releases propose-version)
# Create a release
sentry-cli releases new -p cliqznighly-ios $VERSION
# Associate commits with the release
sentry-cli releases set-commits --auto $VERSION
'''
}
}
}
}
}
}
def getAllBuilds(build) {
def results = [build]
build = build.getPreviousBuild()
while (build != null && build.result != 'SUCCESS') {
results.add(build)
build = build.getPreviousBuild()
}
return results
}
def getChangeString(builds) {
def changeString = ""
for (int x = builds.size() - 1; x >= 0; x--) {
def currentBuild = builds[x];
def buildNumber = currentBuild.number
def changeLogSets = currentBuild.rawBuild.changeSets
for (int i = 0; i < changeLogSets.size(); i++) {
def entries = changeLogSets[i].items
for (int j = 0; j < entries.length; j++) {
def entry = entries[j]
changeString += "- ${entry.msg}\n"
}
}
}
return changeString;
}