-
Notifications
You must be signed in to change notification settings - Fork 0
/
jenkinsTestflightUploader.groovy
89 lines (71 loc) · 2.49 KB
/
jenkinsTestflightUploader.groovy
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
import hudson.model.*
/*
* TestFlight constants
*/
// the following are mandatory (get them from your TestFlight account on www.testflightapp.com)
def apiToken = "<your_testflight_api_token>"
def teamToken = "<your_testflight_team_token>"
// Distribution list: to send emails about the build to people in your distribution list (set to "" if not interested)
def testFlightDistList = "<testflight_distribution_list_name>"
// Build notes: absolute path to a text file containing notes to be prepended to every email sent
def testFlightNotes = "/path/to/file.text"
// Build change log: a temporary file used by the script to collect commit messages and append them to the above notes
def changeLog = "/temp/changelog.txt"
// get changes since last build
def buildChanges = build.getChangeSet()
// prepare TestFlight release notes
String fileContents = new File(testFlightNotes).text
File cl = new File(changeLog)
cl.write(fileContents)
if(!buildChanges.isEmptySet()){
// append commit messages and author
def entryNumber = 1
buildChanges.each() { entry ->
cl.append("${entryNumber}. " + entry.getMsg() + " - " + entry.getAuthor() + "\n")
entryNumber++
}
}
else{
cl.append("No changes")
}
testFlightNotes = changeLog
// find the .ipa or .apk build output file in the workspace
def getBuildFile(fileOrDir){
def filePattern = ~/.*\.(ipa|apk)$/
def found = null
if(fileOrDir.isDirectory()){
fileOrDir.eachFileRecurse{
if(!it.isDirectory() && it.getName() =~ filePattern)
found = it.getAbsolutePath()
}
}else{
if(fileOrDir.getName() =~ filePattern){
found = fileOrDir.getAbsolutePath()
}
}
return found
}
def buildFile = getBuildFile(new File(build.getWorkspace().getRemote()))
if(buildFile == null){
println("ERROR: could not find .ipa or .apk file in " + build.getWorkspace().getRemote())
}
// curl the build + metadata to TestFlight Upload API
def proc = """\
curl http://testflightapp.com/api/builds.json \
-F file="@${buildFile}" \
-F api_token=${apiToken} \
-F team_token=${teamToken} \
-F notes="<${testFlightNotes}" \
-F notify=True \
-F distribution_lists=${testFlightDistList}
"""
// log the request
println(proc)
def response = proc.execute().text
if(response == null || response == ""){
println("ERROR uploading to TestFlight")
return 1
}
// log the response
println(response)
return 0