Fix run_script method.

Existing code assumes the script sent by the user is terminated with a newline.
Appending magic string without '\n' before print() command results in a syntactically
incorrect Groovy code.
This patch ensures that '\n' is added between user's provided script and appended
magic string.

Change-Id: I39021f1058e7434d487efb4bc7aca18416b2c08e
This commit is contained in:
Richard Felkl 2018-07-10 13:44:27 +02:00
parent e5e7a097b1
commit 4e64f0f880

View File

@ -1299,8 +1299,8 @@ class Jenkins(object):
Plugin:maven-plugin, Plugin:pam-auth]' Plugin:maven-plugin, Plugin:pam-auth]'
''' '''
magic_str = ')]}.' magic_str = ')]}.'
print_magic_str = 'println()\nprint("{}")'.format(magic_str) print_magic_str = 'print("{}")'.format(magic_str)
data = {'script': script.encode('utf-8') + print_magic_str.encode('utf-8')} data = {'script': "{0}\n{1}".format(script, print_magic_str).encode('utf-8')}
if node: if node:
url = self._build_url(NODE_SCRIPT_TEXT, locals()) url = self._build_url(NODE_SCRIPT_TEXT, locals())
else: else: