Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JENKINS-24090 Re-implement "Append Jenkins Build Number" Option #24

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -137,6 +139,14 @@ public boolean isSelectCustomScmTag() {
return selectCustomScmTag;
}

public boolean isSelectAppendJenkinsBuildNumber() {
return selectAppendJenkinsBuildNumber;
}

public void setSelectAppendJenkinsBuildNumber(boolean selectAppendJenkinsBuildNumber) {
this.selectAppendJenkinsBuildNumber = selectAppendJenkinsBuildNumber;
}

public Collection<MavenModule> getModules() {
return project.getModules();
}
Expand Down Expand Up @@ -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$
Expand Down Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class M2ReleaseArgumentsAction implements Action {

private transient boolean appendHusonUserName;
private transient String hudsonUserName;
private transient boolean appendJenkinsBuildNumber;

public M2ReleaseArgumentsAction() {
super();
Expand Down Expand Up @@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -114,6 +115,7 @@ public M2ReleaseBuildWrapper(String releaseGoals, String dryRunGoals, boolean se
this.scmUserEnvVar = scmUserEnvVar;
this.scmPasswordEnvVar = scmPasswordEnvVar;
this.numberOfReleaseBuildsToKeep = numberOfReleaseBuildsToKeep;
this.selectAppendJenkinsBuildNumber = selectAppendJenkinsBuildNumber;
}


Expand Down Expand Up @@ -141,7 +143,11 @@ public void buildEnvVars(Map<String, String> 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(' ');
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
<f:entry title="Development version">
<f:textbox name="developmentVersion" value="${it.computeNextVersion()}" />
</f:entry>
<f:entry title="Append Jenkins Build Number" help="/plugin/m2release/help-actionRelease-appendJenkinsBuildNumber.html">
<f:checkbox name="appendJenkinsBuildNumber" checked="${it.selectAppendJenkinsBuildNumber}"/>
</f:entry>
<f:entry title="Dry run only?">
<f:checkbox name="isDryRun" checked="false"/>
</f:entry>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
</select>
</f:entry>

<f:entry title="Preselect 'Append Jenkins Build Number'" help="/plugin/m2release/help-projectConfig-selectAppendJenkinsBuildNumber.html">
<f:checkbox name="selectAppendJenkinsBuildNumber" checked="${h.defaulted(instance.selectAppendJenkinsBuildNumber,descriptor.DEFAULT_SELECT_APPEND_JENKINS_BUILD_NUMBER)}"/>
</f:entry>

<f:entry title="Preselect 'Specify custom SCM comment prefix'" help="/plugin/m2release/help-projectConfig-selectCustomScmCommentPrefix.html">
<f:checkbox name="selectCustomScmCommentPrefix" checked="${h.defaulted(instance.selectCustomScmCommentPrefix,descriptor.DEFAULT_SELECT_CUSTOM_SCM_COMMENT_PREFIX)}"/>
</f:entry>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div>
Enable this option to append the Jenkins Build Number to the Release Version Number.
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div>
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.
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down