all demo
This commit is contained in:
218
jenkins/1csrv.groovy
Normal file
218
jenkins/1csrv.groovy
Normal file
@@ -0,0 +1,218 @@
|
||||
import java.text.SimpleDateFormat
|
||||
import groovy.transform.Field
|
||||
@Field List props = []
|
||||
|
||||
pipeline {
|
||||
agent none
|
||||
|
||||
parameters {
|
||||
choice(
|
||||
name: 'ACTION',
|
||||
choices: ['ALL','1CDB','KD'],
|
||||
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 23 * * 5 %ACTION=KD
|
||||
''')
|
||||
}
|
||||
|
||||
stages {
|
||||
|
||||
stage('Prepare_MASTER') {
|
||||
agent {label "master"}
|
||||
steps {
|
||||
deleteDir()
|
||||
gitClone("master")
|
||||
}
|
||||
}
|
||||
|
||||
stage('Prepare_1CSRV') {
|
||||
agent {label "mssql"}
|
||||
steps {
|
||||
deleteDir()
|
||||
gitClone("master")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/////
|
||||
stage('Backup_KD') {
|
||||
agent {label "master"}
|
||||
when { beforeAgent true
|
||||
anyOf {environment name: 'ACTION', value: 'KD'; environment name: 'ACTION', value: 'ALL'}
|
||||
}
|
||||
|
||||
steps {
|
||||
pwsh script: "./1csrv/1csrv_session.ps1 KD $env.JOB_NAME"
|
||||
updateDesc("${env.STAGE_NAME}")
|
||||
sendME("${env.STAGE_NAME}","Backup success!!!")
|
||||
telegramSend(message: 'KD backup success!!!', chatId: 648920818)
|
||||
}
|
||||
}
|
||||
/////
|
||||
|
||||
stage('Backup_1C_MSSQL') {
|
||||
agent {label "master"}
|
||||
when { beforeAgent true
|
||||
anyOf {environment name: 'ACTION', value: '1CDB'; environment name: 'ACTION', value: 'ALL'}
|
||||
}
|
||||
|
||||
steps {
|
||||
pwsh script: "./1csrv/1csrv_session.ps1 1CDB $env.JOB_NAME"
|
||||
updateDesc("${env.STAGE_NAME}")
|
||||
sendME("${env.STAGE_NAME}","Backup success!!!")
|
||||
telegramSend(message: '1C backup success!!!', chatId: 648920818)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
post {
|
||||
success {
|
||||
node ("master") {
|
||||
jabberNotify notificationStrategy: 'success', extraMessage: 'MSSQL и Сетевые диски успешно сбэкапированы, можно забирать', targets: 'user@domen'
|
||||
}
|
||||
}
|
||||
|
||||
aborted {
|
||||
node ("master") {
|
||||
jabberNotify notificationStrategy: 'aborted', notifyCulprits: true, notifyFixers: true, notifySuspects: true, notifyUpstreamCommitters: true, extraMessage: 'Пришлось остановить', targets: 'user@domen'
|
||||
}
|
||||
}
|
||||
failure {
|
||||
node ("master") {
|
||||
jabberNotify notificationStrategy: 'failure', notifyCulprits: true, notifyFixers: true, notifySuspects: true, notifyUpstreamCommitters: true, extraMessage: 'Бэкап сетевых дисков завершился с ошибкой', 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 """
|
||||
<?xml version="1.0" encoding="UTF-8"?><html>
|
||||
<body>
|
||||
<b>Задача бэкапирует базы данных 1С</b>
|
||||
<div style="font-wight:bold;">
|
||||
Если сборка не прошла, звонить :)
|
||||
</div>
|
||||
<style>
|
||||
.backup_table { margin:15px 0; border:none; border-collapse:collapse; border-spacing:0; font-size:100%; width: 100%;}
|
||||
.backup_table th, .stand_table td { padding:3px 4px; border: 1px solid #cdcdcd; }
|
||||
.backup_table th { text-align:center; font-weight:bold; border: 1px solid #cdcdcd; background:#f9efcf; }
|
||||
.backup_table .last_update { text-align:right; font-size:75%; border:none; }
|
||||
.backup_table .stand:hover { background:#f6faf2; }
|
||||
.backup_table .col_title { width:120px; }
|
||||
</style>
|
||||
<table class="backup_table">
|
||||
<tr>
|
||||
<th colspan="8" style="text-align:left;">Задания бэкапа:</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th abbr="ACTION">Бэкапирование</th>
|
||||
<th abbr="BACKUP_DATE">Дата выполнения</th>
|
||||
<th abbr="END_TIME">Время завершения</th>
|
||||
</tr>
|
||||
${props.collect { prop ->
|
||||
def idx = props.findIndexOf { it.equals(prop) }
|
||||
return """ <tr class="mail">
|
||||
<td abbr="ACTION">${prop.ACTION}</td>
|
||||
<td abbr="BACKUP_DATE">${prop.BACKUP_DATE}</td>
|
||||
<td abbr="END_TIME">${prop.END_TIME}</td>
|
||||
</tr>"""
|
||||
}.join('')}
|
||||
|
||||
|
||||
</table>
|
||||
<br/>
|
||||
<br/>
|
||||
<br/>При запуске необходимо указать параметры:
|
||||
<br/>
|
||||
<ul>
|
||||
<li>
|
||||
<b>ACTION</b> - выполняемое действие (ALL, 1CDB, WORK)
|
||||
<ul>
|
||||
<li>
|
||||
<b>ALL</b> - Выполнение всех задач, планировщик делает по умолчанию в выходной
|
||||
</li>
|
||||
<li>
|
||||
<b>1CDB</b> - Бэкап Баз Данных 1С, после выполнения, архив доступен для скачки по ссылке
|
||||
</li>
|
||||
<li>
|
||||
<b>KD</b> - Бэкап Конструкторской документации
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<b>Бэкапы тут</b> - <a href="\\\\1CSRV.domen\\Backup">\\\\1CSRV.domen\\Backup</a>
|
||||
</li>
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user