Hello Gregory,
I have the exact same issue with jenkins 1.532.1 & gradle-plugin 1.23. I need to create a job where one of the parameters is a text one (in order to specify release notes).
The text parameter has the following value:
When the Gradle builder runs, it fails with the following error which shows that Gradle is confused by the multi-line argument:
I did some local tests and found that (on Mac OS), the command line should be changed from
to
Here's the command output when run outside jenkins:
I tried changing the gradle plugin to have the plugin generate the command line above. For that, I updated the method hudson.plugins.gradle.Gradle.fixParameters(Map<String, String>) to handle multi-line parameter values.
Initial implementation:
private Map<String, String> fixParameters(Map<String, String> parmas) {
Map<String, String> result = new HashMap<String, String>();
for (Map.Entry<String, String> entry : parmas.entrySet()) {
String value = entry.getValue();
if (isValue2Escape(value)) {
result.put(entry.getKey(), "\"" + value + "\"");
} else {
result.put(entry.getKey(), value);
}
}
return result;
}
Implementation I tested:
private Map<String, String> fixParameters(Map<String, String> parmas) {
Map<String, String> result = new HashMap<String, String>();
final String lineSeparator = System.getProperty("line.separator");
for (Map.Entry<String, String> entry : parmas.entrySet()) {
final String value = entry.getValue();
if (!value.contains(lineSeparator)) {
if (isValue2Escape(value)) {
result.put(entry.getKey(), "\"" + value + "\"");
} else {
result.put(entry.getKey(), value);
}
} else {
final StringBuilder buffer = new StringBuilder(256);
for (String string: value.split(lineSeparator)) {
if (isValue2Escape(string)) {
buffer.append("\"" + string + "\"");
} else {
buffer.append(string);
}
buffer.append("\\").append(lineSeparator);
}
result.put(entry.getKey(), buffer.toString());
}
}
return result;
}
With this second implementation, the plugin properly escapes line feeds (see below) but the jenkins job still fails with the same error:
The topic of handling multi-line parameters seems to be a tricky one (because very OS-specific).
Any idea what could be wrong with the above ? Is the method hudson.plugins.gradle.Gradle.fixParameters(Map<String, String>) the one to be changed for fixing this issue ?
I also found some code in jenkins itself (method hudson.util.ArgumentListBuilder.addKeyValuePair(String, String, String, boolean)) that deals with those system properties but I'm pretty reluctant to change such a low-level method.
Thanks for your insight
Hello Gregory,
I have the exact same issue with jenkins 1.532.1 & gradle-plugin 1.23. I need to create a job where one of the parameters is a text one (in order to specify release notes).
The text parameter has the following value:
When the Gradle builder runs, it fails with the following error which shows that Gradle is confused by the multi-line argument:
I did some local tests and found that (on Mac OS), the command line should be changed from
to
Here's the command output when run outside jenkins:
I tried changing the gradle plugin to have the plugin generate the command line above. For that, I updated the method hudson.plugins.gradle.Gradle.fixParameters(Map<String, String>) to handle multi-line parameter values.
Initial implementation:
Implementation I tested:
With this second implementation, the plugin properly escapes line feeds (see below) but the jenkins job still fails with the same error:
The topic of handling multi-line parameters seems to be a tricky one (because very OS-specific).
Any idea what could be wrong with the above ? Is the method hudson.plugins.gradle.Gradle.fixParameters(Map<String, String>) the one to be changed for fixing this issue ?
I also found some code in jenkins itself (method hudson.util.ArgumentListBuilder.addKeyValuePair(String, String, String, boolean)) that deals with those system properties but I'm pretty reluctant to change such a low-level method.
Thanks for your insight