Skip to content

Instantly share code, notes, and snippets.

@hypest
Last active December 22, 2018 22:12
Show Gist options
  • Save hypest/f526fe0775dedce0ce0133f1400d22a4 to your computer and use it in GitHub Desktop.
Save hypest/f526fe0775dedce0ce0133f1400d22a4 to your computer and use it in GitHub Desktop.
Manually wait for JitPack to make an artifact available
def waitJitpack(group, module, hash) {
preBuild.dependsOn(tasks.create(name: "waitJitpack-${module}-${hash}") { thisTask ->
def url = "https://jitpack.io/${group.replace('.', '/')}/${module}/${hash}/${module}-${hash}.pom"
def backoffLimit = 7
for (def backoffCount : (0..backoffLimit)) {
def connection = new URL(url).openConnection() as HttpURLConnection
def timeout = (2**backoffCount) * 5 * 1000; // exponential timeout
connection.setConnectTimeout(timeout)
connection.setReadTimeout(timeout)
connection.setRequestMethod("HEAD");
connection.setInstanceFollowRedirects(true)
try {
def responseCode = connection.getResponseCode();
if (responseCode >= 200 && responseCode <= 299) {
// success. Just bail
return
} else {
def responseMessage = connection.getResponseCode();
throw new RuntimeException("Failed reaching Jitpack for ${group}:${module}:${hash}: ${responseMessage}")
}
} catch (SocketTimeoutException ignored) {
if (backoffCount == backoffLimit) {
throw new Exception("Exhausted waiting for Jipack on ${group}:${module}:${hash}")
}
println "Retrying JitPack ${backoffCount+1}/${backoffLimit+1} for ${group}:${module}:${hash}"
} catch (Exception e) {
throw e
}
}
})
return "${group}:${module}:${hash}"
}
ext {
waitJitpack = this.&waitJitpack
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment