Add possibility to redefine values in YAML-based
Jenkins parameters
Also fixed typo in method name
PROD-36265
Change-Id: I7df29e7c46b7cdf6cd7e45b684c7e18c64201765
diff --git a/tcp_tests/managers/jenkins/client.py b/tcp_tests/managers/jenkins/client.py
index 79b248c..a31bbc8 100644
--- a/tcp_tests/managers/jenkins/client.py
+++ b/tcp_tests/managers/jenkins/client.py
@@ -4,6 +4,7 @@
import jenkins
import json
+import yaml
import requests
from devops.helpers import helpers
@@ -99,16 +100,47 @@
job_params = job_params['parameterDefinitions']
return job_params
- def make_defults_params(self, name):
+ def make_defaults_params(self, name):
job_params = self.job_params(name)
def_params = dict(
[(j['name'], j['defaultParameterValue']['value'])
for j in job_params])
return def_params
+ def _correct_yaml_params(self, job_name, params):
+ """
+ Params can be defined as a nested dict.
+ In that case 2nd-layer dict will be translated to YAML text and
+ added to default parameter value
+
+ :param job_name: Job name
+ :param params: dict of JenkinsJobs parameters
+ :return: nothing
+ """
+ for param_name, param_value in params.items():
+ if not isinstance(param_value, dict):
+ continue
+ default_param = self.make_defaults_params(job_name).get(param_name)
+ if default_param is None:
+ print("{param} param of {job} job doesn't exist. "
+ "Ignoring enriching it with {value}".format(
+ param=param_name,
+ job=job_name,
+ value=param_value
+ ))
+ continue
+ yaml_param = yaml.load(default_param)
+ yaml_param.update(param_value)
+ params[param_name] = yaml.dump(yaml_param,
+ default_flow_style=False)
+ return params
+
@retry()
def run_build(self, name, params=None, timeout=600, verbose=False):
- params = params or self.make_defults_params(name)
+ params = params or self.make_defaults_params(name)
+ params = self._correct_yaml_params(job_name=name,
+ params=params)
+
num = self.__client.build_job(name, params)
time.sleep(2) # wait while job is started