Merge "Adds support for multi-select build parameters"
This commit is contained in:
commit
abe6df6d1d
@ -1128,14 +1128,26 @@ class Jenkins(object):
|
||||
Authenticated setups may require configuring a token on the server
|
||||
side.
|
||||
|
||||
:param parameters: parameters for job, or None., ``dict``
|
||||
Use ``list of two membered tuples`` to supply parameters with multi
|
||||
select options.
|
||||
|
||||
:param parameters: parameters for job, or None., ``dict`` or
|
||||
``list of two membered tuples``
|
||||
:param token: (optional) token for building job, ``str``
|
||||
:returns: URL for building job
|
||||
'''
|
||||
folder_url, short_name = self._get_job_folder(name)
|
||||
if parameters:
|
||||
if token:
|
||||
parameters['token'] = token
|
||||
if isinstance(parameters, list):
|
||||
parameters.append(('token', token, ))
|
||||
elif isinstance(parameters, dict):
|
||||
parameters.update({'token': token})
|
||||
else:
|
||||
raise JenkinsException('build parameters can be a dictionary '
|
||||
'like {"param_key": "param_value", ...} '
|
||||
'or a list of two membered tuples '
|
||||
'like [("param_key", "param_value",), ...]')
|
||||
return (self._build_url(BUILD_WITH_PARAMS_JOB, locals()) +
|
||||
'?' + urlencode(parameters))
|
||||
elif token:
|
||||
|
@ -1,4 +1,6 @@
|
||||
import json
|
||||
|
||||
import collections
|
||||
from mock import patch
|
||||
|
||||
import jenkins
|
||||
@ -464,3 +466,32 @@ class JenkinsListRunningBuildsTest(JenkinsTestBase):
|
||||
node_info_mock.return_value = node_info_to_return
|
||||
builds = self.j.get_running_builds()
|
||||
self.assertEqual([], builds)
|
||||
|
||||
|
||||
class JenkinsBuildJobUrlTest(JenkinsTestBase):
|
||||
|
||||
def test_params_as_dict(self):
|
||||
token = 'token123'
|
||||
params = [
|
||||
('m_select', 'value1'),
|
||||
('s_select', 's_select2')
|
||||
]
|
||||
parameters = collections.OrderedDict(params)
|
||||
self.assertEqual(
|
||||
self.j.build_job_url('Test Job', parameters=parameters, token=token),
|
||||
self.make_url(
|
||||
'job/Test%20Job/buildWithParameters?m_select=value1'
|
||||
'&s_select=s_select2&token=token123'))
|
||||
|
||||
def test_params_as_list(self):
|
||||
token = 'token123'
|
||||
params = [
|
||||
('m_select', 'value1',),
|
||||
('m_select', 'value3'),
|
||||
('s_select', 's_select2')
|
||||
]
|
||||
self.assertEqual(
|
||||
self.j.build_job_url('Test Job', parameters=params, token=token),
|
||||
self.make_url(
|
||||
'job/Test%20Job/buildWithParameters?m_select=value1'
|
||||
'&m_select=value3&s_select=s_select2&token=token123'))
|
||||
|
Loading…
Reference in New Issue
Block a user