Last active
August 27, 2018 10:05
-
-
Save naumvd95/1e08f15eb25ea3857f59e6a3e0ae4d5e to your computer and use it in GitHub Desktop.
Jenkins plugin information monitoring
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
''' | |
requirements: | |
pip install python-jenkins | |
chmod u+x plugin_info.py | |
Example output: | |
./plugin_info.py -o=log.txt -f=longName,version | |
''' | |
import argparse | |
import jenkins | |
import pprint | |
import json | |
pp = pprint.PrettyPrinter() | |
server = jenkins.Jenkins('http://172.16.10.254:8081', username='admin', password='password') | |
user = server.get_whoami() | |
version = server.get_version() | |
print('Hello %s from Jenkins %s' % (user['fullName'], version)) | |
def get_args(): | |
parser = argparse.ArgumentParser("Script retrieves plugin info from jenkins server") | |
parser.add_argument("-o", "--output", | |
help="filename to print output, otherwise console stdout is default", | |
default="stdout", | |
type=str) | |
parser.add_argument("-f", "--filter", | |
help="print only filter plugin info by specific comma-separated keys: \n \ | |
active | \ | |
backupVersion | \ | |
bundled | \ | |
deleted | \ | |
dependencies | \ | |
downgradable | \ | |
enabled | \ | |
hasUpdate | \ | |
longName | \ | |
pinned | \ | |
requiredCoreVersion | \ | |
shortName | \ | |
supportsDynamicLoad | \ | |
url | \ | |
version", | |
default="all", | |
type=str) | |
args = parser.parse_args() | |
output = args.output | |
filter_scope = args.filter.split(",") | |
return output, filter_scope | |
# Start | |
output, scope = get_args() | |
plugin_list = server.get_plugins_info() | |
output_list = plugin_list | |
if scope != 'all': | |
output_list = {} | |
for i in plugin_list: | |
targets = "" | |
for c in scope: | |
targets += "{} >>> {}, ".format(c, i.get(c, "")) | |
output_list[i['shortName']] = targets | |
if output != 'stdout': | |
report_file = open(output, 'w') | |
report_file.write(json.dumps(output_list, indent=4, sort_keys=True)) | |
report_file.close() | |
else: | |
pp.pprint("Jenkins plugins: {}".format(output_list)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment