added requirements.txt and Jenkinsfile

master
SLW\ARNAUA 2023-05-17 13:27:15 +02:00
parent 7d89b05c0b
commit f0bcfd5a58
3 changed files with 176 additions and 6 deletions

175
Jenkinsfile vendored Normal file
View File

@ -0,0 +1,175 @@
def installRetryCount = 0
def reportRetryCount = 0
def checkRetryCount = 0
def checkRetryCountSec = 0
pipeline {
options {
ansiColor('xterm')
}
agent {label 'jaws-slaves'}
triggers {
cron('0 5 * * 0-7')
}
environment {
AUTH = credentials('proxy')
proxy_user = "${AUTH_USR}"
proxy_pw = "${AUTH_PSW}"
EMEA_PROD_API_TOKEN = credentials('EUPROD_TOKEN_VAR')
EMEA_PREPROD_API_TOKEN = credentials('EUPREPROD_TOKEN_VAR')
NA_PROD_API_TOKEN = credentials('NAPROD_TOKEN_VAR')
NA_PREPROD_API_TOKEN = credentials('NAPREPROD_TOKEN_VAR')
CN_PROD_API_TOKEN = credentials('CNPROD_TOKEN_VAR')
CN_PREPROD_API_TOKEN = credentials('CNPREPROD_TOKEN_VAR')
}
stages {
stage('Fetch Repositories') {
steps {
parallel 'Checkout Repositories': {
dir("/opt/workspace/coco_apm_dynatrace_terraform_backup/") {
retry(3) {
sleep(300*checkRetryCount)
script {
checkRetryCount = checkRetryCount + 1
}
git branch: "master", credentialsId: "jaws_dynatrace_bitbuket_user", url: "https://atc.bmwgroup.net/bitbucket/scm/opapm/coco_apm_dynatrace_terraform_backup.git"
}
}
dir("/opt/workspace/coco_apm_dynatrace_terraform_backup_exporter/") {
retry(3) {
sleep(300*checkRetryCountSec)
script {
checkRetryCountSec = checkRetryCountSec + 1
}
git branch: "main", credentialsId: "jaws_dynatrace_bitbuket_user", url: "https://atc.bmwgroup.net/bitbucket/scm/opapm/coco_apm_dynatrace_terraform_backup_exporter.git"
}
}
}
}
}
stage('Install Required Python Packages') {
steps {
dir("/opt/workspace/qm_report/") {
retry(3) {
sleep(300*installRetryCount)
script {
installRetryCount = installRetryCount+1
}
sh '''
pip3 install --user -r requirements.txt
'''
}
}
}
}
stage('Move SLO Configuration File') {
steps {
dir("/opt/workspace/") {
// move slo configuration file
sh'''
mv /opt/workspace/shared_configuration/slo_parameter.yaml /opt/workspace/qm_report/
'''
}
}
}
stage('Execute Reporting Script') {
steps {
dir("/opt/workspace/qm_report/") {
retry(3) {
sleep(300*reportRetryCount)
script {
reportRetryCount = reportRetryCount+1
def SCRIPT_PARAMETER = ''
if(SLICES.isEmpty()) {
currentBuild.result = 'ABORTED'
error('Aborting due to missing slice parameter')
return
} else {
SCRIPT_PARAMETER = SCRIPT_PARAMETER + " -s " + SLICES.toString()
}
if (PRESELECT.isEmpty()) {
if (FROMDATE=='') {
currentBuild.result = 'ABORTED'
error('Aborting due to missing startdate parameter')
return
} else {
SCRIPT_PARAMETER = SCRIPT_PARAMETER + " -f " + FROMDATE.toString()
}
if (TODATE=='') {
currentBuild.result = 'ABORTED'
error('Aborting due to missing enddate parameter')
return
} else {
SCRIPT_PARAMETER = SCRIPT_PARAMETER + " -t " + TODATE.toString()
}
} else {
SCRIPT_PARAMETER = SCRIPT_PARAMETER + " -p " + PRESELECT.toString()
}
echo "${SCRIPT_PARAMETER}"
sh "python3 createReport.py ${SCRIPT_PARAMETER}"
sh "python3 summary.py"
summary = readFile('summary.txt').trim()
}
}
// Only required once CN is not reachable from EMEA
// loopEnvironments(environments)
}
}
}
stage('Send Report') {
steps {
script {
dir("/opt/workspace/qm_report/") {
try {
emailext subject: "NEW ${env.JOB_NAME}",
mimeType: 'text/html',
body: "Please find the output of the daily QM-Report attached </br></br>${summary}",
// to: 'michaela.jaeger@bmw.de, OOC-Support@bmwgroup.com, Andreas.DA.Danzer@partner.bmw.de',
// to: 'rene.forstner@nttdata.com, Andreas.DA.Danzer@partner.bmw.de, linnea.bickeboeller@partner.bmwgroup.com',
// to: 'rene.forstner@nttdata.com, stephan.oertelt@bmw.de, Mohammed.Abadel@bmw.de, michaela.jaeger@bmw.de',
// to: 'rene.forstner@nttdata.com, ermis.wieger@nttdata.com, patryk.gudalewicz.bp@nttdata.com',
// to: 'patryk.gudalewicz.bp@nttdata.com',
// to: 'rene.forstner@nttdata.com, ermis.wieger@nttdata.com, arnel.arnautovic@nttdata.com, patryk.gudalewicz.bp@nttdata.com, stephan.oertelt@bmw.de, Mohammed.Abadel@bmw.de, michaela.jaeger@bmw.de, OOC-Support@bmwgroup.com, Andreas.DB.Danzer@bmwgroup.com',
to: 'Andreas.DB.Danzer@bmwgroup.com, Arnel.Arnautovic@nttdata.com, Ermis.Wieger@nttdata.com',
replyTo: 'coco-apm@bmw.de',
attachmentsPattern: '*.xlsx'
} catch ( mailExc ) {
echo "Sending Email Failed: ${mailExc}"
}
}
}
}
}
}
post {
failure {
emailext subject: "${env.JOB_NAME} build ${env.BUILD_ID} failed",
body: "QM report failed, see logs for details: ${env.BUILD_URL}",
to: 'Arnel.Arnautovic@nttdata.com'
// to post to the teams channel "0 - APM Service Desk" just uncomment the following command:
// office365ConnectorSend webhookUrl: "https://bmwgroup.webhook.office.com/webhookb2/483edc00-c925-4672-8088-8299a0139fca@ce849bab-cc1c-465b-b62e-18f07c9ac198/JenkinsCI/9aca6923685b40f794134853fcbe88f1/ff31bcee-96b3-4481-9bd8-4f74180b263b",
// message: "QM report failed, see logs for details: ${env.BUILD_URL}",
// status: 'Failure',
// color: "d00000"
}
always {
cleanWs()
}
}
}

View File

@ -8,7 +8,6 @@ from dotenv import load_dotenv
from glob import glob
# [AA 2021.12.10] Method to set environments
def setEnv(env, time, path, dashboard):
os.environ['DYNATRACE_ENV_URL'] = str(os.getenv(env + "_ENV_URL"))
os.environ['DYNATRACE_API_TOKEN'] = str(os.getenv(env + "_API_TOKEN"))
@ -16,7 +15,6 @@ def setEnv(env, time, path, dashboard):
return os.environ
# [AA 2021.12.10] Method to call process synchronously
def runProcess(process_name, input_params):
process_names = ["Export", "Terraform init"]
success = False
@ -25,7 +23,6 @@ def runProcess(process_name, input_params):
process.wait(timeout=60*10) # 10 minutes
success = True
print("[DEBUG]", "Process:", process_name, "Success:", success)
# print("[DEBUG]", "Process return code:", outs)
except subprocess.TimeoutExpired:
print("[DEBUG]", "Exception occured:", subprocess.TimeoutExpired)
print("[DEBUG]", "Killing process:", process_name)
@ -43,7 +40,6 @@ def runProcess(process_name, input_params):
print("[FAILED]", input_params)
# [AA 2022.01.17] Arguments passed
if __name__ == "__main__":
if(len(sys.argv) == 1):
@ -61,5 +57,4 @@ if __name__ == "__main__":
print("Finished!")
else:
print("Usage example: ")
print("List of available environments: CN_PREPROD, CN_PROD, EMEA_PREPROD, EMEA_PROD, NA_PREPROD, NA_PROD")
print("python .\exportConfig.py EMEA_PROD ")
print("python .\export.py")

BIN
requirements.txt Normal file

Binary file not shown.