slo-generator/Jenkinsfile

167 lines
6.7 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'}
agent {label 'jaws-slaves'}
parameters {
string(name: 'INPUTFOLDER', defaultValue: '', description: 'Enter the business line (aka department) folder e.g. DE-3')
string(name: 'ABRANCH', defaultValue: 'BusinessLine', description: 'Enter the branch for the shared_configuration repository')
string(name: 'BBRANCH', defaultValue: 'master', description: 'Enter the branch for the coco_terraform_config repository')
string(name: 'CBRANCH', defaultValue: 'master', description: 'Enter the branch for the coco_apm_slo_yaml2tf repository')
}
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')
// FROM_DATE="${params.FROMDATE}"
// TO_DATE="${params.TODATE}"
}
stages {
stage('Fetch Repositories'){
steps {
parallel 'Checkout Repositories': {
dir("/opt/workspace/shared_configuration/") {
git branch: "${params.ABRANCH}", credentialsId: "jaws_dynatrace_bitbuket_user", url: "https://atc.bmwgroup.net/bitbucket/scm/opapm/shared_configuration.git"
}
dir("/opt/workspace/coco_terraform_config/") {
git branch: "${params.BBRANCH}", credentialsId: "jaws_dynatrace_bitbuket_user", url: "https://atc.bmwgroup.net/bitbucket/scm/opapm/coco_terraform_config.git"
}
dir("/opt/workspace/coco_apm_slo_yaml2tf/") {
git branch: "${params.CBRANCH}", credentialsId: "jaws_dynatrace_bitbuket_user", url: "https://atc.bmwgroup.net/bitbucket/scm/opapm/coco_apm_slo_yaml2tf.git"
}
}
}
}
stage('Checkout New Branch') {
steps{
script {
def now = new Date()
env.timestamp = now.format("yyMMdd-HHmm", TimeZone.getTimeZone('GMT'))
println env.timestamp
env.branch = env.timestamp+"-automatedSLOGeneration"
dir("/opt/workspace/coco_terraform_config/") {
sh "git checkout -b \"${env.branch}\""
}
}
}
}
stage('Install Required Python Packages') {
steps {
sh '''
pwd
cd ..
pwd
ls -la
cd ./shared_configuration/
ls -la
cd ../coco_terraform_config/
ls -la
cd ../coco_apm_slo_yaml2tf/
ls -la
cd ..
pwd
python3 --version
pip3 --version
pip3 install --user -r ./coco_apm_slo_yaml2tf/requirements.txt
'''
}
}
stage('Execute Script') {
steps {
dir("/opt/workspace/coco_apm_slo_yaml2tf/"){
sh "python3 generate.py /opt/workspace/shared_configuration/${params.INPUTFOLDER} /opt/workspace/coco_terraform_config/"
//Only required once CN is not reachable from EMEA
//loopEnvironments(environments)
}
}
}
stage('Push Changes') {
steps {
withCredentials([gitUsernamePassword(credentialsId: "jaws_dynatrace_bitbuket_user", gitToolName: 'Default')]) {
script {
dir("/opt/workspace/coco_terraform_config/") {
sh "git status"
sh "git add ."
sh "git commit -m \"${env.timestamp}\""
sh "git push origin ${env.branch}"
}
}
}
}
}
// stage('Push Changes') {
// steps {
// script {
// dir("/opt/workspace/coco_terraform_config/") {
// sh "git status"
// sh "git add ."
// sh "git commit -m \"${env.timestamp}\""
// sh "git push origin ${env.branch}"
// }
// }
// }
// }
}
post {
failure {
emailext subject: "${env.JOB_NAME} build ${env.BUILD_ID} failed",
body: "SLO Generator failed, see logs for details: ${env.BUILD_URL}",
to: 'ermis.wieger@nttdata.com, 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()
}
}
}