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:

- Dummy release notes
- Dummy release notes
- Dummy release notes
- Dummy release notes
- Dummy release notes

When the Gradle builder runs, it fails with the following error which shows that Gradle is confused by the multi-line argument:

Started by user anonymous
Building in workspace /Users/francois_ritaly/git/gradle-plugin/work/jobs/TEST/workspace
[Gradle] - Launching build.
[workspace] $ gradle "-DRELEASE_NOTES=- Dummy release notes
- Dummy release notes
- Dummy release notes
- Dummy release notes
- Dummy release notes
- Dummy release notes" clean tasks
Projects loaded

FAILURE: Could not determine which tasks to execute.

* What went wrong:
Task '-DRELEASE_NOTES=- Dummy release notes
- Dummy release notes
- Dummy release notes
- Dummy release notes
- Dummy release notes
- Dummy release notes' not found in root project 'workspace'.

* Try:
Run gradle tasks to get a list of available tasks.

BUILD FAILED

Total time: 4.048 secs
Build step 'Invoke Gradle script' changed build result to FAILURE
Build step 'Invoke Gradle script' marked build as failure
Finished: FAILURE

I did some local tests and found that (on Mac OS), the command line should be changed from

gradle "-DRELEASE_NOTES=- Dummy release notes
- Dummy release notes
- Dummy release notes
- Dummy release notes
- Dummy release notes
- Dummy release notes" clean tasks

to

gradle "-DRELEASE_NOTES=- Dummy release notes \
- Dummy release notes \
- Dummy release notes \
- Dummy release notes \
- Dummy release notes \
- Dummy release notes" clean tasks

Here's the command output when run outside jenkins:

[15:59:39 francois_ritaly@fritaly-mac:~/releasable-project/trunk]$ gradle "-DRELEASE_NOTES=- Dummy release notes \
> - Dummy release notes \
> - Dummy release notes \
> - Dummy release notes \
> - Dummy release notes \
> - Dummy release notes" clean tasks
:clean UP-TO-DATE
:tasks
(log truncated)

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>();

        // TODO should this line separator depend on the launcher type (unix / windows) ?
        final String lineSeparator = System.getProperty("line.separator");

        for (Map.Entry<String, String> entry : parmas.entrySet()) {
            final String value = entry.getValue();

            if (!value.contains(lineSeparator)) {
            	// the initial implementation expected all values to be a single line (no line feed)
                if (isValue2Escape(value)) {
                    result.put(entry.getKey(), "\"" + value + "\"");
                } else {
                    result.put(entry.getKey(), value);
                }
            } else {
            	// the value contains line feeds, escape each line and the line feeds
            	final StringBuilder buffer = new StringBuilder(256);

            	for (String string: value.split(lineSeparator)) {
	                if (isValue2Escape(string)) {
	                	buffer.append("\"" + string + "\"");
	                } else {
	                	buffer.append(string);
	                }

	                // escape line feeds
	                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:

Started by user anonymous
Building in workspace /Users/francois_ritaly/git/gradle-plugin/work/jobs/TEST/workspace
[Gradle] - Launching build.
[workspace] $ gradle "-DRELEASE_NOTES=- Dummy release notes\
- Dummy release notes\
- Dummy release notes\
- Dummy release notes\
- Dummy release notes\
- Dummy release notes\
" clean tasks
Projects loaded
FAILURE: Could not determine which tasks to execute.

* What went wrong:
Task '-DRELEASE_NOTES=- Dummy release notes\
- Dummy release notes\
- Dummy release notes\
- Dummy release notes\
- Dummy release notes\
- Dummy release notes\
' not found in root project 'workspace'.

* Try:
Run gradle tasks to get a list of available tasks.

BUILD FAILED

Total time: 4.121 secs
Build step 'Invoke Gradle script' changed build result to FAILURE
Build step 'Invoke Gradle script' marked build as failure
Finished: FAILURE

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

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators.
For more information on JIRA, see: http://www.atlassian.com/software/jira

--
You received this message because you are subscribed to the Google Groups "Jenkins Issues" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-issues+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to