From 07cbe8e4c9c547c1705df127f84d96c051cbddc4 Mon Sep 17 00:00:00 2001 From: Patryk Gudalewicz Date: Fri, 28 Oct 2022 10:14:47 +0200 Subject: [PATCH] Adjusting parameters --- Jenkinsfile | 13 +++++++++++-- createDash.py | 4 ++-- readme.md | 7 +++++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 180cf62..e83e70b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -6,8 +6,9 @@ pipeline { agent {label 'libraryBuild'} parameters { string(name: 'CLUSTER', defaultValue: '', description: 'Enter the cluster name') - - string(name: 'ENVIRONMENT', defaultValue: '', description: 'Enter single environment name. Possible values are: euprod, eupreprod, napreprod, naprod, cnprod. cnpreprod') + choice(name: 'ENVIRONMENT', choices: ['euprod', 'eupreprod', 'napreprod', 'naprod', 'cnprod', 'cnpreprod'], description: 'Choose Dynatrace environment') + string(name: 'OWNER', defaultValue: '', description: 'Enter e-mail address of dashboard owner') + booleanParam(name: 'REMOVE', defaultValue: false, description: 'Check if dashboard for provided cluster should be removed instead of created') } @@ -45,6 +46,7 @@ pipeline { stage('Execute Dashboard script') { steps { script { + boolean remove = Boolean.getBoolean(REMOVE); def SCRIPT_PARAMETER = '' if(CLUSTER.isEmpty()) { currentBuild.result = 'ABORTED' @@ -56,9 +58,16 @@ pipeline { error('Aborting due to missing ENVIRONMENT parameter') return } + else if(OWNER.isEmpty()) { + currentBuild.result = 'ABORTED' + error('Aborting due to missing OWNER parameter') + return + } else { SCRIPT_PARAMETER = SCRIPT_PARAMETER + " -C " + CLUSTER.toString() SCRIPT_PARAMETER = SCRIPT_PARAMETER + " -E " + ENVIRONMENT.toString() + SCRIPT_PARAMETER = SCRIPT_PARAMETER + " -O " + OWNER.toString() + if(remove) { SCRIPT_PARAMETER = SCRIPT_PARAMETER + " --remove "} sh "python createDash.py ${SCRIPT_PARAMETER}" } } diff --git a/createDash.py b/createDash.py index 5bc2f53..6cf3f64 100644 --- a/createDash.py +++ b/createDash.py @@ -13,7 +13,7 @@ parser = argparse.ArgumentParser(description="Generate and deploy the Kubernetes parser.add_argument("-C", "--cluster", type=str,required=True, help="Name of the Kubernetes cluster") parser.add_argument('--remove', default=False, action='store_true', help="Remove dashboard for given cluster. If not specified dashboard will be created or updated") parser.add_argument('-E', '--environment', type=str, help="Name of the environment (the same as in environment.yaml file. Used to upload dashboard to specific Dynatrace environment. If not specified all environments in file will be used") - +parser.add_argument('-O', '--owner', type=str, help="Email address of dashboard owner") args = parser.parse_args() def make_request(url, DTAPIToken,verify, method, jsondata): headers = { @@ -80,7 +80,7 @@ def create_or_update_dashboard(DTAPIToken, DTENV, dashboards, templatename, dash newdashboard = { "dashboardMetadata":{ "name": dashname, - "owner": config("DASHBOARD_OWNER"), + "owner": args.owner, "tags": ["Kubernetes"], #"preset": 'true', "shared":'true' diff --git a/readme.md b/readme.md index a7b7aa1..8f8b96e 100644 --- a/readme.md +++ b/readme.md @@ -25,7 +25,7 @@ To provide authentication for API calls, create ".env" file in the script direct # Usage - usage: createDash.py [-h] -C CLUSTER [--remove] [-E ENVIRONMENT] + usage: createDash.py [-h] -C CLUSTER [--remove] [-E ENVIRONMENT] [-O OWNER] Generate and deploy the Kubernetes Overview Dashboard as Code. @@ -35,7 +35,10 @@ To provide authentication for API calls, create ".env" file in the script direct Name of the Kubernetes cluster (default: None) --remove Remove dashboard for given cluster. If not specified dashboard will be created or updated (default: False) -E ENVIRONMENT, --environment ENVIRONMENT - Name of the environment (the same as in environment.yaml file. Used to upload dashboard to specific Dynatrace environment. If not specified all environments in file will be used (default: None) + Name of the environment (the same as in environment.yaml file. Used to upload dashboard to specific Dynatrace environment. If not specified all environments in file will be used + (default: None) + -O OWNER, --owner OWNER + Email address of dashboard owner (default: None) # Files ## createDash.py