diff --git a/autojenkins/jobs.py b/autojenkins/jobs.py index ddfc6bb..ef864c4 100644 --- a/autojenkins/jobs.py +++ b/autojenkins/jobs.py @@ -46,7 +46,8 @@ def __str__(self): LAST_REPORT = '{0}/job/{1}/lastBuild/testReport/' + API ENABLE = '{0}/job/{1}/enable' DISABLE = '{0}/job/{1}/disable' - +NEWVIEW = '{0}/createView' +NEW_JOB_INTO_VIEW = '{0}/view/{1}/createItem' class HttpStatusError(Exception): pass @@ -351,3 +352,36 @@ def wait_for_build(self, jobname, poll_interval=3): sys.stdout.write('.') sys.stdout.flush() print('') + + def createJobIntoView(self, jobname, viewname, config_file, **context): + """ + Create a job into a view from a configuration file. + """ + params = {'name': jobname} + with open(config_file) as file: + content = file.read() + + template = Template(content) + content = template.render(**context) + + return self._build_post(NEW_JOB_INTO_VIEW, + viewname, + data=content, + params=params, + headers={'Content-Type': 'application/xml'}) + + def create_view(self, viewname, config_file, **context): + """ + Create a view from a configuration file. + """ + params = {'name': viewname} + with open(config_file) as file: + content = file.read() + + template = Template(content) + content = template.render(**context) + + return self._build_post(NEWVIEW, + data=content, + params=params, + headers={'Content-Type': 'application/xml'})