Compare commits

...

10 Commits

Author SHA1 Message Date
Doris Ruppert (ext.) a5f17567ee Pull request #1: fix: for environments ALL do an apply after plan and not a second apply
Merge in OPAPM/coco_terraform_pipeline from qxd0086/JENKINSFILE-1679922731469 to master

* commit '02a77c976c23891a43d5d4137adbce9269f97f35':
  fix: for environments ALL do an apply after plan and not a second apply
2023-03-27 16:03:17 +00:00
Doris Ruppert (ext.) 02a77c976c fix: for environments ALL do an apply after plan and not a second apply 2023-03-27 13:29:11 +00:00
SLW\ARNAUA e6b1fb6128 Piping yes into command line. 2022-06-17 13:24:16 +02:00
rforstner d8bb9c04a8 dry run fix 2022-06-02 13:07:52 +02:00
SLW\ARNAUA 53e1e741e9 String interpolation adjustment. 2022-06-02 10:03:02 +02:00
SLW\ARNAUA f72b956ef2 Install Terraform attempt to fix. 2022-05-24 10:49:08 +02:00
rforstner 3d0085f982 updating CN env 2022-04-29 10:30:51 +02:00
rforstner 585651f460 init 2022-03-03 15:47:14 +01:00
rforstner 2adc220615 init 2022-03-03 14:37:41 +01:00
rforstner 1b8797929e init 2022-03-03 14:35:55 +01:00
2 changed files with 457 additions and 473 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://dyna-synth-cn.bmwgroup.com.cn/e/b921f1b9-c00e-4031-b9d1-f5a0d530757b" TF_VAR_CN_PROD_ENV_URL="https://dynatrace-cn-int.bmwgroup.com/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://dyna-synth-cn.bmwgroup.com.cn/e/ab88c03b-b7fc-45f0-9115-9e9ecc0ced35" TF_VAR_CN_PREPROD_ENV_URL="https://dynatrace-cn-int.bmwgroup.com/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,22 +101,14 @@
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
unzip terraform.zip yes | sudo unzip terraform.zip
sudo mv /tmp/terraform /usr/local/bin yes | sudo mv -f /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 ~
@ -149,20 +141,15 @@
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 != 0) { if (plan_status == 1) {
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"
@ -177,16 +164,20 @@
if(folderArr != null){ if(folderArr != null){
for (folder in folderArr) for (folder in folderArr)
{ {
sh """ init_status = sh(returnStatus: true, script: "cd $WORKSPACE/$environment/$folder && set +e; terraform init")
cd $WORKSPACE if (init_status == 0) {
cd $environment/$folder println "Starting terraform plan..."
""" plan_status = sh(returnStatus: true, script: "cd $WORKSPACE/$environment/$folder && set +e; terraform plan -out=tfplan -detailed-exitcode")
status = sh(returnStatus: true, script: "set +e; terraform init") println "Statuscode: $plan_status"
if (status == "0") { if (plan_status == 1) {
status = sh(returnStatus: true, script: "set +e; terraform plan -out=tfplan -detailed-exitcode") println "Failed to plan $folder for $environment"
if (status != "0") {currentBuild.result = 'UNSTABLE'} 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'
}
} }
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'
} }
} }
@ -203,31 +194,39 @@
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)
{ {
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 {
set +e; 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'
}
} }
} }
} }
else { else {
for (environment in environments){ for (environment in environments)
if(folderArr != null){ {
if(folderArr != null)
{
for (folder in folderArr) for (folder in folderArr)
{ {
sh """ // apply_status = sh(returnStatus: true, script: "cd $WORKSPACE/$environment/$folder && set +e; terraform plan -out=tfplan -detailed-exitcode")
cd $WORKSPACE apply_status = sh(returnStatus: true, script: "cd $WORKSPACE/$environment/$folder && set +e; terraform apply tfplan")
cd $environment/$folder if (apply_status != 0)
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'
}
} }
} }
} }
} }
@ -235,21 +234,6 @@
} }
} }
/*
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') {
@ -258,7 +242,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: 'rene.forstner@nttdata.com', to: 'bmw.dynatrace@nttdata.com',
replyTo: 'coco-apm@bmw.de', replyTo: 'coco-apm@bmw.de',
attachmentsPattern: '*.csv' attachmentsPattern: '*.csv'