coco_apm_exportdtconfig/Jenkinsfile

166 lines
5.6 KiB
Groovy

//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'
envurl = environments."${key}"[1].'env-url'
tokenname = environments."${key}"[2].'env-token-name'
sh 'python createReport.py "${envname}"'
}
}
}
pipeline {
options {
ansiColor('xterm')
}
//label libraryBuild is available in CN JAWS and ROW JAWS, therefore this one was used; no additional intents
agent {label 'jaws-slaves'}
//here comes the trigger according to crontabs - jenkins is in UTC
triggers {
//every 1st of every month at 00:00
cron('0 0 1 * *')
//every day at 08:00
//cron('0 8 * * *')
//every monday at 08:00
//cron('0 8 * * MON')
}
environment {
//ProxySettings
AUTH = credentials('proxy')
proxy_user = "${AUTH_USR}"
proxy_pw = "${AUTH_PSW}"
http_proxy="http://${proxy_user}:${proxy_pw}@proxy.muc:8080"
https_proxy="http://${proxy_user}:${proxy_pw}@proxy.muc:8080"
no_proxy="localhost,127.0.0.1,.muc,.bmwgroup.net"
HTTP_PROXY="${http_proxy}"
HTTPS_PROXY="${https_proxy}"
NO_PROXY="${no_proxy}"
// EUPROD_TOKEN_VAR = credentials('EUPROD_TOKEN_VAR')
// EUPREPROD_TOKEN_VAR = credentials('EUPREPROD_TOKEN_VAR')
// NAPROD_TOKEN_VAR = credentials('NAPROD_TOKEN_VAR')
// NAPREPROD_TOKEN_VAR = credentials('NAPREPROD_TOKEN_VAR')
// CNPROD_TOKEN_VAR = credentials('CNPROD_TOKEN_VAR')
// CNPREPROD_TOKEN_VAR = credentials('CNPREPROD_TOKEN_VAR')
// AWS_ACCESS_KEY_ID = credentials('AWS_TERRAFORM_KEY')
// AWS_SECRET_ACCESS_KEY = credentials('AWS_SECRET_ACCESS_KEY')
TERRAFORM_RESOURCES="dynatrace_management_zone"
//EMEA PROD
TF_VAR_EMEA_PROD_ENV_URL="https://xxu26128.live.dynatrace.com"
TF_VAR_EMEA_PROD_API_TOKEN=credentials('EUPROD_TOKEN_VAR')
//EMEA PREPROD
TF_VAR_EMEA_PREPROD_ENV_URL="https://qqk70169.live.dynatrace.com"
TF_VAR_EMEA_PREPROD_API_TOKEN=credentials('EUPREPROD_TOKEN_VAR')
//NA PROD
TF_VAR_NA_PROD_ENV_URL="https://wgv50241.live.dynatrace.com/"
TF_VAR_NA_PROD_API_TOKEN=credentials('NAPROD_TOKEN_VAR')
//NA PREPROD
TF_VAR_NA_PREPROD_ENV_URL="https://onb44935.live.dynatrace.com/"
TF_VAR_NA_PREPROD_API_TOKEN=credentials('NAPREPROD_TOKEN_VAR')
//CN PROD
TF_VAR_CN_PROD_ENV_URL="https://dynatracemgd-tsp.bmwgroup.net/e/b921f1b9-c00e-4031-b9d1-f5a0d530757b"
TF_VAR_CN_PROD_API_TOKEN=credentials('CNPROD_TOKEN_VAR')
//CN PREPROD
TF_VAR_CN_PREPROD_ENV_URL="https://dynatracemgd-tsp.bmwgroup.net/e/ab88c03b-b7fc-45f0-9115-9e9ecc0ced35"
TF_VAR_CN_PREPROD_API_TOKEN=credentials('CNPREPROD_TOKEN_VAR')
//TERRAFORM
TF_VAR_TERRAFORM_ENV_URL="https://rsb41808.live.dynatrace.com"
TF_VAR_TERRAFORM_API_TOKEN=credentials('TERRAFORM_TOKEN_VAR')
}
stages {
stage('install required python packages') {
steps {
sh '''
pip3 install --user -r requirements.txt
'''
}
}
stage('Install Terraform') {
steps {
sh '''
cd /tmp
curl https://releases.hashicorp.com/terraform/1.1.4/terraform_1.1.4_linux_amd64.zip > terraform.zip
unzip terraform.zip
sudo mv /tmp/terraform /usr/local/bin
terraform --version
cd ~
'''
}
}
stage('Make exporter executable') {
steps {
sh 'chmod 755 ./bin/terraform-provider-dynatrace_v1.9.1'
sh 'sudo zypper refresh'
//sh 'chmod 755 ./updatepython.sh'
//sh './updatepython.sh'
//Only required once CN is not reachable from EMEA
//loopEnvironments(environments)
}
}
stage('Execute Export Script TERRAFORM') {
steps {
sh 'python3 export.py TERRAFORM'
//Only required once CN is not reachable from EMEA
//loopEnvironments(environments)
}
}
stage('Send report') {
steps {
script {
try {
emailext subject: env.JOB_NAME,
body: 'Please find the output of your reports attached',
to: 'rene.forstner@nttdata.com',
replyTo: 'coco-apm@bmw.de',
attachmentsPattern: '*.csv'
}
catch ( mailExc ){
echo "Sending Email Failed: ${mailExc}"
}
}
}
}
}
post {
always {
cleanWs()
}
}
}