coco_apm_reporting_accmgmt/Jenkinsfile

112 lines
3.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 'libraryBuild'}
parameters {
string(name: 'maxUsers', defaultValue: '2', description: 'Enter the number of users, to consider a group as empty')
string(name: 'lastLogin', defaultValue: '60', description: 'Enter the amount of days since the last login to consider a user inactive')
}
//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}"
ACCOUNT_TOKEN_VAR = credentials('ACCOUNT_TOKEN_VAR')
}
stages {
stage('install required python packages') {
steps {
sh '''
pip3 install --user -r requirements.txt
'''
print env.JENKINS_URL
}
}
stage('Execute Reporting Script') {
steps {
script{
def SCRIPT_PARAMETER = ''
SCRIPT_PARAMETER = " -mU " + maxUsers.toString()
SCRIPT_PARAMETER = SCRIPT_PARAMETER + " -ll " + lastLogin.toString()
sh """cd ./src
python3 createReport.py ${SCRIPT_PARAMETER}
pwd
ls -la
"""
}
//Only required once CN is not reachable from EMEA
//loopEnvironments(environments)
}
}
stage('Send report') {
steps {
script {
try {
emailext subject: env.JOB_NAME,
body: 'Please find the output of your reports attached',
to: 'bmw.dynatrace@nttdata.com, coco-apm@bmw.de, ops-xibix@list.bmw.com, omo-xibix@list.bmw.com, omo@bmwgroup.com',
replyTo: 'coco-apm@bmw.de',
attachmentsPattern: '*.xlsx'
}
catch ( mailExc ){
echo "Sending Email Failed: ${mailExc}"
}
}
}
}
}
post {
always {
cleanWs()
}
}
}