Skip to content
Permalink
Browse files

[JENKINS-42284] Add an option to prevent chcp from being executed

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 78cf15892d8411edae8aded2ec13e9b12015c740
@@ -52,6 +52,7 @@
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,
@@ -63,16 +64,18 @@
* @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")
@@ -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()) {
@@ -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));
@@ -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}"

0 comments on commit 78cf158

Please sign in to comment.
You can’t perform that action at this time.