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

384
.gitignore vendored
View File

@ -1,193 +1,193 @@
.env .env
.vscode .vscode
output/ output/
# Local .terraform directories # Local .terraform directories
**/.terraform/* **/.terraform/*
# .tfstate files # .tfstate files
*.tfstate *.tfstate
*.tfstate.* *.tfstate.*
# Crash log files # Crash log files
crash.log crash.log
crash.*.log crash.*.log
# Exclude all .tfvars files, which are likely to contain sensitive data, such as # Exclude all .tfvars files, which are likely to contain sensitive data, such as
# password, private keys, and other secrets. These should not be part of version # password, private keys, and other secrets. These should not be part of version
# control as they are data points which are potentially sensitive and subject # control as they are data points which are potentially sensitive and subject
# to change depending on the environment. # to change depending on the environment.
*.tfvars *.tfvars
*.tfvars.json *.tfvars.json
# Ignore override files as they are usually used to override resources locally and so # Ignore override files as they are usually used to override resources locally and so
# are not checked in # are not checked in
override.tf override.tf
override.tf.json override.tf.json
*_override.tf *_override.tf
*_override.tf.json *_override.tf.json
# Include override files you do wish to add to version control using negated pattern # Include override files you do wish to add to version control using negated pattern
# !example_override.tf # !example_override.tf
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan # Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
# example: *tfplan* # example: *tfplan*
# Ignore CLI configuration files # Ignore CLI configuration files
.terraformrc .terraformrc
terraform.rc terraform.rc
# Byte-compiled / optimized / DLL files # Byte-compiled / optimized / DLL files
__pycache__/ __pycache__/
*.py[cod] *.py[cod]
*$py.class *$py.class
# C extensions # C extensions
*.so *.so
# Distribution / packaging # Distribution / packaging
.Python .Python
build/ build/
develop-eggs/ develop-eggs/
dist/ dist/
downloads/ downloads/
eggs/ eggs/
.eggs/ .eggs/
lib/ lib/
lib64/ lib64/
parts/ parts/
sdist/ sdist/
var/ var/
wheels/ wheels/
share/python-wheels/ share/python-wheels/
*.egg-info/ *.egg-info/
.installed.cfg .installed.cfg
*.egg *.egg
MANIFEST MANIFEST
# PyInstaller # PyInstaller
# Usually these files are written by a python script from a template # Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it. # before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest *.manifest
*.spec *.spec
# Installer logs # Installer logs
pip-log.txt pip-log.txt
pip-delete-this-directory.txt pip-delete-this-directory.txt
# Unit test / coverage reports # Unit test / coverage reports
htmlcov/ htmlcov/
.tox/ .tox/
.nox/ .nox/
.coverage .coverage
.coverage.* .coverage.*
.cache .cache
nosetests.xml nosetests.xml
coverage.xml coverage.xml
*.cover *.cover
*.py,cover *.py,cover
.hypothesis/ .hypothesis/
.pytest_cache/ .pytest_cache/
cover/ cover/
# Translations # Translations
*.mo *.mo
*.pot *.pot
# Django stuff: # Django stuff:
*.log *.log
local_settings.py local_settings.py
db.sqlite3 db.sqlite3
db.sqlite3-journal db.sqlite3-journal
# Flask stuff: # Flask stuff:
instance/ instance/
.webassets-cache .webassets-cache
# Scrapy stuff: # Scrapy stuff:
.scrapy .scrapy
# Sphinx documentation # Sphinx documentation
docs/_build/ docs/_build/
# PyBuilder # PyBuilder
.pybuilder/ .pybuilder/
target/ target/
# Jupyter Notebook # Jupyter Notebook
.ipynb_checkpoints .ipynb_checkpoints
# IPython # IPython
profile_default/ profile_default/
ipython_config.py ipython_config.py
# pyenv # pyenv
# For a library or package, you might want to ignore these files since the code is # For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in: # intended to run in multiple environments; otherwise, check them in:
# .python-version # .python-version
# pipenv # pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies # However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not # having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies. # install all needed dependencies.
#Pipfile.lock #Pipfile.lock
# poetry # poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more # This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries. # commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock #poetry.lock
# PEP 582; used by e.g. github.com/David-OConnor/pyflow # PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/ __pypackages__/
# Celery stuff # Celery stuff
celerybeat-schedule celerybeat-schedule
celerybeat.pid celerybeat.pid
# SageMath parsed files # SageMath parsed files
*.sage.py *.sage.py
# Environments # Environments
.env .env
.venv .venv
env/ env/
venv/ venv/
ENV/ ENV/
env.bak/ env.bak/
venv.bak/ venv.bak/
# Spyder project settings # Spyder project settings
.spyderproject .spyderproject
.spyproject .spyproject
# Rope project settings # Rope project settings
.ropeproject .ropeproject
# mkdocs documentation # mkdocs documentation
/site /site
# mypy # mypy
.mypy_cache/ .mypy_cache/
.dmypy.json .dmypy.json
dmypy.json dmypy.json
# Pyre type checker # Pyre type checker
.pyre/ .pyre/
# pytype static type analyzer # pytype static type analyzer
.pytype/ .pytype/
# Cython debug symbols # Cython debug symbols
cython_debug/ cython_debug/
# PyCharm # PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear # and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder. # option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/ #.idea/

View File

@ -1,281 +1,265 @@
def params def params
def String[] envs def String[] envs
def String[] folders def String[] folders
def rootdirlist = '' def rootdirlist = ''
def envlist = '' def envlist = ''
environments=['EMEA_PROD', 'EMEA_PREPROD', 'NA_PROD', 'NA_PREPROD', 'CN_PROD', 'CN_PREPROD'] environments=['EMEA_PROD', 'EMEA_PREPROD', 'NA_PROD', 'NA_PREPROD', 'CN_PROD', 'CN_PREPROD']
@NonCPS // has to be NonCPS or the build breaks on the call to .each @NonCPS // has to be NonCPS or the build breaks on the call to .each
def export_config_all(list) { def export_config_all(list) {
list.each { env -> list.each { env ->
sh "python3 export.py ${env}" sh "python3 export.py ${env}"
} }
} }
pipeline { pipeline {
options { options {
ansiColor('xterm') ansiColor('xterm')
} }
//label libraryBuild is available in CN JAWS and ROW JAWS, therefore this one was used; no additional intents //label libraryBuild is available in CN JAWS and ROW JAWS, therefore this one was used; no additional intents
agent {label 'jaws-slaves'} agent {label 'jaws-slaves'}
parameters { parameters {
//string(name: 'ENVIRONMENT', defaultValue: 'ALL', description: 'Possible values EMEA_PROD, EMEA_PREPROD, NA_PROD, NA_PREPROD, CN_PROD, CN_PREPROD') //string(name: 'ENVIRONMENT', defaultValue: 'ALL', description: 'Possible values EMEA_PROD, EMEA_PREPROD, NA_PROD, NA_PREPROD, CN_PROD, CN_PREPROD')
choice(name: 'ENVIRONMENT', choices: ['ALL', 'EMEA_PROD', 'EMEA_PREPROD', 'NA_PROD', 'NA_PREPROD', 'CN_PROD', 'CN_PREPROD']) choice(name: 'ENVIRONMENT', choices: ['ALL', 'EMEA_PROD', 'EMEA_PREPROD', 'NA_PROD', 'NA_PREPROD', 'CN_PROD', 'CN_PREPROD'])
string(name: 'BRANCH', defaultValue: 'master', description: 'Enter the branch you want to commit') string(name: 'BRANCH', defaultValue: 'master', description: 'Enter the branch you want to commit')
string(name: 'CONFIGS', defaultValue: '["slo"]', description: 'enter the folders, you want to deploy e.g.["CD_ABC","slo","calculated_service_metrics"]') string(name: 'CONFIGS', defaultValue: '["slo"]', description: 'enter the folders, you want to deploy e.g.["CD_ABC","slo","calculated_service_metrics"]')
booleanParam(name: 'DRY_RUN_ONLY', defaultValue: true, description: 'Execute only a terraform init and plan, no config gets deployed') booleanParam(name: 'DRY_RUN_ONLY', defaultValue: true, description: 'Execute only a terraform init and plan, no config gets deployed')
} }
//here comes the trigger according to crontabs - jenkins is in UTC //here comes the trigger according to crontabs - jenkins is in UTC
/*triggers { /*triggers {
//every 1st of every month at 00:00 //every 1st of every month at 00:00
//cron('0 0 1 * *') //cron('0 0 1 * *')
//every day at 08:00 //every day at 08:00
//cron('0 8 * * *') //cron('0 8 * * *')
//every monday at 08:00 //every monday at 08:00
//cron('0 8 * * MON') //cron('0 8 * * MON')
}*/ }*/
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"
//HTTP_PROXY="${http_proxy}" //HTTP_PROXY="${http_proxy}"
//HTTPS_PROXY="${https_proxy}" //HTTPS_PROXY="${https_proxy}"
//NO_PROXY="${no_proxy}" //NO_PROXY="${no_proxy}"
// EUPROD_TOKEN_VAR = credentials('EUPROD_TOKEN_VAR') // EUPROD_TOKEN_VAR = credentials('EUPROD_TOKEN_VAR')
// EUPREPROD_TOKEN_VAR = credentials('EUPREPROD_TOKEN_VAR') // EUPREPROD_TOKEN_VAR = credentials('EUPREPROD_TOKEN_VAR')
// NAPROD_TOKEN_VAR = credentials('NAPROD_TOKEN_VAR') // NAPROD_TOKEN_VAR = credentials('NAPROD_TOKEN_VAR')
// NAPREPROD_TOKEN_VAR = credentials('NAPREPROD_TOKEN_VAR') // NAPREPROD_TOKEN_VAR = credentials('NAPREPROD_TOKEN_VAR')
// CNPROD_TOKEN_VAR = credentials('CNPROD_TOKEN_VAR') // CNPROD_TOKEN_VAR = credentials('CNPROD_TOKEN_VAR')
// CNPREPROD_TOKEN_VAR = credentials('CNPREPROD_TOKEN_VAR') // CNPREPROD_TOKEN_VAR = credentials('CNPREPROD_TOKEN_VAR')
AWS_ACCESS_KEY_ID = credentials('AWS_TERRAFORM_KEY') AWS_ACCESS_KEY_ID = credentials('AWS_TERRAFORM_KEY')
AWS_SECRET_ACCESS_KEY = credentials('AWS_SECRET_ACCESS_KEY') AWS_SECRET_ACCESS_KEY = credentials('AWS_SECRET_ACCESS_KEY')
AWS_S3_BUCKET="coco-dynatrace-tfstate" AWS_S3_BUCKET="coco-dynatrace-tfstate"
AWS_S3_REGION="eu-central-1" AWS_S3_REGION="eu-central-1"
//TERRAFORM_RESOURCES="dynatrace_management_zone" //TERRAFORM_RESOURCES="dynatrace_management_zone"
//EMEA PROD //EMEA PROD
TF_VAR_EMEA_PROD_ENV_URL="https://xxu26128.live.dynatrace.com" TF_VAR_EMEA_PROD_ENV_URL="https://xxu26128.live.dynatrace.com"
TF_VAR_EMEA_PROD_API_TOKEN=credentials('EUPROD_TOKEN_VAR') TF_VAR_EMEA_PROD_API_TOKEN=credentials('EUPROD_TOKEN_VAR')
//EMEA PREPROD //EMEA PREPROD
TF_VAR_EMEA_PREPROD_ENV_URL="https://qqk70169.live.dynatrace.com" TF_VAR_EMEA_PREPROD_ENV_URL="https://qqk70169.live.dynatrace.com"
TF_VAR_EMEA_PREPROD_API_TOKEN=credentials('EUPREPROD_TOKEN_VAR') TF_VAR_EMEA_PREPROD_API_TOKEN=credentials('EUPREPROD_TOKEN_VAR')
//NA PROD //NA PROD
TF_VAR_NA_PROD_ENV_URL="https://wgv50241.live.dynatrace.com/" TF_VAR_NA_PROD_ENV_URL="https://wgv50241.live.dynatrace.com/"
TF_VAR_NA_PROD_API_TOKEN=credentials('NAPROD_TOKEN_VAR') TF_VAR_NA_PROD_API_TOKEN=credentials('NAPROD_TOKEN_VAR')
//NA PREPROD //NA PREPROD
TF_VAR_NA_PREPROD_ENV_URL="https://onb44935.live.dynatrace.com/" TF_VAR_NA_PREPROD_ENV_URL="https://onb44935.live.dynatrace.com/"
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
TF_VAR_TERRAFORM_ENV_URL="https://rsb41808.live.dynatrace.com" TF_VAR_TERRAFORM_ENV_URL="https://rsb41808.live.dynatrace.com"
TF_VAR_TERRAFORM_API_TOKEN=credentials('TERRAFORM_TOKEN_VAR') TF_VAR_TERRAFORM_API_TOKEN=credentials('TERRAFORM_TOKEN_VAR')
} }
stages { stages {
stage('Checkout branch') { stage('Checkout branch') {
steps { steps {
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') { stage('Install Terraform') {
steps { steps {
sh ''' sh '''
pip3 install --user -r requirements.txt cd /tmp
''' curl https://releases.hashicorp.com/terraform/1.1.6/terraform_1.1.6_linux_amd64.zip > terraform.zip
} yes | sudo unzip terraform.zip
} yes | sudo mv -f /tmp/terraform /usr/local/bin
*/ sudo chmod +x /usr/local/bin/terraform
stage('Install Terraform') { terraform --version
steps { cd ~
sh ''' '''
cd /tmp }
curl https://releases.hashicorp.com/terraform/1.1.6/terraform_1.1.6_linux_amd64.zip > terraform.zip }
unzip terraform.zip
sudo mv /tmp/terraform /usr/local/bin //Not required for using terraform, but for export config from dynatrace
sudo chmod +x /usr/local/bin/terraform /*
terraform --version stage('Download & Make exporter executable') {
cd ~ steps {
''' sh '''
} cd /tmp
} curl -L https://github.com/dynatrace-oss/terraform-provider-dynatrace/releases/download/v1.10.0/terraform-provider-dynatrace_1.10.0_linux_amd64.zip > terraform_provider.zip
unzip terraform_provider.zip
//Not required for using terraform, but for export config from dynatrace sudo mv /tmp/terraform-provider-dynatrace* /usr/local/bin/terraform-provider-dynatrace
/* sudo chmod +x /usr/local/bin/terraform-provider-dynatrace
stage('Download & Make exporter executable') { '''
steps {
sh ''' sh 'python3 --version'
cd /tmp }
curl -L https://github.com/dynatrace-oss/terraform-provider-dynatrace/releases/download/v1.10.0/terraform-provider-dynatrace_1.10.0_linux_amd64.zip > terraform_provider.zip
unzip terraform_provider.zip }
sudo mv /tmp/terraform-provider-dynatrace* /usr/local/bin/terraform-provider-dynatrace */
sudo chmod +x /usr/local/bin/terraform-provider-dynatrace stage('Dry Run') {
''' steps {
script {
sh 'python3 --version' ArrayList folderArr = evaluate("${CONFIGS}")
} if(ENVIRONMENT != 'ALL'){
if(folderArr != null){
} for (folder in folderArr)
*/ {
stage('Dry Run') { init_status = sh(returnStatus: true, script: "cd $WORKSPACE/$environment/$folder && set +e; terraform init")
steps { if (init_status == 0) {
script { println "Starting terraform plan..."
ArrayList folderArr = evaluate("${CONFIGS}") plan_status = sh(returnStatus: true, script: "cd $WORKSPACE/$environment/$folder && set +e; terraform plan -out=tfplan -detailed-exitcode")
if(ENVIRONMENT != 'ALL'){ if (plan_status == 1) {
if(folderArr != null){ println "Failed to plan $folder for $environment"
for (folder in folderArr) 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'
/* }
sh """ }
cd $WORKSPACE else {
cd $WORKSPACE/$environment/$folder 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'
init_status = sh(returnStatus: true, script: "cd $WORKSPACE/$environment/$folder && set +e; terraform init") }
if (init_status == 0) { }
println "Starting terraform plan..." }
plan_status = sh(returnStatus: true, script: "cd $WORKSPACE/$environment/$folder && set +e; terraform plan -out=tfplan -detailed-exitcode") }
if (plan_status != 0) { else {
println "Failed to plan $folder for $environment" for (environment in environments){
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(folderArr != null){
currentBuild.result = 'UNSTABLE'} for (folder in folderArr)
} {
else { init_status = sh(returnStatus: true, script: "cd $WORKSPACE/$environment/$folder && set +e; terraform init")
println "Failed to init $folder for $environment" if (init_status == 0) {
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") println "Starting terraform plan..."
currentBuild.result = 'UNSTABLE' plan_status = sh(returnStatus: true, script: "cd $WORKSPACE/$environment/$folder && set +e; terraform plan -out=tfplan -detailed-exitcode")
} println "Statuscode: $plan_status"
} if (plan_status == 1) {
} 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")
else { currentBuild.result = 'UNSTABLE'
for (environment in environments){ }
if(folderArr != null){ }
for (folder in folderArr) else {
{ println "Failed to init $folder for $environment"
sh """ 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")
cd $WORKSPACE currentBuild.result = 'UNSTABLE'
cd $environment/$folder }
""" }
status = sh(returnStatus: true, script: "set +e; terraform init")
if (status == "0") { }
status = sh(returnStatus: true, script: "set +e; terraform plan -out=tfplan -detailed-exitcode") }
if (status != "0") {currentBuild.result = 'UNSTABLE'} }
} }
else { }
currentBuild.result = 'UNSTABLE' }
}
} stage('Deploy Configuration') {
when { expression { return !DRY_RUN_ONLY.toBoolean() }}
} steps {
} script {
} ArrayList folderArr = evaluate("${CONFIGS}")
} if(ENVIRONMENT != 'ALL')
} {
} if(folderArr != null)
{
stage('Deploy Configuration') { for (folder in folderArr)
when { expression { return !DRY_RUN_ONLY.toBoolean() }} {
steps { apply_status = sh(returnStatus: true, script: "cd $WORKSPACE/$environment/$folder && set +e; terraform apply tfplan")
script { if (apply_status != 0)
ArrayList folderArr = evaluate("${CONFIGS}") {
if(ENVIRONMENT != 'ALL'){ println "Failed to apply $folder for $environment"
if(folderArr != null){ 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")
for (folder in folderArr) currentBuild.result = 'UNSTABLE'
{ }
sh """ }
cd $WORKSPACE }
cd $ENVIRONMENT/$folder }
set +e; terraform apply tfplan
""" else {
} for (environment in environments)
} {
} if(folderArr != null)
else { {
for (environment in environments){ for (folder in folderArr)
if(folderArr != null){ {
for (folder in folderArr) // apply_status = sh(returnStatus: true, script: "cd $WORKSPACE/$environment/$folder && set +e; terraform plan -out=tfplan -detailed-exitcode")
{ 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"
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'
}
} }
}
} }
} }
} }
} }
}
}
}
/* /*
stage('Execute Export Script TERRAFORM') { stage('Send report') {
steps { steps {
script {
export_config_all(environments) try {
//sh 'python3 export.py EMEA_PROD' emailext subject: env.JOB_NAME,
//sh 'python3 export.py TERRAFORM' body: 'Please find the output of your reports attached',
to: 'bmw.dynatrace@nttdata.com',
//Only required once CN is not reachable from EMEA replyTo: 'coco-apm@bmw.de',
//loopEnvironments(environments) attachmentsPattern: '*.csv'
}
}
catch ( mailExc ){
} echo "Sending Email Failed: ${mailExc}"
*/ }
}
/* }
stage('Send report') { }
steps {
script { */
try { }
emailext subject: env.JOB_NAME,
body: 'Please find the output of your reports attached', post {
to: 'rene.forstner@nttdata.com', always {
replyTo: 'coco-apm@bmw.de', cleanWs()
attachmentsPattern: '*.csv' }
}
} }
catch ( mailExc ){
echo "Sending Email Failed: ${mailExc}"
}
}
}
}
*/
}
post {
always {
cleanWs()
}
}
}