coco_apm_exportdtconfig/Jenkinsfile

127 lines
4.3 KiB
Groovy

def loopEnvironments(environments){
print env.JENKINS_URL
environments.each { key, val ->
//sh "echo ${key} - ${value}"
environments."${key}".each {k,v -> sh "echo ${k.name} - ${k.jenkins} - ${k.env-url}"
//env.each { k,v -> sh "echo ${k} - ${v}"}
}
}
}
pipeline {
options {
ansiColor('xterm')
}
//label libraryBuild is available in CN JAWS and ROW JAWS, therefore this one was used; no additional intents
agent {label 'libraryBuild'}
//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')
}
stages {
stage('install required python packages') {
steps {
sh '''
pip install --user -r requirements.txt
'''
print env.JENKINS_URL
}
}
//DISTINGUISH between China and EMEA JAWS environment and execute the script only on the respective environment
//Define how to
// could also be a script block instead of a when block
//e.g. add an additional parameter to python scripts to let python choose on which environment it should execute the script (not that good, as the script should be as generic as possible)
//e.g. just put the execute python script step in both steps (not that good --> do not repeat yourself)
//e.g. create two environment.yaml files and use different files for different jenkins (not that good --> ugly)
//e.g. is the environment yaml even that good, should python be refactored to only execute one environment at time
stage('Detect Jenkins Environment CN') {
when {
expression { return env.JENKINS_URL == 'https://jaws-china.bmwgroup.net/opmaas/' }
}
steps {
//env.JENKINS_URL
//env.BRANCH_NAME
print env.JENKINS_URL
print env.BRANCH_NAME
}
}
stage('Detect Jenkins Environment EMEA') {
when {
expression { return env.JENKINS_URL == 'https://jaws.bmwgroup.net/opapm/' }
}
steps {
script{environments = readYaml (file:'environment.yaml')}
sh 'echo "test" > test.csv'
loopEnvironments(environments)
//env.JENKINS_URL
//env.BRANCH_NAME
print env.JENKINS_URL
print env.BRANCH_NAME
}
}
stage('Send report') {
steps {
script {
try {
emailext subject: env.JOB_NAME,
body: 'test',
to: 'rene.forstner@nttdata.com',
replyTo: 'rene.forstner@nttdata.com',
from: 'coco-apm@bmw.de',
attachmentsPattern: 'test.csv'
}
catch ( mailExc ){
echo "Sending Email Failed: ${mailExc}"
}
}
}
}
}
post {
always {
cleanWs()
}
}
}