Update Jenkinsfile
This commit is contained in:
parent
f9af97f86c
commit
6cd83ba19e
188
Jenkinsfile
vendored
188
Jenkinsfile
vendored
@ -1,21 +1,22 @@
|
||||
pipeline {
|
||||
agent { label 'master' }
|
||||
agent none
|
||||
triggers {
|
||||
githubPush()
|
||||
}
|
||||
options {
|
||||
disableConcurrentBuilds()
|
||||
buildDiscarder (logRotator(numToKeepStr: '3', artifactNumToKeepStr: '3'))
|
||||
}
|
||||
}
|
||||
stages {
|
||||
stage('test_deploy') {
|
||||
agent { label 'master' }
|
||||
when {
|
||||
branch 'test_deploy'
|
||||
}
|
||||
environment {
|
||||
DESTSITE = 'testdeploy'
|
||||
DESTHOST = '18.224.174.2'
|
||||
LETTER = 'U:'
|
||||
LETTER = 'I:'
|
||||
}
|
||||
steps {
|
||||
withCredentials([
|
||||
@ -25,14 +26,14 @@ pipeline {
|
||||
bat '''
|
||||
if not exist %LETTER% subst %LETTER% %WORKSPACE%
|
||||
'''
|
||||
bat '''
|
||||
echo " == Build == "
|
||||
%msbuild% %LETTER%\\publish.proj /t:PrecompileWeb
|
||||
'''
|
||||
powershell '''
|
||||
$ErrorActionPreference='Stop'
|
||||
(get-content sync.bat) | %{$_ -replace "%poolname%", "$Env:DESTSITE"} | set-content sync.bat
|
||||
'''
|
||||
bat '''
|
||||
echo " == Build == "
|
||||
%msbuild% %LETTER%\\publish.proj /t:PrecompileWeb
|
||||
'''
|
||||
bat '''
|
||||
echo " == Deploy == "
|
||||
%msdeployv2% -verb:sync -source:iisapp="%LETTER%\\Precompiled" -dest:iisapp="%DESTSITE%",computerName="%DESTHOST%",username=%deploymentuser%,password=%deploymentpass% -preSync:runCommand="%LETTER%\\sync.bat",waitInterval=120000 -postSync:runCommand="%LETTER%\\sync.bat",waitInterval=120000
|
||||
@ -41,10 +42,74 @@ pipeline {
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('production_deploy') {
|
||||
stage('stop_monitor') {
|
||||
agent { label 'ubuntu' }
|
||||
when {
|
||||
branch 'production_deploy'
|
||||
}
|
||||
steps {
|
||||
withCredentials([
|
||||
string(credentialsId: 'monitor_rtoken_helpcenter', variable: 'monitor_rtoken'),
|
||||
string(credentialsId: 'monitor_token_helpcenter', variable: 'monitor_token'),
|
||||
string(credentialsId: 'monitor_clientid_helpcenter', variable: 'monitor_clientid'),
|
||||
string(credentialsId: 'monitor_secret_helpcenter', variable: 'monitor_secret'),
|
||||
])
|
||||
{
|
||||
sh '''
|
||||
#!/bin/bash
|
||||
monitor=58439000004453003
|
||||
clientid=$monitor_clientid
|
||||
secret=$monitor_secret
|
||||
|
||||
#generated with scope Site24x7.Operations.All
|
||||
token=$monitor_token
|
||||
|
||||
#pasted from function get_refresh_token
|
||||
rtoken=$monitor_rtoken
|
||||
|
||||
get_access_token () {
|
||||
access_token=$(curl https://accounts.zoho.com/oauth/v2/token \
|
||||
-X POST \
|
||||
-d "client_id=$clientid" \
|
||||
-d "client_secret=$secret" \
|
||||
-d "refresh_token=$rtoken"\
|
||||
-d "grant_type=refresh_token" \
|
||||
| cut -d '"' -f4)
|
||||
}
|
||||
|
||||
activate_monitor () {
|
||||
get_access_token
|
||||
curl https://www.site24x7.com/api/monitors/activate/$monitor \
|
||||
-X PUT \
|
||||
-H "Accept: application/json; version=2.0" \
|
||||
-H "Authorization: Zoho-oauthtoken $access_token"
|
||||
}
|
||||
|
||||
suspend_monitor () {
|
||||
get_access_token
|
||||
curl https://www.site24x7.com/api/monitors/suspend/$monitor \
|
||||
-X PUT \
|
||||
-H "Accept: application/json; version=2.0" \
|
||||
-H "Authorization: Zoho-oauthtoken $access_token"
|
||||
}
|
||||
|
||||
#activate_monitor
|
||||
suspend_monitor
|
||||
|
||||
#get env rtoken
|
||||
#curl https://accounts.zoho.com/oauth/v2/token -X POST -d "client_id=$clientid" -d "client_secret=$secret" -d "code=$token" -d "grant_type=authorization_code"
|
||||
|
||||
'''
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('production_deploy') {
|
||||
agent { label 'master' }
|
||||
when {
|
||||
branch 'production_deploy'
|
||||
}
|
||||
|
||||
environment {
|
||||
DESTSITE = 'testproddeploy'
|
||||
DESTHOST = '18.224.174.2'
|
||||
@ -52,13 +117,10 @@ pipeline {
|
||||
}
|
||||
steps {
|
||||
withCredentials([
|
||||
usernamePassword(credentialsId: 'deploymentuser_pass', usernameVariable: 'deploymentuser', passwordVariable: 'deploymentpass')
|
||||
usernamePassword(credentialsId: 'deploymentuser_pass', usernameVariable: 'deploymentuser', passwordVariable: 'deploymentpass'),
|
||||
string(credentialsId: 'chat_dep_automation_operation', variable: 'TEL_CHAT'),
|
||||
string(credentialsId: 'token_bot_jenkins_notifier', variable: 'TEL_TOKEN')
|
||||
])
|
||||
sshPublisher(publishers: [sshPublisherDesc(configName: 'aggregator@guru.info', \
|
||||
transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: "/bin/bash ~/deploy/uptime.sh >> ~/deploy/bash.log", \
|
||||
execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', \
|
||||
remoteDirectorySDF: false, removePrefix: 'testdeploy/scripts/', sourceFiles: 'testdeploy\\scripts\\uptime.sh')], \
|
||||
usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
|
||||
{
|
||||
bat '''
|
||||
if not exist %LETTER% subst %LETTER% %WORKSPACE%
|
||||
@ -77,23 +139,105 @@ pipeline {
|
||||
%msdeployv2% -verb:sync -source:iisapp="%LETTER%\\Precompiled" -dest:iisapp="%DESTSITE%",computerName="%DESTHOST%",username=%deploymentuser%,password=%deploymentpass% -preSync:runCommand="%LETTER%\\sync.bat",waitInterval=120000 -postSync:runCommand="%LETTER%\\sync.bat",waitInterval=120000
|
||||
'''
|
||||
bat 'subst %LETTER% /D'
|
||||
|
||||
powershell '''
|
||||
$MESSAGE = "helpcenter.onlyoffice.com is deployed."
|
||||
$TOKEN = "1341043651:AAGjwG5Wv4eo075KK_uvhZtw1fzWGH8NlU8"
|
||||
$CHAT_ID = "-1001346473906"
|
||||
$TOKEN = "$Env:TEL_TOKEN"
|
||||
$CHAT_ID = "$Env:TEL_CHAT"
|
||||
$URL = "https://api.telegram.org/bot$TOKEN/sendMessage"
|
||||
|
||||
#Invoke-WebRequest -Uri $URL -Body @{chat_id=$CHAT_ID; text=$MESSAGE} -UseBasicParsing
|
||||
'''
|
||||
}
|
||||
sshPublisher(publishers: [sshPublisherDesc(configName: 'aggregator@guru.info', \
|
||||
transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: "/bin/bash ~/deploy/uptime.sh >> ~/deploy/bash.log", \
|
||||
execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', \
|
||||
remoteDirectorySDF: false, removePrefix: 'testdeploy/scripts/', sourceFiles: 'testdeploy\\scripts\\uptime.sh')], \
|
||||
usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
|
||||
}
|
||||
}
|
||||
|
||||
stage('start_monitor') {
|
||||
agent { label 'ubuntu' }
|
||||
when {
|
||||
branch 'production_deploy'
|
||||
}
|
||||
steps {
|
||||
withCredentials([
|
||||
string(credentialsId: 'monitor_rtoken_helpcenter', variable: 'monitor_rtoken'),
|
||||
string(credentialsId: 'monitor_token_helpcenter', variable: 'monitor_token'),
|
||||
string(credentialsId: 'monitor_clientid_helpcenter', variable: 'monitor_clientid'),
|
||||
string(credentialsId: 'monitor_secret_helpcenter', variable: 'monitor_secret'),
|
||||
])
|
||||
{
|
||||
sh '''
|
||||
#!/bin/bash
|
||||
monitor=58439000004453003
|
||||
clientid=$monitor_clientid
|
||||
secret=$monitor_secret
|
||||
|
||||
#generated with scope Site24x7.Operations.All
|
||||
token=$monitor_token
|
||||
|
||||
#pasted from function get_refresh_token
|
||||
rtoken=$monitor_rtoken
|
||||
|
||||
get_access_token () {
|
||||
access_token=$(curl https://accounts.zoho.com/oauth/v2/token \
|
||||
-X POST \
|
||||
-d "client_id=$clientid" \
|
||||
-d "client_secret=$secret" \
|
||||
-d "refresh_token=$rtoken"\
|
||||
-d "grant_type=refresh_token" \
|
||||
| cut -d '"' -f4)
|
||||
}
|
||||
|
||||
activate_monitor () {
|
||||
get_access_token
|
||||
curl https://www.site24x7.com/api/monitors/activate/$monitor \
|
||||
-X PUT \
|
||||
-H "Accept: application/json; version=2.0" \
|
||||
-H "Authorization: Zoho-oauthtoken $access_token"
|
||||
}
|
||||
|
||||
suspend_monitor () {
|
||||
get_access_token
|
||||
curl https://www.site24x7.com/api/monitors/suspend/$monitor \
|
||||
-X PUT \
|
||||
-H "Accept: application/json; version=2.0" \
|
||||
-H "Authorization: Zoho-oauthtoken $access_token"
|
||||
}
|
||||
|
||||
#get env rtoken
|
||||
#curl https://accounts.zoho.com/oauth/v2/token -X POST -d "client_id=$clientid" -d "client_secret=$secret" -d "code=$token" -d "grant_type=authorization_code"
|
||||
|
||||
|
||||
check_site_status () {
|
||||
if curl -s --head --request GET https://helpcenter.onlyoffice.com | grep "200 OK" > /dev/null; then
|
||||
echo `date`
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# === MAIN ===
|
||||
# check i=30 minuts
|
||||
for ((i=30; i>0 ; i--))
|
||||
do
|
||||
if check_site_status; then
|
||||
activate_monitor
|
||||
exit 0
|
||||
else
|
||||
sleep 60
|
||||
fi
|
||||
done
|
||||
|
||||
# turn on monitor
|
||||
activate_monitor
|
||||
|
||||
# if site no returned 200
|
||||
echo "helpcenter.onlyoffice.com do not available after deploy within 30 minutes"
|
||||
exit 1
|
||||
'''
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user