Update Jenkinsfile

This commit is contained in:
AlexandrKharitonov 2021-12-06 17:43:41 +03:00
parent 0eed0e7d16
commit 17de3bbf2c

86
.jenkins/Jenkinsfile vendored
View File

@ -1,18 +1,18 @@
println("Job name: ${JOB_NAME}") println("Job name: ${JOB_NAME}")
switch(JOB_NAME) { switch(JOB_NAME) {
case "production.helpcenter.onlyoffice.com.pl": case "production.helpcenter.onlyoffice.com.pl":
DESTSITE = 'helpcenter.teamlab.com' DESTSITE = 'helpcenter.teamlab.com'
DESTHOST = '54.186.188.62' DESTHOST = '54.186.188.62'
MONITOR_ID = '58439000008116012' MONITOR_ID = '58439000008116012'
break break
case "release.test-helpcenter.onlyoffice.pl": case "release.test-helpcenter.onlyoffice.pl":
DESTSITE = 'test-helpcenter.teamlab.com' DESTSITE = 'test-helpcenter.teamlab.com'
DESTHOST = '54.186.188.62' DESTHOST = '54.186.188.62'
break break
default: default:
println("JOB: ${JOB_NAME} not known.") println("JOB: ${JOB_NAME} not known.")
System.exit(1) System.exit(1)
} }
println("SITE: ${DESTSITE}") println("SITE: ${DESTSITE}")
@ -27,17 +27,17 @@ pipeline {
choice(name: 'DEPLOY', choices: ['False','True'],description: 'Run deploy? Set "True" to run, "False" to update job') choice(name: 'DEPLOY', choices: ['False','True'],description: 'Run deploy? Set "True" to run, "False" to update job')
} }
stages { stages {
stage('build') { stage('build') {
when { expression { return env.DEPLOY == "True" } } when { expression { return env.DEPLOY == "True" } }
environment { environment {
DESTSITE = "${DESTSITE}" DESTSITE = "${DESTSITE}"
DESTHOST = "${DESTHOST}" DESTHOST = "${DESTHOST}"
} }
steps { steps {
withCredentials([usernamePassword(credentialsId: 'jenkins_user_api', withCredentials([usernamePassword(credentialsId: 'jenkins_user_api',
passwordVariable: 'jenkins_token', passwordVariable: 'jenkins_token',
usernameVariable: 'jenkins_user')]) usernameVariable: 'jenkins_user')])
{ {
powershell ''' powershell '''
$ErrorActionPreference='Stop' $ErrorActionPreference='Stop'
(get-content Web\\web.config) | %{$_ -replace '<rule name="pages HTTP to HTTPS" enabled="false" stopProcessing="true">', '<rule name="pages HTTP to HTTPS" enabled="true" stopProcessing="true">'} | set-content Web\\web.config (get-content Web\\web.config) | %{$_ -replace '<rule name="pages HTTP to HTTPS" enabled="false" stopProcessing="true">', '<rule name="pages HTTP to HTTPS" enabled="true" stopProcessing="true">'} | set-content Web\\web.config
@ -61,39 +61,39 @@ pipeline {
echo " == Precompile == " echo " == Precompile == "
%aspnetmerge% "%WORKSPACE%\\Precompiled" -w ASC.dll %aspnetmerge% "%WORKSPACE%\\Precompiled" -w ASC.dll
''' '''
} }
} }
} }
stage('stop_monitor') { stage('stop_monitor') {
when { when {
allOf { expression { return env.DEPLOY == "True" }; expression { return env.JOB_NAME == 'production.helpcenter.onlyoffice.com.pl' } } allOf { expression { return env.DEPLOY == "True" }; expression { return env.JOB_NAME == 'production.helpcenter.onlyoffice.com.pl' } }
} }
steps { steps {
build job: 'monitor.24x7.start.stop', build job: 'monitor.24x7.start.stop',
parameters: [string(name: 'monitor_id', value: "${MONITOR_ID}"), parameters: [string(name: 'monitor_id', value: "${MONITOR_ID}"),
string(name: 'action', value: 'suspend')] string(name: 'action', value: 'suspend')]
} }
} }
stage('deploy') { stage('deploy') {
when { expression { return env.DEPLOY == "True" } } when { expression { return env.DEPLOY == "True" } }
environment { environment {
DESTSITE = "${DESTSITE}" DESTSITE = "${DESTSITE}"
DESTHOST = "${DESTHOST}" DESTHOST = "${DESTHOST}"
} }
steps { steps {
withCredentials([usernamePassword(credentialsId: 'sites.onlyoffice.com_21H1', withCredentials([usernamePassword(credentialsId: 'sites.onlyoffice.com_21H1',
passwordVariable: 'deploymentpass', passwordVariable: 'deploymentpass',
usernameVariable: 'deploymentuser')]) usernameVariable: 'deploymentuser')])
{ {
bat ''' bat '''
echo " == Deploy == " echo " == Deploy == "
%msdeployv2% -verb:sync -source:iisapp="%WORKSPACE%\\Precompiled" -dest:iisapp="%DESTSITE%",computerName="%DESTHOST%",username=%deploymentuser%,password=%deploymentpass% -preSync:runCommand="%WORKSPACE%\\sync.bat",waitInterval=120000 -postSync:runCommand="%WORKSPACE%\\sync.bat",waitInterval=120000 %msdeployv2% -verb:sync -source:iisapp="%WORKSPACE%\\Precompiled" -dest:iisapp="%DESTSITE%",computerName="%DESTHOST%",username=%deploymentuser%,password=%deploymentpass% -preSync:runCommand="%WORKSPACE%\\sync.bat",waitInterval=120000 -postSync:runCommand="%WORKSPACE%\\sync.bat",waitInterval=120000
''' '''
} }
} }
} }
stage('notify telegram') { stage('notify telegram') {
when { when {
@ -102,7 +102,7 @@ pipeline {
steps { steps {
withCredentials([string(credentialsId: 'chat_dep_automation_operation', variable: 'TEL_CHAT'), withCredentials([string(credentialsId: 'chat_dep_automation_operation', variable: 'TEL_CHAT'),
string(credentialsId: 'token_bot_jenkins_notifier', variable: 'TEL_TOKEN')]) string(credentialsId: 'token_bot_jenkins_notifier', variable: 'TEL_TOKEN')])
{ {
powershell ''' powershell '''
$MESSAGE = "helpcenter.onlyoffice.com is deployed." $MESSAGE = "helpcenter.onlyoffice.com is deployed."
$TOKEN = "$Env:TEL_TOKEN" $TOKEN = "$Env:TEL_TOKEN"
@ -115,11 +115,11 @@ pipeline {
} }
} }
} }
stage('start_monitor') { stage('start_monitor') {
when { when {
allOf { expression { return env.DEPLOY == "True" }; expression { return env.JOB_NAME == 'production.helpcenter.onlyoffice.com.pl' } } allOf { expression { return env.DEPLOY == "True" }; expression { return env.JOB_NAME == 'production.helpcenter.onlyoffice.com.pl' } }
} }
steps { steps {
powershell ''' powershell '''
[int]$statusCode = 0 [int]$statusCode = 0
@ -140,12 +140,12 @@ pipeline {
} }
Write-Host "helpcenter.onlyoffice.com do not available after deploy within 30 minutes" Write-Host "helpcenter.onlyoffice.com do not available after deploy within 30 minutes"
''' '''
build job: 'monitor.24x7.start.stop', build job: 'monitor.24x7.start.stop',
parameters: [string(name: 'monitor_id', value: "${MONITOR_ID}"), parameters: [string(name: 'monitor_id', value: "${MONITOR_ID}"),
string(name: 'action', value: 'activate')] string(name: 'action', value: 'activate')]
} }
} }
} }
} }