Adds support for multi-select build parameters
This feature will allow build_job to accept build parameters as a list of two membered tuples - [('parameter key', 'parameter value', ), ...]. Currently, build_job expects to receive a dictionary of parameters but this limits the build_job_url function (which is called from build_job()) to build jenkins url for jobs with multi-select parameter(s) because dictionaries cannot have duplicate keys (in case, when there are several values to one parameter key). urlencode is capable of converting lists with two membered tuples to url as well. Change-Id: I134a5f8b69ba91acd89afa791cb1cf0b5e63f5f5 Signed-off-by: Sorin Sbarnea <ssbarnea@redhat.com>
This commit is contained in:
parent
e15a54bdc3
commit
96f0a7fa5f
@ -1127,14 +1127,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
|
||||
@ -442,3 +444,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