Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-7442] Change ArgumentListBuilder.toWindowsCommand() to…
… not escape %VAR%

type references by default (can now be done by passing "true" parameter).
This restores ability to use %VAR% references for ant build steps on windows.

Originally-Committed-As: c4590529f731ba30b5deb0961d73f76e35ab70ff
  • Loading branch information
alanharder committed Mar 17, 2011
1 parent dc57aad commit e344ba8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
46 changes: 44 additions & 2 deletions test/src/test/java/hudson/tasks/AntTest.java
Expand Up @@ -26,6 +26,7 @@
import com.gargoylesoftware.htmlunit.html.HtmlButton;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import hudson.Functions;
import hudson.matrix.Axis;
import hudson.matrix.AxisList;
import hudson.matrix.MatrixRun;
Expand All @@ -43,6 +44,7 @@
import hudson.tools.ToolProperty;
import hudson.tools.ToolPropertyDescriptor;
import hudson.util.DescribableList;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.ExtractResourceSCM;
import org.jvnet.hudson.test.HudsonTestCase;
import org.jvnet.hudson.test.SingleFileSCM;
Expand Down Expand Up @@ -145,8 +147,9 @@ public void testParameterExpansion() throws Exception {
assertTrue("Missing $BUILD_NUMBER: " + log, log.contains("vNUM=1"));
assertTrue("Missing $BUILD_ID: " + log, log.contains("vID=2")); // Assuming the year starts with 2!
assertTrue("Missing $JOB_NAME: " + log, log.contains(project.getName()));
// Odd build tag, but it's constructed with getParent().getName() and the parent is the matrix
// configuration, not the project.. if matrix build tag ever changes, update expected value here:
// Odd build tag, but it's constructed with getParent().getName() and the parent is the
// matrix configuration, not the project.. if matrix build tag ever changes, update
// expected value here:
assertTrue("Missing $BUILD_TAG: " + log, log.contains("vTAG=jenkins-AX=is-1"));
assertTrue("Missing $EXECUTOR_NUMBER: " + log, log.matches("(?s).*vEXEC=\\d.*"));
// $NODE_NAME is expected to be empty when running on master.. not checking.
Expand All @@ -161,4 +164,43 @@ public void testParameterExpansion() throws Exception {
assertTrue("Missing build parameter $FOO: " + log, log.contains("vFOO=bar"));
assertTrue("Missing matrix axis $AX: " + log, log.contains("vAX=is"));
}

public void testParameterExpansionByShell() throws Exception {
String antName = configureDefaultAnt().getName();
FreeStyleProject project = createFreeStyleProject();
project.setScm(new ExtractResourceSCM(getClass().getResource("ant-job.zip")));
String homeVar = Functions.isWindows() ? "%HOME%" : "$HOME";
project.addProperty(new ParametersDefinitionProperty(
new StringParameterDefinition("vFOO", homeVar, ""),
new StringParameterDefinition("vBAR", "Home sweet " + homeVar + ".", "")));
project.getBuildersList().add(new Ant("", antName, null, null,
"vHOME=" + homeVar + "\nvFOOHOME=Foo " + homeVar + "\n"));
FreeStyleBuild build = project.scheduleBuild2(0, new UserCause()).get();
assertBuildStatusSuccess(build);
String log = getLog(build);
if (!Functions.isWindows()) homeVar = "\\" + homeVar; // Regex escape for $
assertTrue("Missing simple HOME parameter: " + log,
log.matches("(?s).*vFOO=(?!" + homeVar + ").*"));
assertTrue("Missing HOME parameter with other text: " + log,
log.matches("(?s).*vBAR=Home sweet (?!" + homeVar + ")[^\\r\\n]*\\..*"));
assertTrue("Missing HOME ant property: " + log,
log.matches("(?s).*vHOME=(?!" + homeVar + ").*"));
assertTrue("Missing HOME ant property with other text: " + log,
log.matches("(?s).*vFOOHOME=Foo (?!" + homeVar + ").*"));
}

@Bug(7108)
public void testEscapeXmlInParameters() throws Exception {
String antName = configureDefaultAnt().getName();
FreeStyleProject project = createFreeStyleProject();
project.setScm(new ExtractResourceSCM(getClass().getResource("ant-job.zip")));
project.addProperty(new ParametersDefinitionProperty(
new StringParameterDefinition("vFOO", "<xml/>", "")));
project.getBuildersList().add(new Ant("", antName, null, null, "vBAR=<xml/>\n"));
FreeStyleBuild build = project.scheduleBuild2(0, new UserCause()).get();
assertBuildStatusSuccess(build);
String log = getLog(build);
assertTrue("Missing parameter: " + log, log.contains("vFOO=<xml/>"));
assertTrue("Missing ant property: " + log, log.contains("vBAR=<xml/>"));
}
}
5 changes: 3 additions & 2 deletions war/src/main/webapp/help/ant/ant-properties.html
Expand Up @@ -7,8 +7,9 @@
name2=$VAR2
</pre>
These are passed to Ant like <tt>"-Dname1=value1 -Dname2=value2"</tt>.
Always use <tt>$VAR</tt> style for parameter references (do not use %VAR% style,
even when build runs on Windows).
Always use <tt>$VAR</tt> style (even on Windows) for references to Jenkins-defined
environment variables. On Windows, <tt>%VAR%</tt> style references may be used
for environment variables that exist outside of Jenkins.
Backslashes are used for escaping, so use <tt>\\</tt> for a single backslash.
Double quotes (") should be avoided, as ant on *nix wraps parameters in quotes
quotes and runs them through <tt>eval</tt>, and Windows has its own issues
Expand Down

0 comments on commit e344ba8

Please sign in to comment.