Skip to content

Instantly share code, notes, and snippets.

@srgtuszy
Last active May 18, 2022 03:16
Show Gist options
  • Save srgtuszy/6371749 to your computer and use it in GitHub Desktop.
Save srgtuszy/6371749 to your computer and use it in GitHub Desktop.
Gradle task for uploading builds to TestFlight using HTTPBuilder
task uploadTf(dependsOn: assembleRelease) << {
def teamToken = '<TestFlight team token here>'
def apiToken = '<TestFlight api token here>'
def lists = '<TestFlight distribution lists here>'
def apk = file("build/apk/$project.name-release.apk")
def notes = new File(file('changelog.mdown')).getText("UTF-8")
def http = new HTTPBuilder('http://testflightapp.com')
println('Uploading build to TestFlight...')
http.request(POST, JSON) { req ->
uri.path = '/api/builds.json'
requestContentType = 'multipart/form-data'
MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE)
entity.addPart('distribution_lists', new StringBody(lists))
entity.addPart('team_token', new StringBody(teamToken))
entity.addPart('api_token', new StringBody(apiToken))
entity.addPart('notes', new StringBody(notes))
entity.addPart('file', new FileBody(apk))
req.setEntity(entity)
response.success = {resp, json ->
println("Upload successful!")
}
response.failure = {resp ->
println(resp)
throw new StopExecutionException("TestFlight upload failed! See server response above")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment