This repository has been archived by the owner on Jun 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
/
CliqzJenkinsfile.nightly
224 lines (216 loc) · 8.8 KB
/
CliqzJenkinsfile.nightly
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
#!/bin/env groovy
@Library('cliqz-shared-library@vagrant') _
properties([
disableConcurrentBuilds(),
[$class: 'JobRestrictionProperty']
])
def jobStatus = 'FAIL'
node('gideon') {
try{
timeout(120){
writeFile file: 'Vagrantfile', text: '''
Vagrant.configure("2") do |config|
config.vm.box = "xcode-10.1"
config.vm.synced_folder ".", "/vagrant", disabled: true
config.vm.define "publishios" do |publishios|
publishios.vm.hostname ="publishios"
publishios.vm.network "public_network", :bridge => "en0: Ethernet 1", auto_config: false
publishios.vm.boot_timeout = 900
publishios.ssh.forward_agent = true
publishios.vm.provider "virtualbox" do |v|
v.name = "publishios"
v.gui = false
v.memory = ENV["NODE_MEMORY"]
v.cpus = ENV["NODE_CPU_COUNT"]
end
publishios.vm.provision "shell", privileged: false, run: "always", inline: <<-SHELL#!/bin/bash -l
set -e
set -x
rm -f agent.jar
curl -LO #{ENV['JENKINS_URL']}/jnlpJars/agent.jar
nohup java -jar agent.jar -jnlpUrl #{ENV['JENKINS_URL']}/computer/#{ENV['NODE_ID']}/slave-agent.jnlp -secret #{ENV["NODE_SECRET"]} &
SHELL
end
end
'''
sh '''#!/bin/bash -l
set -e
set -x
mkdir -p .vagrant/machines/publishios/virtualbox
cd .vagrant/machines/publishios/virtualbox/
if [ ! -f id ]; then touch id && echo "1b070f2c-9c26-470f-9d81-58e109313b47" >> id; fi
'''
vagrant.inside(
'Vagrantfile',
'/jenkins',
2, // CPU
8000, // MEMORY
12000, // VNC port
false, // rebuild image
) { nodeId ->
node(nodeId) {
try {
stage('Checkout') {
checkout scm
}
stage('Prepare') {
sh '''#!/bin/bash -l
set -e
set -x
java -version
node -v
npm -v
brew -v
xcodebuild -version
pkgutil --pkg-info=com.apple.pkg.CLTools_Executables
sudo xcodebuild -license accept
fastlane clearCache
fastlane prepare
'''
}
stage('Build & Upload') {
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: 'c21d2e60-e4b9-4f75-bad7-6736398a1a05', variable: 'SentryDSN'),
string(credentialsId: '05be12cd-5177-4adf-9812-809f01451fa0', variable: 'FASTLANE_PASSWORD'),
string(credentialsId: 'ea8c47ad-1de8-4300-ae93-ec9ff4b68f39', variable: 'MATCH_PASSWORD'),
string(credentialsId: 'f206e880-e09a-4369-a3f6-f86ee94481f2', variable: 'SENTRY_AUTH_TOKEN'),
string(credentialsId: 'ab91f92a-4588-4034-8d7f-c1a741fa31ab', variable: 'FASTLANE_ITC_TEAM_ID')])
{
sh '''#!/bin/bash -l
set -x
set -e
rm -rf /Users/vagrant/Library/Keychains/ios-build.keychain*
rm -rf ../build-tools
export MATCH_KEYCHAIN_NAME=ios-build.keychain
export app_name=Cliqz
export CommitHash=`git rev-parse --short HEAD`
export PATH="$PATH:/Users/vagrant/Library/Python/2.7/bin"
echo de > shipping_locales.txt && echo en-US >> shipping_locales.txt
fastlane importLocalizations
fastlane cliqzNightly
'''
}
}
jobStatus = 'PASS'
}
catch(all) {
jobStatus = 'FAIL'
print "Something Failed. Check the above logs."
emailext(
to: 'iosdev@cliqz.com',
subject: '$PROJECT_NAME - Build # $BUILD_NUMBER Failed!!!',
body: '\n\nCheck console output at ' + env.BUILD_URL + ' to view the cause.'
)
currentBuild.result = 'FAILURE'
}
finally {
stage("Clean Up"){
sh '''#!/bin/bash -l
set -x
set -e
fastlane clearCache
'''
}
}
}
}
}
} catch(err){
echo 'Build was not completed before timeout'
currentBuild.result = 'FAILURE'
}
}
if (jobStatus == 'PASS') {
stage('Update Jira') {
withEnv(['JIRA_SITE=cliqztix']) {
passedBuilds = listOfFailedBuilds(currentBuild)
def issueIds = getIssueList()
def transitionInput = [
transition: [
id: '121',
],
]
for (id in issueIds) {
try {
def issue = jiraGetIssue idOrKey: id
if (issue.data.fields.status.name == "Resolved") {
jiraTransitionIssue idOrKey: id, input: transitionInput
echo "Transistioned ${id}"
} else{
echo """Element with id ${id} was not transitioned\nIts status is: """+issue.data.fields.status.name
}
} catch (Error e) {
echo e
}
}
}
}
}
/**
* Return the list of failed builds up to the latest successfull one or the
* first build if there is not such build
*
* @param build the current build
*/
def listOfFailedBuilds(build) {
def results = []
while (build != null && build.result != 'SUCCESS') {
println("Found unsuccessfull build ${build.number}")
results.add(build)
build = build.getPreviousBuild()
}
if (build != null) {
println("Found successfull build ${build.number}")
results.add(build)
} else {
println("Found EOL")
}
results
}
@NonCPS
def getChangeString(passedBuilds) {
def changeString = ""
echo "Gathering Changes Since Last Successful Build"
for (int x = 0; x < passedBuilds.size(); x++) {
def currentBuild = passedBuilds[x];
def buildNumber = currentBuild.number
echo "Changes for Build ${buildNumber}"
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} by ${entry.author} \n"
}
}
}
if (!changeString) {
changeString = " - No new changes"
}
echo changeString
return changeString;
}
@NonCPS
def getIssueList(){
def list = []
def changes = getChangeString(passedBuilds)
def re = /IB-([0-9])+/
def y = changes =~ re
while (y){
list.add(y.group().toString())
}
if (list.size() > 0) {
echo 'Detected JIRA tickets'
echo list.toString()
} else {
echo 'No JIRA tickets detected'
}
return list
}