blob: 1ece31ed3c427033e824880588a599b4f687488e [file] [log] [blame]
chnyda124ca042017-08-03 16:40:51 +02001#!/usr/bin/env python
2
chnydad6f76352017-08-07 12:49:34 +02003try:
4 import jenkins
5 HAS_JENKINS = True
6except ImportError:
7 HAS_JENKINS = False
chnyda124ca042017-08-03 16:40:51 +02008import salt.config
9
10def main():
chnydad6f76352017-08-07 12:49:34 +020011 if not HAS_JENKINS:
12 return {}
13
chnyda124ca042017-08-03 16:40:51 +020014 output = { "jenkins_plugins" : {} }
15 opts = salt.config.minion_config('/etc/salt/minion')
chnydaea190432017-08-08 15:37:29 +020016 try:
17 url = opts['jenkins']['url']
18 except KeyError:
19 return {}
20
21 try:
22 user = opts['jenkins']['user']
23 password = opts['jenkins']['password']
24 except KeyError:
25 user = None
26 password = None
chnyda124ca042017-08-03 16:40:51 +020027
Dennis Dmitriev9be80b02018-02-13 12:01:29 +020028 try:
29 server = jenkins.Jenkins(url, username=user, password=password)
30 plugins = server.get_plugins(depth=1)
31 except jenkins.JenkinsException:
32 return {}
33
chnyda124ca042017-08-03 16:40:51 +020034 for plugin_name, plugin_dict in plugins.iteritems():
chnyda9c05a3d2017-08-07 22:37:25 +020035 output["jenkins_plugins"][plugin_name[0]] = {"version" : (plugin_dict["version"] or 0)}
chnyda124ca042017-08-03 16:40:51 +020036 return output