From 4954b4765fc0484daf66cfbdb4eb851386dc0f12 Mon Sep 17 00:00:00 2001 From: rforstner Date: Thu, 2 Dec 2021 10:51:38 +0100 Subject: [PATCH] adding py --- Jenkinsfile | 45 ++++++++++----------------------------------- createReport.py | 11 +++++++---- environment.yaml | 2 +- 3 files changed, 18 insertions(+), 40 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 5c7c10d..f3acdcb 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,9 +1,11 @@ + //not required right now as CN is reachable from EMEA as well def loopEnvironments(environments){ print env.JENKINS_URL environments.each { key, val -> //Execute only if you are on the same environment + //not required right now as CN is reachable from EMEA as well if (env.JENKINS_URL == environments."${key}"[3].'jenkins') { envname = environments."${key}"[0].'name' @@ -67,40 +69,13 @@ } } - //DISTINGUISH between China and EMEA JAWS environment and execute the script only on the respective environment - //Define how to - // could also be a script block instead of a when block - //e.g. add an additional parameter to python scripts to let python choose on which environment it should execute the script (not that good, as the script should be as generic as possible) - //e.g. just put the execute python script step in both steps (not that good --> do not repeat yourself) - //e.g. create two environment.yaml files and use different files for different jenkins (not that good --> ugly) - //e.g. is the environment yaml even that good, should python be refactored to only execute one environment at time - - - stage('Detect Jenkins Environment CN') { - when { - expression { return env.JENKINS_URL == 'https://jaws-china.bmwgroup.net/opmaas/' } - } + stage('Execute Reporting Script') { steps { - - //env.JENKINS_URL - //env.BRANCH_NAME - print env.JENKINS_URL - print env.BRANCH_NAME - } - - } - stage('Detect Jenkins Environment EMEA') { - when { - expression { return env.JENKINS_URL == 'https://jaws.bmwgroup.net/opapm/' } - } - steps { - script{environments = readYaml (file:'environment.yaml')} - sh 'echo "test" > test.csv' - loopEnvironments(environments) - //env.JENKINS_URL - //env.BRANCH_NAME - print env.JENKINS_URL - print env.BRANCH_NAME + + sh 'python createReport.py' + + //Only required once CN is not reachable from EMEA + //loopEnvironments(environments) } } @@ -109,10 +84,10 @@ script { try { emailext subject: env.JOB_NAME, - body: 'test', + body: 'Please find the output of your reports attached', to: 'rene.forstner@nttdata.com', replyTo: 'coco-apm@bmw.de', - attachmentsPattern: 'test.csv' + attachmentsPattern: '*.csv' } catch ( mailExc ){ diff --git a/createReport.py b/createReport.py index e4d2ef7..2c0bee5 100644 --- a/createReport.py +++ b/createReport.py @@ -5,9 +5,9 @@ import json import pandas as pd from datetime import datetime -def make_request(url, headers): +def make_request(url, headers,verify): try: - response = requests.get(url, headers=headers,verify=False) + response = requests.get(url, headers=headers,verify=verify) response.raise_for_status() except requests.exceptions.HTTPError as errh: return "An Http Error occurred:" + repr(errh) @@ -31,8 +31,11 @@ def GatherReportingInfo(DTAPIToken, DTENV,friendlyName): 'Authorization': 'Api-Token ' + DTAPIToken } - #r = requests.get(DTAPIURL,headers=headers) - r = make_request(DTAPIURL,headers) + if (DTAPIURL.find('dynatracemgd') != -1): + verify='./certs.pem' + else: + verify=True + r = make_request(DTAPIURL,headers,verify) print(r) diff --git a/environment.yaml b/environment.yaml index 57db221..572b277 100644 --- a/environment.yaml +++ b/environment.yaml @@ -25,6 +25,6 @@ cnprod: - jenkins: "https://jaws-china.bmwgroup.net/opmaas/" cnpreprod: - name: "cnpreprod" - - env-url: "https://dynatracemgd-tsp.bmwgroup.net/e/b921f1b9-c00e-4031-b9d1-f5a0d530757b" + - env-url: "https://dynatracemgd-tsp.bmwgroup.net/e/ab88c03b-b7fc-45f0-9115-9e9ecc0ced35" - env-token-name: "CNPREPROD_TOKEN_VAR" - jenkins: "https://jaws-china.bmwgroup.net/opmaas/"