diff --git a/src/main/java/org/jvnet/hudson/plugins/m2release/M2ReleaseAction.java b/src/main/java/org/jvnet/hudson/plugins/m2release/M2ReleaseAction.java index 590807d1..cb8d9d21 100644 --- a/src/main/java/org/jvnet/hudson/plugins/m2release/M2ReleaseAction.java +++ b/src/main/java/org/jvnet/hudson/plugins/m2release/M2ReleaseAction.java @@ -71,12 +71,14 @@ public class M2ReleaseAction implements PermalinkProjectAction { private boolean selectCustomScmTag = false; private boolean selectAppendHudsonUsername; private boolean selectScmCredentials; + private boolean selectAppendJenkinsBuildNumber; - public M2ReleaseAction(MavenModuleSet project, boolean selectCustomScmCommentPrefix, boolean selectAppendHudsonUsername, boolean selectScmCredentials) { + public M2ReleaseAction(MavenModuleSet project, boolean selectCustomScmCommentPrefix, boolean selectAppendHudsonUsername, boolean selectScmCredentials, boolean selectAppendJenkinsBuildNumber) { this.project = project; this.selectCustomScmCommentPrefix = selectCustomScmCommentPrefix; this.selectAppendHudsonUsername = selectAppendHudsonUsername; this.selectScmCredentials = selectScmCredentials; + this.selectAppendJenkinsBuildNumber = selectAppendJenkinsBuildNumber; if (getRootModule() == null) { // if the root module is not available, the user should be informed // about the stuff we are not able to compute @@ -137,6 +139,14 @@ public boolean isSelectCustomScmTag() { return selectCustomScmTag; } + public boolean isSelectAppendJenkinsBuildNumber() { + return selectAppendJenkinsBuildNumber; + } + + public void setSelectAppendJenkinsBuildNumber(boolean selectAppendJenkinsBuildNumber) { + this.selectAppendJenkinsBuildNumber = selectAppendJenkinsBuildNumber; + } + public Collection getModules() { return project.getModules(); } @@ -207,6 +217,7 @@ public void doSubmit(StaplerRequest req, StaplerResponse resp) throws IOExceptio // good old http... Map httpParams = req.getParameterMap(); + final boolean appendJenkinsBuildNumber = httpParams.containsKey("appendJenkinsBuildNumber"); //$NON-NLS-1$ final boolean closeNexusStage = httpParams.containsKey("closeNexusStage"); //$NON-NLS-1$ final String repoDescription = closeNexusStage ? getString("repoDescription", httpParams) : ""; //$NON-NLS-1$ final boolean specifyScmCredentials = httpParams.containsKey("specifyScmCredentials"); //$NON-NLS-1$ @@ -282,6 +293,7 @@ public void doSubmit(StaplerRequest req, StaplerResponse resp) throws IOExceptio arguments.setScmCommentPrefix(scmCommentPrefix); arguments.setAppendHusonUserName(appendHusonUserName); arguments.setHudsonUserName(Hudson.getAuthentication().getName()); + arguments.setAppendJenkinsBuildNumber(appendJenkinsBuildNumber); if (project.scheduleBuild(0, new ReleaseCause(), parameters, arguments)) { diff --git a/src/main/java/org/jvnet/hudson/plugins/m2release/M2ReleaseArgumentsAction.java b/src/main/java/org/jvnet/hudson/plugins/m2release/M2ReleaseArgumentsAction.java index b5aeccde..dfeae8ae 100644 --- a/src/main/java/org/jvnet/hudson/plugins/m2release/M2ReleaseArgumentsAction.java +++ b/src/main/java/org/jvnet/hudson/plugins/m2release/M2ReleaseArgumentsAction.java @@ -62,6 +62,7 @@ public class M2ReleaseArgumentsAction implements Action { private transient boolean appendHusonUserName; private transient String hudsonUserName; + private transient boolean appendJenkinsBuildNumber; public M2ReleaseArgumentsAction() { super(); @@ -186,4 +187,12 @@ public void setHudsonUserName(String hudsonUserName) { this.hudsonUserName = hudsonUserName; } + public boolean isAppendJenkinsBuildNumber() { + return appendJenkinsBuildNumber; + } + + public void setAppendJenkinsBuildNumber(boolean appendJenkinsBuildNumber) { + this.appendJenkinsBuildNumber = appendJenkinsBuildNumber; + } + } diff --git a/src/main/java/org/jvnet/hudson/plugins/m2release/M2ReleaseBuildWrapper.java b/src/main/java/org/jvnet/hudson/plugins/m2release/M2ReleaseBuildWrapper.java index bd64d13e..c93eb338 100644 --- a/src/main/java/org/jvnet/hudson/plugins/m2release/M2ReleaseBuildWrapper.java +++ b/src/main/java/org/jvnet/hudson/plugins/m2release/M2ReleaseBuildWrapper.java @@ -99,11 +99,12 @@ public class M2ReleaseBuildWrapper extends BuildWrapper { public boolean selectCustomScmCommentPrefix = DescriptorImpl.DEFAULT_SELECT_CUSTOM_SCM_COMMENT_PREFIX; public boolean selectAppendHudsonUsername = DescriptorImpl.DEFAULT_SELECT_APPEND_HUDSON_USERNAME; public boolean selectScmCredentials = DescriptorImpl.DEFAULT_SELECT_SCM_CREDENTIALS; + public boolean selectAppendJenkinsBuildNumber = DescriptorImpl.DEFAULT_SELECT_APPEND_JENKINS_BUILD_NUMBER; public int numberOfReleaseBuildsToKeep = DescriptorImpl.DEFAULT_NUMBER_OF_RELEASE_BUILDS_TO_KEEP; @DataBoundConstructor - public M2ReleaseBuildWrapper(String releaseGoals, String dryRunGoals, boolean selectCustomScmCommentPrefix, boolean selectAppendHudsonUsername, boolean selectScmCredentials, String releaseEnvVar, String scmUserEnvVar, String scmPasswordEnvVar, int numberOfReleaseBuildsToKeep) { + public M2ReleaseBuildWrapper(String releaseGoals, String dryRunGoals, boolean selectCustomScmCommentPrefix, boolean selectAppendHudsonUsername, boolean selectScmCredentials, String releaseEnvVar, String scmUserEnvVar, String scmPasswordEnvVar, int numberOfReleaseBuildsToKeep, boolean selectAppendJenkinsBuildNumber) { super(); this.releaseGoals = releaseGoals; this.dryRunGoals = dryRunGoals; @@ -114,6 +115,7 @@ public M2ReleaseBuildWrapper(String releaseGoals, String dryRunGoals, boolean se this.scmUserEnvVar = scmUserEnvVar; this.scmPasswordEnvVar = scmPasswordEnvVar; this.numberOfReleaseBuildsToKeep = numberOfReleaseBuildsToKeep; + this.selectAppendJenkinsBuildNumber = selectAppendJenkinsBuildNumber; } @@ -141,7 +143,11 @@ public void buildEnvVars(Map env) { StringBuilder buildGoals = new StringBuilder(); buildGoals.append("-DdevelopmentVersion=").append(args.getDevelopmentVersion()).append(' '); - buildGoals.append("-DreleaseVersion=").append(args.getReleaseVersion()).append(' '); + buildGoals.append("-DreleaseVersion=").append(args.getReleaseVersion()); + if (args.isAppendJenkinsBuildNumber()) { + buildGoals.append('-').append(build.getNumber()); + } + buildGoals.append(' '); if (args.getScmUsername() != null) { buildGoals.append("-Dusername=").append(args.getScmUsername()).append(' '); @@ -312,6 +318,14 @@ public void setNumberOfReleaseBuildsToKeep(int numberOfReleaseBuildsToKeep) { this.numberOfReleaseBuildsToKeep = numberOfReleaseBuildsToKeep; } + public boolean isSelectAppendJenkinsBuildNumber() { + return selectAppendJenkinsBuildNumber; + } + + public void setSelectAppendJenkinsBuildNumber(boolean selectAppendJenkinsBuildNumber) { + this.selectAppendJenkinsBuildNumber = selectAppendJenkinsBuildNumber; + } + private MavenModuleSet getModuleSet(AbstractBuild build) { if (build instanceof MavenBuild) { MavenBuild m2Build = (MavenBuild) build; @@ -377,7 +391,7 @@ private Object readResolve() { @Override public Action getProjectAction(@SuppressWarnings("rawtypes") AbstractProject job) { - return new M2ReleaseAction((MavenModuleSet) job, selectCustomScmCommentPrefix, selectAppendHudsonUsername, selectScmCredentials); + return new M2ReleaseAction((MavenModuleSet) job, selectCustomScmCommentPrefix, selectAppendHudsonUsername, selectScmCredentials, selectAppendJenkinsBuildNumber); } /** @@ -469,6 +483,7 @@ public static class DescriptorImpl extends BuildWrapperDescriptor { public static final boolean DEFAULT_SELECT_CUSTOM_SCM_COMMENT_PREFIX = false; public static final boolean DEFAULT_SELECT_APPEND_HUDSON_USERNAME = false; public static final boolean DEFAULT_SELECT_SCM_CREDENTIALS = false; + public static final boolean DEFAULT_SELECT_APPEND_JENKINS_BUILD_NUMBER = false; public static final int DEFAULT_NUMBER_OF_RELEASE_BUILDS_TO_KEEP = 1; diff --git a/src/main/resources/org/jvnet/hudson/plugins/m2release/M2ReleaseAction/index.jelly b/src/main/resources/org/jvnet/hudson/plugins/m2release/M2ReleaseAction/index.jelly index 9d0f2e08..604bfd0b 100644 --- a/src/main/resources/org/jvnet/hudson/plugins/m2release/M2ReleaseAction/index.jelly +++ b/src/main/resources/org/jvnet/hudson/plugins/m2release/M2ReleaseAction/index.jelly @@ -14,6 +14,9 @@ + + + diff --git a/src/main/resources/org/jvnet/hudson/plugins/m2release/M2ReleaseBuildWrapper/config.jelly b/src/main/resources/org/jvnet/hudson/plugins/m2release/M2ReleaseBuildWrapper/config.jelly index 6a4b6724..08207edc 100644 --- a/src/main/resources/org/jvnet/hudson/plugins/m2release/M2ReleaseBuildWrapper/config.jelly +++ b/src/main/resources/org/jvnet/hudson/plugins/m2release/M2ReleaseBuildWrapper/config.jelly @@ -26,6 +26,10 @@ + + + + diff --git a/src/main/webapp/help-actionRelease-appendJenkinsBuildNumber.html b/src/main/webapp/help-actionRelease-appendJenkinsBuildNumber.html new file mode 100644 index 00000000..bf290677 --- /dev/null +++ b/src/main/webapp/help-actionRelease-appendJenkinsBuildNumber.html @@ -0,0 +1,3 @@ +
+ Enable this option to append the Jenkins Build Number to the Release Version Number. +
\ No newline at end of file diff --git a/src/main/webapp/help-projectConfig-selectAppendJenkinsBuildNumber.html b/src/main/webapp/help-projectConfig-selectAppendJenkinsBuildNumber.html new file mode 100644 index 00000000..d1dbb2c8 --- /dev/null +++ b/src/main/webapp/help-projectConfig-selectAppendJenkinsBuildNumber.html @@ -0,0 +1,3 @@ +
+ Enable this to have the "Append Jenkins Build Number" option (appends the build number to the release version) selected by default in the "Perform Maven Release" view. +
\ No newline at end of file diff --git a/src/test/java/org/jvnet/hudson/plugins/m2release/M2ReleaseActionTest.java b/src/test/java/org/jvnet/hudson/plugins/m2release/M2ReleaseActionTest.java index d9f17722..8740779e 100644 --- a/src/test/java/org/jvnet/hudson/plugins/m2release/M2ReleaseActionTest.java +++ b/src/test/java/org/jvnet/hudson/plugins/m2release/M2ReleaseActionTest.java @@ -60,7 +60,8 @@ public MavenModuleSetBuild runPepareRelease_dryRun(String projectZip, String unp m.setGoals("dummygoal"); // build would fail with this goal final M2ReleaseBuildWrapper wrapper = new M2ReleaseBuildWrapper(DescriptorImpl.DEFAULT_RELEASE_GOALS, DescriptorImpl.DEFAULT_DRYRUN_GOALS, false, - false, false, "ENV", "USERENV", "PWDENV", DescriptorImpl.DEFAULT_NUMBER_OF_RELEASE_BUILDS_TO_KEEP); + false, false, "ENV", "USERENV", "PWDENV", DescriptorImpl.DEFAULT_NUMBER_OF_RELEASE_BUILDS_TO_KEEP, + DescriptorImpl.DEFAULT_SELECT_APPEND_JENKINS_BUILD_NUMBER); M2ReleaseArgumentsAction args = new M2ReleaseArgumentsAction(); args.setDevelopmentVersion("1.0-SNAPSHOT"); args.setReleaseVersion("0.9"); diff --git a/src/test/java/org/jvnet/hudson/plugins/m2release/M2ReleaseBadgeActionTest.java b/src/test/java/org/jvnet/hudson/plugins/m2release/M2ReleaseBadgeActionTest.java index ba309dd5..dc5c5a94 100644 --- a/src/test/java/org/jvnet/hudson/plugins/m2release/M2ReleaseBadgeActionTest.java +++ b/src/test/java/org/jvnet/hudson/plugins/m2release/M2ReleaseBadgeActionTest.java @@ -94,7 +94,8 @@ private MavenModuleSetBuild runDryRunRelease(String projectZip, String unpackedP final M2ReleaseBuildWrapper wrapper = new M2ReleaseBuildWrapper(DescriptorImpl.DEFAULT_RELEASE_GOALS, DescriptorImpl.DEFAULT_DRYRUN_GOALS, false, false, false, "ENV", "USERENV", "PWDENV", - DescriptorImpl.DEFAULT_NUMBER_OF_RELEASE_BUILDS_TO_KEEP); + DescriptorImpl.DEFAULT_NUMBER_OF_RELEASE_BUILDS_TO_KEEP, + DescriptorImpl.DEFAULT_SELECT_APPEND_JENKINS_BUILD_NUMBER); M2ReleaseArgumentsAction args = new M2ReleaseArgumentsAction(); args.setReleaseVersion("1.0"); args.setDevelopmentVersion("1.1-SNAPSHOT");