diff --git a/pom.xml b/pom.xml index 2926d1a..ff0b1e4 100644 --- a/pom.xml +++ b/pom.xml @@ -90,13 +90,14 @@ - ${plugin.name}-${version} + ${plugin.name}-${project.version} src/main/resources/views ${resource.directory} + true diff --git a/src/main/java/in/ashwanthkumar/gocd/github/GitHubPRBuildPlugin.java b/src/main/java/in/ashwanthkumar/gocd/github/GitHubPRBuildPlugin.java index c99d7ae..45fbb8f 100644 --- a/src/main/java/in/ashwanthkumar/gocd/github/GitHubPRBuildPlugin.java +++ b/src/main/java/in/ashwanthkumar/gocd/github/GitHubPRBuildPlugin.java @@ -40,6 +40,8 @@ public class GitHubPRBuildPlugin implements GoPlugin { public static final String REQUEST_LATEST_REVISION = "latest-revision"; public static final String REQUEST_LATEST_REVISIONS_SINCE = "latest-revisions-since"; public static final String REQUEST_CHECKOUT = "checkout"; + + public static final int CHECKOUT_ATTEMPTS = 3; public static final String BRANCH_TO_REVISION_MAP = "BRANCH_TO_REVISION_MAP"; private static final String DATE_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"; @@ -249,22 +251,27 @@ private GoPluginApiResponse handleCheckout(GoPluginApiRequest goPluginApiRequest String destinationFolder = (String) requestBodyMap.get("destination-folder"); Map revisionMap = (Map) requestBodyMap.get("revision"); String revision = (String) revisionMap.get("revision"); - LOGGER.info(String.format("destination: %s. commit: %s", destinationFolder, revision)); + for (int attempt = 0; attempt < CHECKOUT_ATTEMPTS; attempt++) { + LOGGER.info(String.format("destination: %s. commit: %s, attempt: %s out of %s", destinationFolder, revision, attempt, CHECKOUT_ATTEMPTS)); - try { + try { GitHelper git = HelperFactory.gitCmd(gitConfig, new File(destinationFolder)); - git.cloneOrFetch(provider.getRefSpec()); - git.resetHard(revision); + git.cloneOrFetch(provider.getRefSpec()); + git.resetHard(revision); - Map response = new HashMap(); - response.put("status", "success"); - response.put("messages", Arrays.asList(String.format("Checked out to revision %s", revision))); + Map response = new HashMap(); + response.put("status", "success"); + response.put("messages", Arrays.asList(String.format("Checked out to revision %s", revision))); - return renderJSON(SUCCESS_RESPONSE_CODE, response); - } catch (Throwable t) { - LOGGER.warn("checkout: ", t); - return renderJSON(INTERNAL_ERROR_RESPONSE_CODE, t.getMessage()); + return renderJSON(SUCCESS_RESPONSE_CODE, response); + } catch (Throwable t) { + LOGGER.warn(String.format("Attempt %s out of %s, checkout: ", attempt, CHECKOUT_ATTEMPTS), t); + if (attempt >= CHECKOUT_ATTEMPTS) { + return renderJSON(INTERNAL_ERROR_RESPONSE_CODE, t.getMessage()); + } + } } + return renderJSON(INTERNAL_ERROR_RESPONSE_CODE, "Checkout failed"); } GitConfig getGitConfig(Map configuration) { diff --git a/src/main/resources/gerrit/plugin.xml b/src/main/resources/gerrit/plugin.xml index 46333e2..ec3eafd 100644 --- a/src/main/resources/gerrit/plugin.xml +++ b/src/main/resources/gerrit/plugin.xml @@ -2,7 +2,7 @@ Gerrit Change Set plugin - 1.2.2 + ${project.version} 15.1.0 Provides ability to do change set builds for Gerrit repository diff --git a/src/main/resources/git/plugin.xml b/src/main/resources/git/plugin.xml index d40497e..254276c 100644 --- a/src/main/resources/git/plugin.xml +++ b/src/main/resources/git/plugin.xml @@ -2,7 +2,7 @@ Git Feature Branch plugin - 1.2.2 + ${project.version} 15.1.0 Provides ability to do feature branch builds for Git repository diff --git a/src/main/resources/github/plugin.xml b/src/main/resources/github/plugin.xml index 59948d5..fca3716 100644 --- a/src/main/resources/github/plugin.xml +++ b/src/main/resources/github/plugin.xml @@ -2,7 +2,7 @@ Github Pull Requests Builder - 1.2.2 + ${project.version} 15.1.0 Plugin that polls a GitHub repository for pull requests and triggers a build for each of them diff --git a/src/main/resources/stash/plugin.xml b/src/main/resources/stash/plugin.xml index 13dc31a..1c1c487 100644 --- a/src/main/resources/stash/plugin.xml +++ b/src/main/resources/stash/plugin.xml @@ -2,7 +2,7 @@ Stash Pull Requests Builder - 1.2.2 + ${project.version} 15.1.0 Plugin that polls a Stash repository for pull requests and triggers a build for each of them