forked from Amwam/Jenkins-Alfred-Workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
51 lines (40 loc) · 1.5 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from workflow import Workflow3
from jenkins.jenkins_interface import JenkinsInterface, NoJobsFound
def main(wf):
wf.setvar('WF_USERNAME', 'jenkins')
command = wf.args[0]
query = wf.args[1] if len(wf.args) > 1 else None
interface = JenkinsInterface(wf)
options = {
'set_url': interface.set_jenkins_url,
'login': interface.set_login,
'clear_login': interface.clear_login,
'failing': interface.get_failed_jobs,
'building': interface.get_building_jobs,
'all': interface.get_all_jobs
}
try:
jobs = options[command](query)
if not query:
wf.add_item("Open Jenkins",
arg=interface.get_jenkins_url(),
valid=True)
for job in jobs:
item = wf.add_item(title=job.name,
subtitle=job.build_infos,
arg=job.last_build_url if command == 'building' else job.url,
valid=True,
icon=job.image)
item.add_modifier(
key='shift',
subtitle='Open console',
arg=job.last_build_url,
valid=bool(job.last_build_url)
)
except NoJobsFound:
wf.logger.debug("Could not find any jobs for instance: %s",
wf.settings['jenkins_url'])
wf.add_item("Error: No jobs found")
wf.send_feedback()
if __name__ == '__main__': # pragma: no cover
Workflow3().run(main)