Skip to content

Instantly share code, notes, and snippets.

@antionio
Created February 16, 2017 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antionio/9423a78f9b527d17bb80f5c76b6d0807 to your computer and use it in GitHub Desktop.
Save antionio/9423a78f9b527d17bb80f5c76b6d0807 to your computer and use it in GitHub Desktop.
Groovy script to fetch latest successful build data files from Unity Cloud Build and unzip to a folder
// some stuff to get jenkins log output
def out
def config = new HashMap()
def bindings = getBinding()
config.putAll(bindings.getVariables())
out = config['out']
// unity cloud build api key
def apiKey = "YOUR_UNITY_CLOUD_BUILD_API_KEY"
// unity cloud build api url to fetch build information
def url = "https://build-api.cloud.unity3d.com/api/v1/orgs/your-organization/projects/your-project/buildtargets/default-windows-desktop-32-bit/builds?buildStatus=success&platform=standalonewindows".toURL()
out.println "Fetching json info about build"
// fetch info with basic auth & apiKey
def jsonText = url.getText(requestProperties: [Authorization: 'Basic ' + apiKey])
// slurp the json and find the download url
def jsonSlurper = new groovy.json.JsonSlurper()
def json = jsonSlurper.parseText(jsonText)
def downloadUrl = json.first()['links']['download_primary']['href']
out.println "Downloading file from: " + downloadUrl
def build = Thread.currentThread().executable
def file = new FileOutputStream(build.workspace.toString() + "/your-project-latest-build-win32.zip")
def output = new BufferedOutputStream(file)
output << new URL(downloadUrl).openStream()
output.close()
out.println("File download complete. Unzipping.")
def ant = new AntBuilder()
def targetFile = new File(build.workspace.toString() + "/your-project-latest-build-win32.zip")
def destFile = new File(build.workspace.toString() + "/content/win32")
if (!destFile.exists()) {
destFile.mkdir()
}
ant.unzip(src:targetFile,dest:destFile,overwrite:"true")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment