adding py

OPMAAS-3581
rforstner 2021-12-02 10:51:38 +01:00
parent 92bff9c099
commit 4954b4765f
3 changed files with 18 additions and 40 deletions

41
Jenkinsfile vendored
View File

@ -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
}
sh 'python createReport.py'
}
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
//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 ){

View File

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

View File

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