From: Aric Gardner Date: Mon, 16 Nov 2020 19:59:20 +0000 (-0500) Subject: configure global env vars X-Git-Tag: v0.59.0~4 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F75%2F66075%2F9;p=releng%2Fglobal-jjb.git configure global env vars create_jenkins_global_env_vars.py thakes jenkins_global_envvars.yaml from global-vars-production|sandbox.sh and puts them in the casc.d directory (or a custom one) Signed-off-by: Aric Gardner Change-Id: I95c3f7f268ba7146198c791bba5378e233f9b913 --- diff --git a/jenkins-admin/create_jenkins_clouds_openstack_yaml.py b/jenkins-admin/create_jenkins_clouds_openstack_yaml.py index bd94a9e4..2d81a250 100755 --- a/jenkins-admin/create_jenkins_clouds_openstack_yaml.py +++ b/jenkins-admin/create_jenkins_clouds_openstack_yaml.py @@ -111,16 +111,20 @@ def dir_path(path): raise argparse.ArgumentTypeError(f"readable_dir:{path} is not a valid path") def parse_arguments(): - parser = argparse.ArgumentParser(description='Create jcasc yaml from path to jenkins config dir.') - parser.add_argument('--path', type=dir_path) - parser.add_argument('--sandbox', type=bool, default=False, help="Set to True for sandbox yaml generation") + parser = argparse.ArgumentParser( + description='Create jcasc yaml from path to jenkins config dir.') + + + parser.add_argument('--path', type=dir_path, + help="Path to jenkins-admin directory") + parser.add_argument('--sandbox', type=bool, default=False, + help="Set to True for sandbox yaml generation") return parser.parse_args() parsed_args = parse_arguments() path = (parsed_args.path) path = ("{}**/*.cfg".format(path)) - #sandbox switch section section_cloud = {} name_prefix = "prd" @@ -213,7 +217,6 @@ for section in config_parser_merged.sections(): print(j2_template.render(section_all_machines)) - #Footer section j2_template = Template(footertemplate) print(j2_template.render(section_cloud)) diff --git a/jenkins-admin/create_jenkins_global_env_vars.py b/jenkins-admin/create_jenkins_global_env_vars.py new file mode 100755 index 00000000..927a665c --- /dev/null +++ b/jenkins-admin/create_jenkins_global_env_vars.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python + +import argparse +import configparser +import sys +import os +import ruamel.yaml +yaml = ruamel.yaml.YAML() + +kvlist = [] +output = {} +envdict = {"env":kvlist} + +def dir_path(path): + if os.path.isdir(path): + return path + else: + raise argparse.ArgumentTypeError(f"readable_dir:{path} is not a valid path") + +def parse_arguments(): + casc_d_dir = "/var/lib/jenkins/casc.d/community.d" + parser = argparse.ArgumentParser( + description='Create jcasc yaml from path to jenkins config dir.') + parser.add_argument('--path', type=dir_path, + help="Path to jenkins-admin directory") + parser.add_argument('--sandbox', type=bool, default=False, + help="Set to True for sandbox yaml generation") + parser.add_argument( + "--outputvars", + type=argparse.FileType("w"), + default="{}/jenkins_global_envvars.yaml".format(casc_d_dir), + help="Optional custom location for jenkins_global_envvars.yaml", + ) + return parser.parse_args() + +def global_vars(global_var_file): + with open(global_var_file) as myfile: + for line in myfile: + name, var = line.partition("=")[::2] + varstripped = var.strip() + kvlist.append({"key": name, "value": varstripped}) + output.update({'jenkins': + {'globalNodeProperties': + [{'envVars':envdict}] + } + }) + yaml.dump(output, parsed_args.outputvars) + + +parsed_args = parse_arguments() +path = (parsed_args.path) +global_var_file = ("{}/global-vars-production.sh".format(parsed_args.path)) +if parsed_args.sandbox: + global_var_file = ("{}/global-vars-sandbox.sh".format(parsed_args.path)) + +global_vars(global_var_file)