Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for creates views and creates jobs into view #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion autojenkins/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather have the view name as an optional argument in the existing create method (viewname=None as default).
It makes the API simpler IMO. It also means less duplication of code.

What do you think?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, great idea.

"""
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'})