Skip to content

Commit

Permalink
[JENKINS-42284] Add an option to prevent chcp from being executed
Browse files Browse the repository at this point in the history
Since some users encountered an error when the plugin was running chcp
command, this commit add a checkbox on the msbuild step allowing to
prevent the plugin from running it.
  • Loading branch information
marshall777 committed Oct 7, 2017
1 parent 2ab437c commit 78cf158
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/main/java/hudson/plugins/msbuild/MsBuildBuilder.java
Expand Up @@ -52,6 +52,7 @@ public class MsBuildBuilder extends Builder {
private transient boolean continueOnBuilFailure;
private final boolean continueOnBuildFailure;
private final boolean unstableIfWarnings;
private final boolean doNotUseChcpCommand;

/**
* When this builder is created in the project configuration step,
Expand All @@ -63,16 +64,18 @@ public class MsBuildBuilder extends Builder {
* @param buildVariablesAsProperties If true, pass build variables as properties to MSBuild
* @param continueOnBuildFailure If true, job will continue dispite of MSBuild build failure
* @param unstableIfWarnings If true, job will be unstable if there are warnings
* @param doNotUseChcpCommand If true, job will not use chcp command before running msbuild
*/
@DataBoundConstructor
@SuppressWarnings("unused")
public MsBuildBuilder(String msBuildName, String msBuildFile, String cmdLineArgs, boolean buildVariablesAsProperties, boolean continueOnBuildFailure, boolean unstableIfWarnings) {
public MsBuildBuilder(String msBuildName, String msBuildFile, String cmdLineArgs, boolean buildVariablesAsProperties, boolean continueOnBuildFailure, boolean unstableIfWarnings, boolean doNotUseChcpCommand) {
this.msBuildName = msBuildName;
this.msBuildFile = msBuildFile;
this.cmdLineArgs = cmdLineArgs;
this.buildVariablesAsProperties = buildVariablesAsProperties;
this.continueOnBuildFailure = continueOnBuildFailure;
this.unstableIfWarnings = unstableIfWarnings;
this.doNotUseChcpCommand = doNotUseChcpCommand;
}

@SuppressWarnings("unused")
Expand Down Expand Up @@ -104,7 +107,12 @@ public boolean getContinueOnBuildFailure() {
public boolean getUnstableIfWarnings() {
return unstableIfWarnings;
}


@SuppressWarnings("unused")
public boolean getDoNotUseChcpCommand() {
return doNotUseChcpCommand;
}

public MsBuildInstallation getMsBuild() {
DescriptorImpl descriptor = (DescriptorImpl) getDescriptor();
for (MsBuildInstallation i : descriptor.getInstallations()) {
Expand Down Expand Up @@ -193,13 +201,19 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
}

if (!launcher.isUnix()) {
final int cpi = getCodePageIdentifier(build.getCharset());
if(cpi != 0)
args.prepend("cmd.exe", "/C", "\"", "chcp", String.valueOf(cpi), "&&");
else
args.prepend("cmd.exe", "/C", "\"");
if (!doNotUseChcpCommand) {
final int cpi = getCodePageIdentifier(build.getCharset());
if(cpi != 0) {
args.prepend("chcp", String.valueOf(cpi), "&&");
}
}

args.prepend("cmd.exe", "/C", "\"");
args.add("\"", "&&", "exit", "%%ERRORLEVEL%%");
}
else {
listener.fatalError("Unable to use this plugin on this kind of operation system");
}

try {
listener.getLogger().println(String.format("Executing the command %s from %s", args.toStringWithQuote(), pwd));
Expand Down
Expand Up @@ -41,6 +41,10 @@ THE SOFTWARE.
<f:checkbox name="msBuildBuilder.buildVariablesAsProperties" value="${instance.buildVariablesAsProperties}"
checked="${instance.buildVariablesAsProperties}" default="false"/>
</f:entry>
<f:entry title="${%Do not use chcp command}" field="doNotUseChcpCommand">
<f:checkbox name="msBuildBuilder.doNotUseChcpCommand" value="${instance.doNotUseChcpCommand}"
checked="${instance.doNotUseChcpCommand}" default="false"/>
</f:entry>
<f:advanced>
<f:entry title="${%Continue Job on build Failure}" field="continueOnBuildFailure">
<f:checkbox name="msBuildBuilder.continueOnBuildFailure" value="${instance.continueOnBuildFailure}"
Expand Down

0 comments on commit 78cf158

Please sign in to comment.