Fix run_scripts() API
Resolve regression caused by I5369a0d35be4bf8b3b197a51e60aba21b5742cc7 preventing run_scripts() from successfully running against the remote Jenkins instance. Switching data to a dictionary and passing the script string without quote() appears to allow the script to successfully run. Add a magic string ')]}.' as an indicator of if the groovy script successfully passed or failed. In theory if the groovy script failed perhaps due to syntax error or some other reason the magic string will not be printed and we can assume failure. Change-Id: Ibaffb768ea82c76b44ec5a6cccde8563afe1783f Signed-off-by: Thanh Ha <zxiiro@linux.com>
This commit is contained in:
parent
3d59064908
commit
7ffb27c7d5
|
@ -1294,10 +1294,16 @@ class Jenkins(object):
|
|||
Plugin:mailer, Plugin:jquery, Plugin:antisamy-markup-formatter,
|
||||
Plugin:maven-plugin, Plugin:pam-auth]'
|
||||
'''
|
||||
return self.jenkins_open(
|
||||
requests.Request(
|
||||
'POST', self._build_url(SCRIPT_TEXT),
|
||||
data="script=".encode('utf-8') + quote(script).encode('utf-8')))
|
||||
magic_str = ')]}.'
|
||||
print_magic_str = 'println()\nprint("{}")'.format(magic_str)
|
||||
groovy = {'script': script.encode('utf-8') + print_magic_str.encode('utf-8')}
|
||||
result = self.jenkins_open(requests.Request(
|
||||
'POST', self._build_url(SCRIPT_TEXT), data=groovy))
|
||||
|
||||
if not result.endswith(magic_str):
|
||||
raise JenkinsException(result)
|
||||
|
||||
return result[:result.rfind('\n')]
|
||||
|
||||
def install_plugin(self, name, include_dependencies=True):
|
||||
'''Install a plugin and its dependencies from the Jenkins public
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
from mock import patch
|
||||
from six.moves.urllib.parse import quote
|
||||
|
||||
import jenkins
|
||||
from tests.base import JenkinsTestBase
|
||||
|
@ -23,7 +22,6 @@ class JenkinsScriptTest(JenkinsTestBase):
|
|||
self.assertEqual(
|
||||
jenkins_mock.call_args[0][0].url,
|
||||
self.make_url('scriptText'))
|
||||
self.assertIn(quote('&&'), jenkins_mock.call_args[0][0].data.decode('utf8'))
|
||||
self._check_requests(jenkins_mock.call_args_list)
|
||||
|
||||
@patch.object(jenkins.Jenkins, 'jenkins_open')
|
||||
|
|
Loading…
Reference in New Issue