import java.text.SimpleDateFormat import groovy.transform.Field @Field List props = [] pipeline { agent none parameters { choice( name: 'ACTION', choices: ['ALL','WEB','LINUX'], description: 'Выбор бэкапа' ) } options { disableConcurrentBuilds() timestamps() buildDiscarder(logRotator(numToKeepStr: '10')) skipDefaultCheckout() timeout(time: 2400, unit: 'MINUTES') } environment { BUILD_USER = getBuildUser() CURRENT_DATE = new Date().format( 'dd.MM.yy_HH:mm' ) } triggers{ parameterizedCron(''' 00 21 * * 5 %ACTION=WEB ''') } stages { stage('Prepare_ASTAROT') { agent {label "site"} steps { deleteDir() gitClone("master") } } stage('WEB_BACKUP') { agent {label "site"} when { beforeAgent true anyOf {environment name: 'ACTION', value: 'WEB'; environment name: 'ACTION', value: 'ALL'} } steps { sh ''' rsync -avHAXxz --progress --delete --numeric-ids --exclude devpribor.ru/core/cache/* -e ssh intertest@188.120.241.91://var/www/intpribor/www /srv/archive/site/dev/ rsync -avHAXxz --progress --delete --numeric-ids --exclude interpribor.ru/core/cache/* -e ssh intertest@188.120.241.91://var/www/devtest/www /srv/archive/site/test/ rsync -avHAXxz --progress --delete --numeric-ids --exclude interpribor.ru/core/cache/* -e ssh interbase@82.146.55.174://var/www/intpribor/www /srv/archive/site/prod/ ssh interbase@82.146.55.174 "mysqldump --host 127.0.0.1 --port 3307 --column-statistics=0 --no-tablespaces -ucarpribor -p1L5n0E7Ah8A9 carpribor | gzip -9" > /srv/archive/site/prod/carpribor_$(date +%d%m%Y).sql.gz tar -zcvf /mnt/backup/site/site_prod_$(date +%d%m%Y).tar.gz /srv/archive/site/prod/ tar -zcvf /mnt/backup/site/site_dev_$(date +%d%m%Y).tar.gz /srv/archive/site/dev/www/devpribor.ru/ find /mnt/backup/site/ -name "*.gz" -mtime +27 -exec rm -f {} \\; ''' updateDesc("${env.STAGE_NAME}") sendME("${env.STAGE_NAME}","WEB Backup success!!!") telegramSend(message: 'WEB BACKUP success!!!', chatId: 648920818) } } //// } post { success { node ("site") { jabberNotify notificationStrategy: 'success', notifyCulprits: true, notifyFixers: true, notifySuspects: true, notifyUpstreamCommitters: true, extraMessage: 'WEB BACKUP SUCCESS!!!', targets: 'user@domen' } } aborted { node ("site") { jabberNotify notificationStrategy: 'aborted', notifyCulprits: true, notifyFixers: true, notifySuspects: true, notifyUpstreamCommitters: true, extraMessage: 'WEB BACKUP ABORT!!!', targets: 'user@domen' } } failure { node ("site") { jabberNotify notificationStrategy: 'failure', notifyCulprits: true, notifyFixers: true, notifySuspects: true, notifyUpstreamCommitters: true, extraMessage: 'WEB BACKUP ERROR!!!', targets: 'user@domen' } } } } def getBuildUser() { return currentBuild.rawBuild.getCause(Cause.UserIdCause)?.getUserId() } def updateDesc(ACTION) { def d = [ACTION: '', BACKUP_DATE: '', END_TIME: ''] END_TIME = new Date().format( 'dd.MM.yy_HH:mm' ) d.ACTION = "${ACTION}" d.BACKUP_DATE = "${CURRENT_DATE}" d.END_TIME = "${END_TIME}" d1 = d.clone() props << d1 println d1 d.clear() println props println d println "${END_TIME}" def item = Jenkins.instance.getItemByFullName("${JOB_NAME}") item.setDescription("${getDescTemplate(props)}") } def sendME(ACTION,STATUS) { emailext body: "${STATUS}", subject: "${ACTION}", to: 'therion@nasda.ru' } def gitClone(String stand) { checkout poll: false, scm: [ $class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, userRemoteConfigs: [[url: 'git@gitlab.domen:user/sys.git']] ] } def scriptDir = getClass().protectionDomain.codeSource.location.path println "${scriptDir}" String currentDir = new File(".").getAbsolutePath() def getDescTemplate(List props) { return """
Задача бэкапирует сетевые диски| Задания бэкапа: | |||||||
|---|---|---|---|---|---|---|---|
| Бэкапирование | Дата выполнения | Время завершения | |||||
| ${prop.ACTION} | ${prop.BACKUP_DATE} | ${prop.END_TIME} | |||||