diff --git a/.gitignore b/.gitignore index d060983..5bdfbeb 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,7 @@ # Maven # /target/ + +# Intellij IDEA # +.idea/ +*.iml \ No newline at end of file diff --git a/src/main/java/de/jutzig/github/release/plugin/UploadMojo.java b/src/main/java/de/jutzig/github/release/plugin/UploadMojo.java index 270b0be..737809b 100644 --- a/src/main/java/de/jutzig/github/release/plugin/UploadMojo.java +++ b/src/main/java/de/jutzig/github/release/plugin/UploadMojo.java @@ -145,6 +145,20 @@ public class UploadMojo extends AbstractMojo implements Contextualizable{ */ private Boolean prerelease; + /** + * Number of attempts to upload, defaults to 5. + * + * @parameter default-value=5 + */ + private int retryUploadCount = 5; + + /** + * Retry timeout between failing uploads, defaults to 10 seconds. + * + * @parameter default-value=10000 + */ + private int retryUploadTimeout = 10000; + public void execute() throws MojoExecutionException { if(releaseName==null) releaseName = tag; @@ -214,8 +228,28 @@ private void uploadAsset(GHRelease release, File asset) throws IOException { } getLog().info(" Upload asset"); - // for some reason this doesn't work currently - release.uploadAsset(asset, "application/zip"); + int attempt = 0; + do { + try { + release.uploadAsset(asset, "application/zip"); + break; + } catch (IOException e) { + if (attempt < retryUploadCount) { + getLog().warn(String.format("Asset %s failed to upload, retrying in %d seconds (%d/%d)." + , asset.getName() + , retryUploadTimeout / 1000 + , attempt + 1 + , retryUploadCount)); + try { + Thread.sleep(retryUploadTimeout); + } catch (InterruptedException e1) { + throw new IOException(e1); + } + } else { + throw e; + } + } + } while (attempt++ <= retryUploadTimeout); } private void uploadAssets(GHRelease release, FileSet fileset) throws IOException {