Closed Klaus-Valse closed 6 years ago
This method is "magic" one. Read this: https://rszalski.github.io/magicmethods/
As views
are acting like dictionaries, your code could look like this:
for s in projectSelection:
for jobKey, job in jenkins.views[s]:
# Further processing
pass
Wow, thanks for the quick reply and that cool article, I'll printed it out and will study it :)
Best regards!
Edit: For any future greenhorn running into this problem: @lechat's example does not work like this (assertion error): You have to use the iteritems() method to get the jobs out of the view. So in respect to the snippets above, I got it working for me like this:
for jobKey, job in jenkins.views[s].iteritems():
# Further processing
pass
ISSUE TYPE
Jenkinsapi 0.3.6
Jenkins 1.658
SUMMARY
Hey!
Disclaimer: I'm far from being a Python expert, so chances are I didn't get something important. Here's what I wanna do: I wanna select a view, iterate through all the jobs therein and get the console output of each job's last build for later parsing purposes. In views.py there is a method that does just what I need:
The double-leading-underscores tell me that this method is "private", and from what I know it would be very bad practice to get a view via this method, for example it could be gone in a future version and my code wouldn't work anymore... So right now, in order to avoid using this "private" function, I came up with a quite akward solution: projectSelection contains a list of all views
Thanks for this nice API!
Best regards, Klaus