Adjusting parameters

master
Patryk Gudalewicz 2022-10-28 10:14:47 +02:00
parent 2b12f710a0
commit 07cbe8e4c9
3 changed files with 18 additions and 6 deletions

13
Jenkinsfile vendored
View File

@ -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}"
}
}

View File

@ -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'

View File

@ -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