Compare commits

..

No commits in common. "a5f17567eed8bca0d17722906ad062c081df5786" and "49a60993b49d2d0e35db6e3c65e69df2d8b6aa7a" have entirely different histories.

2 changed files with 473 additions and 457 deletions

View File

@ -42,8 +42,8 @@
environment { environment {
//ProxySettings //ProxySettings
AUTH = credentials('proxy') AUTH = credentials('proxy')
proxy_user = '${AUTH_USR}' proxy_user = "${AUTH_USR}"
proxy_pw = '${AUTH_PSW}' proxy_pw = "${AUTH_PSW}"
//http_proxy="http://${proxy_user}:${proxy_pw}@proxy.muc:8080" //http_proxy="http://${proxy_user}:${proxy_pw}@proxy.muc:8080"
//https_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" //no_proxy="localhost,127.0.0.1,.muc,.bmwgroup.net"
@ -81,11 +81,11 @@
TF_VAR_NA_PREPROD_API_TOKEN=credentials('NAPREPROD_TOKEN_VAR') TF_VAR_NA_PREPROD_API_TOKEN=credentials('NAPREPROD_TOKEN_VAR')
//CN PROD //CN PROD
TF_VAR_CN_PROD_ENV_URL="https://dynatrace-cn-int.bmwgroup.com/e/b921f1b9-c00e-4031-b9d1-f5a0d530757b" TF_VAR_CN_PROD_ENV_URL="https://dyna-synth-cn.bmwgroup.com.cn/e/b921f1b9-c00e-4031-b9d1-f5a0d530757b"
TF_VAR_CN_PROD_API_TOKEN=credentials('CNPROD_TOKEN_VAR') TF_VAR_CN_PROD_API_TOKEN=credentials('CNPROD_TOKEN_VAR')
//CN PREPROD //CN PREPROD
TF_VAR_CN_PREPROD_ENV_URL="https://dynatrace-cn-int.bmwgroup.com/e/ab88c03b-b7fc-45f0-9115-9e9ecc0ced35" TF_VAR_CN_PREPROD_ENV_URL="https://dyna-synth-cn.bmwgroup.com.cn/e/ab88c03b-b7fc-45f0-9115-9e9ecc0ced35"
TF_VAR_CN_PREPROD_API_TOKEN=credentials('CNPREPROD_TOKEN_VAR') TF_VAR_CN_PREPROD_API_TOKEN=credentials('CNPREPROD_TOKEN_VAR')
//TERRAFORM //TERRAFORM
@ -101,14 +101,22 @@
git branch: '${branch}', credentialsId: 'jaws_dynatrace_bitbuket_user', url: 'https://atc.bmwgroup.net/bitbucket/scm/opapm/coco_terraform_config.git' git branch: '${branch}', credentialsId: 'jaws_dynatrace_bitbuket_user', url: 'https://atc.bmwgroup.net/bitbucket/scm/opapm/coco_terraform_config.git'
} }
} }
/*
stage('install required python packages') {
steps {
sh '''
pip3 install --user -r requirements.txt
'''
}
}
*/
stage('Install Terraform') { stage('Install Terraform') {
steps { steps {
sh ''' sh '''
cd /tmp cd /tmp
curl https://releases.hashicorp.com/terraform/1.1.6/terraform_1.1.6_linux_amd64.zip > terraform.zip curl https://releases.hashicorp.com/terraform/1.1.6/terraform_1.1.6_linux_amd64.zip > terraform.zip
yes | sudo unzip terraform.zip unzip terraform.zip
yes | sudo mv -f /tmp/terraform /usr/local/bin sudo mv /tmp/terraform /usr/local/bin
sudo chmod +x /usr/local/bin/terraform sudo chmod +x /usr/local/bin/terraform
terraform --version terraform --version
cd ~ cd ~
@ -141,15 +149,20 @@
if(folderArr != null){ if(folderArr != null){
for (folder in folderArr) for (folder in folderArr)
{ {
/*
sh """
cd $WORKSPACE
cd $WORKSPACE/$environment/$folder
"""
*/
init_status = sh(returnStatus: true, script: "cd $WORKSPACE/$environment/$folder && set +e; terraform init") init_status = sh(returnStatus: true, script: "cd $WORKSPACE/$environment/$folder && set +e; terraform init")
if (init_status == 0) { if (init_status == 0) {
println "Starting terraform plan..." println "Starting terraform plan..."
plan_status = sh(returnStatus: true, script: "cd $WORKSPACE/$environment/$folder && set +e; terraform plan -out=tfplan -detailed-exitcode") plan_status = sh(returnStatus: true, script: "cd $WORKSPACE/$environment/$folder && set +e; terraform plan -out=tfplan -detailed-exitcode")
if (plan_status == 1) { if (plan_status != 0) {
println "Failed to plan $folder for $environment" println "Failed to plan $folder for $environment"
sh("curl -H 'Content-Type: application/json' -d '{\"text\":\"Failed to plan $folder for ${environment}\"}' https://bmwgroup.webhook.office.com/webhookb2/483edc00-c925-4672-8088-8299a0139fca@ce849bab-cc1c-465b-b62e-18f07c9ac198/JenkinsCI/1cf354c0e2e54e2baaf2f20b051b1dda/af36b177-c3fb-4707-a2d4-c75dbce454a2") sh("curl -H 'Content-Type: application/json' -d '{\"text\":\"Failed to plan $folder for ${environment}\"}' https://bmwgroup.webhook.office.com/webhookb2/483edc00-c925-4672-8088-8299a0139fca@ce849bab-cc1c-465b-b62e-18f07c9ac198/JenkinsCI/1cf354c0e2e54e2baaf2f20b051b1dda/af36b177-c3fb-4707-a2d4-c75dbce454a2")
currentBuild.result = 'UNSTABLE' currentBuild.result = 'UNSTABLE'}
}
} }
else { else {
println "Failed to init $folder for $environment" println "Failed to init $folder for $environment"
@ -164,20 +177,16 @@
if(folderArr != null){ if(folderArr != null){
for (folder in folderArr) for (folder in folderArr)
{ {
init_status = sh(returnStatus: true, script: "cd $WORKSPACE/$environment/$folder && set +e; terraform init") sh """
if (init_status == 0) { cd $WORKSPACE
println "Starting terraform plan..." cd $environment/$folder
plan_status = sh(returnStatus: true, script: "cd $WORKSPACE/$environment/$folder && set +e; terraform plan -out=tfplan -detailed-exitcode") """
println "Statuscode: $plan_status" status = sh(returnStatus: true, script: "set +e; terraform init")
if (plan_status == 1) { if (status == "0") {
println "Failed to plan $folder for $environment" status = sh(returnStatus: true, script: "set +e; terraform plan -out=tfplan -detailed-exitcode")
sh("curl -H 'Content-Type: application/json' -d '{\"text\":\"Failed to plan $folder for ${environment}\"}' https://bmwgroup.webhook.office.com/webhookb2/483edc00-c925-4672-8088-8299a0139fca@ce849bab-cc1c-465b-b62e-18f07c9ac198/JenkinsCI/1cf354c0e2e54e2baaf2f20b051b1dda/af36b177-c3fb-4707-a2d4-c75dbce454a2") if (status != "0") {currentBuild.result = 'UNSTABLE'}
currentBuild.result = 'UNSTABLE'
}
} }
else { else {
println "Failed to init $folder for $environment"
sh("curl -H 'Content-Type: application/json' -d '{\"text\":\"Failed to init $folder for ${environment}\"}' https://bmwgroup.webhook.office.com/webhookb2/483edc00-c925-4672-8088-8299a0139fca@ce849bab-cc1c-465b-b62e-18f07c9ac198/JenkinsCI/1cf354c0e2e54e2baaf2f20b051b1dda/af36b177-c3fb-4707-a2d4-c75dbce454a2")
currentBuild.result = 'UNSTABLE' currentBuild.result = 'UNSTABLE'
} }
} }
@ -194,39 +203,31 @@
steps { steps {
script { script {
ArrayList folderArr = evaluate("${CONFIGS}") ArrayList folderArr = evaluate("${CONFIGS}")
if(ENVIRONMENT != 'ALL') if(ENVIRONMENT != 'ALL'){
{ if(folderArr != null){
if(folderArr != null)
{
for (folder in folderArr) for (folder in folderArr)
{ {
apply_status = sh(returnStatus: true, script: "cd $WORKSPACE/$environment/$folder && set +e; terraform apply tfplan") sh """
if (apply_status != 0) cd $WORKSPACE
{ cd $ENVIRONMENT/$folder
println "Failed to apply $folder for $environment" set +e; terraform apply tfplan
sh("curl -H 'Content-Type: application/json' -d '{\"text\":\"Failed to apply $folder for ${environment}\"}' https://bmwgroup.webhook.office.com/webhookb2/483edc00-c925-4672-8088-8299a0139fca@ce849bab-cc1c-465b-b62e-18f07c9ac198/JenkinsCI/1cf354c0e2e54e2baaf2f20b051b1dda/af36b177-c3fb-4707-a2d4-c75dbce454a2") """
currentBuild.result = 'UNSTABLE'
}
} }
} }
} }
else { else {
for (environment in environments) for (environment in environments){
{ if(folderArr != null){
if(folderArr != null)
{
for (folder in folderArr) for (folder in folderArr)
{ {
// apply_status = sh(returnStatus: true, script: "cd $WORKSPACE/$environment/$folder && set +e; terraform plan -out=tfplan -detailed-exitcode") sh """
apply_status = sh(returnStatus: true, script: "cd $WORKSPACE/$environment/$folder && set +e; terraform apply tfplan") cd $WORKSPACE
if (apply_status != 0) cd $environment/$folder
{ terraform apply tfplan
println "Failed to apply $folder for $environment" """
sh("curl -H 'Content-Type: application/json' -d '{\"text\":\"Failed to apply $folder for ${environment}\"}' https://bmwgroup.webhook.office.com/webhookb2/483edc00-c925-4672-8088-8299a0139fca@ce849bab-cc1c-465b-b62e-18f07c9ac198/JenkinsCI/1cf354c0e2e54e2baaf2f20b051b1dda/af36b177-c3fb-4707-a2d4-c75dbce454a2")
currentBuild.result = 'UNSTABLE'
}
} }
} }
} }
} }
@ -234,6 +235,21 @@
} }
} }
/*
stage('Execute Export Script TERRAFORM') {
steps {
export_config_all(environments)
//sh 'python3 export.py EMEA_PROD'
//sh 'python3 export.py TERRAFORM'
//Only required once CN is not reachable from EMEA
//loopEnvironments(environments)
}
}
*/
/* /*
stage('Send report') { stage('Send report') {
@ -242,7 +258,7 @@
try { try {
emailext subject: env.JOB_NAME, emailext subject: env.JOB_NAME,
body: 'Please find the output of your reports attached', body: 'Please find the output of your reports attached',
to: 'bmw.dynatrace@nttdata.com', to: 'rene.forstner@nttdata.com',
replyTo: 'coco-apm@bmw.de', replyTo: 'coco-apm@bmw.de',
attachmentsPattern: '*.csv' attachmentsPattern: '*.csv'