Finish Hotfix-1
All checks were successful
IntegryManagementSystem_Multi/pipeline/head This commit looks good
All checks were successful
IntegryManagementSystem_Multi/pipeline/head This commit looks good
This commit is contained in:
122
build/Jenkinsfile.groovy
Normal file
122
build/Jenkinsfile.groovy
Normal file
@@ -0,0 +1,122 @@
|
||||
pipeline {
|
||||
agent any
|
||||
stages {
|
||||
stage ('PreBuild Steps (Master)') {
|
||||
when {
|
||||
expression {
|
||||
return env.GIT_BRANCH == "origin/master"
|
||||
}
|
||||
}
|
||||
steps {
|
||||
echo "Creo version tag su Git"
|
||||
bat 'build\\create_build_tag.bat'
|
||||
}
|
||||
}
|
||||
stage('Maven Build') {
|
||||
steps {
|
||||
echo "${WORKSPACE}"
|
||||
withMaven(jdk: 'JDK 17.0.6 x64', traceability: true, maven: 'Maven 3.9.5') {
|
||||
bat(script: 'mvn clean install -t toolchains-jenkins.xml', returnStdout: true)
|
||||
archiveArtifacts(artifacts: 'ems-engine/target/*.war*', onlyIfSuccessful: true)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
stage('Publish Develop') {
|
||||
when {
|
||||
expression {
|
||||
return env.GIT_BRANCH == "origin/develop"
|
||||
}
|
||||
}
|
||||
parallel {
|
||||
stage('Tomcat update') {
|
||||
stages {
|
||||
stage('Update Tomcat 1') {
|
||||
steps {
|
||||
echo "Updating Tomcat9 from ${WORKSPACE}"
|
||||
powershell returnStdout: true, script: "build\\update_tomcat.ps1 -serviceName \"Tomcat9\" -httpPort \"8081\" -updatedArtifactPath \"${WORKSPACE}\\ems-engine\\target\\ems-api.war\""
|
||||
}
|
||||
}
|
||||
stage('Update Tomcat 2') {
|
||||
steps {
|
||||
echo "Updating Tomcat9 from ${WORKSPACE}"
|
||||
powershell returnStdout: true, script: "build\\update_tomcat.ps1 -serviceName \"Tomcat9Backup\" -httpPort \"8082\" -updatedArtifactPath \"${WORKSPACE}\\ems-engine\\target\\ems-api.war\""
|
||||
bat 'curl -k https://devservices.studioml.it/ems-api/updateWMSApp'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Publish over FTP') {
|
||||
steps {
|
||||
echo "Publish over FTP"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Publish Master') {
|
||||
when {
|
||||
expression {
|
||||
return env.GIT_BRANCH == "origin/master"
|
||||
}
|
||||
}
|
||||
parallel {
|
||||
stage('Tomcat update') {
|
||||
stages {
|
||||
stage('Update Tomcat 1') {
|
||||
steps {
|
||||
echo "Updating Tomcat9 from ${WORKSPACE}"
|
||||
sshPublisher(publishers: [sshPublisherDesc(configName: 'Production Linux Tomcat Server (192.168.3.16)', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: '''sudo /usr/bin/systemctl stop tomcat9
|
||||
rm -R tomcat9/webapps/ems-api
|
||||
sudo /usr/bin/systemctl start tomcat9
|
||||
|
||||
/home/studioml/./wait_tomcat_startup.sh 8081''', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '/tomcat9/webapps', remoteDirectorySDF: false, removePrefix: 'ems-engine/target/', sourceFiles: 'ems-engine/target/*.war*')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
|
||||
}
|
||||
}
|
||||
stage('Update Tomcat 2') {
|
||||
steps {
|
||||
echo "Updating Tomcat9 from ${WORKSPACE}"
|
||||
sshPublisher(publishers: [sshPublisherDesc(configName: 'Production Linux Tomcat Server (192.168.3.16)', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: '''sudo /usr/bin/systemctl stop tomcat9backup
|
||||
rm -R tomcat9backup/webapps/ems-api
|
||||
sudo /usr/bin/systemctl start tomcat9backup
|
||||
|
||||
/home/studioml/./wait_tomcat_startup.sh 8082
|
||||
|
||||
sleep 10''', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '/tomcat9backup/webapps', remoteDirectorySDF: false, removePrefix: 'ems-engine/target/', sourceFiles: 'ems-engine/target/*.war*')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
|
||||
bat 'curl -k https://services.studioml.it/ems-api/updateWMSApp'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Publish over FTP') {
|
||||
steps {
|
||||
ftpPublisher alwaysPublishFromMaster: false,
|
||||
continueOnError: false,
|
||||
failOnError: false,
|
||||
masterNodeName: '',
|
||||
paramPublish: null,
|
||||
publishers: [[configName: 'OVH Linux Web Server (51.38.112.23)',
|
||||
transfers: [[asciiMode: false,
|
||||
cleanRemote: false,
|
||||
excludes: '',
|
||||
flatten: false,
|
||||
makeEmptyDirs: false,
|
||||
noDefaultExcludes: false,
|
||||
patternSeparator: '[, ]+',
|
||||
remoteDirectory: '/download/Aggiornamenti',
|
||||
remoteDirectorySDF: false,
|
||||
removePrefix: 'ems-engine/target/',
|
||||
sourceFiles: 'ems-engine/target/*.war*']],
|
||||
usePromotionTimestamp: false,
|
||||
useWorkspaceInPromotion: false,
|
||||
verbose: true]]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
43
build/create_build_tag.bat
Normal file
43
build/create_build_tag.bat
Normal file
@@ -0,0 +1,43 @@
|
||||
REM SET YEAR
|
||||
set YEAR=%date:~6,4%
|
||||
|
||||
REM SET MONTH
|
||||
set MONTH=%date:~3,2%
|
||||
if %MONTH% LSS 10 set MONTH=%MONTH:~1,2%
|
||||
if %MONTH% LSS 10 set MONTH=0%MONTH%
|
||||
|
||||
REM SET DAY
|
||||
set DAY=%date:~0,2%
|
||||
if %DAY% LSS 10 set DAY=%DAY:~1,2%
|
||||
if %DAY% LSS 10 set DAY=0%DAY%
|
||||
|
||||
REM SET HOUR
|
||||
set HOUR=%time:~0,2%
|
||||
if %HOUR% LSS 10 set HOUR=%HOUR:~1,2%
|
||||
if %HOUR% LSS 10 set HOUR=0%HOUR%
|
||||
|
||||
REM SET MINUTE
|
||||
set MINUTE=%time:~3,2%
|
||||
if %MINUTE% LSS 10 set MINUTE=%MINUTE:~1,2%
|
||||
if %MINUTE% LSS 10 set MINUTE=0%MINUTE%
|
||||
|
||||
REM SET SECOND
|
||||
set SECOND=%time:~6,2%
|
||||
if %SECOND% LSS 10 set SECOND=%SECOND:~1,2%
|
||||
if %SECOND% LSS 10 set SECOND=0%SECOND%
|
||||
|
||||
set mydate=%YEAR%%MONTH%%DAY%_%HOUR%%MINUTE%%SECOND%
|
||||
|
||||
|
||||
|
||||
echo #spring.profiles.active=@activatedProperties@ > ems-core\src\main\resources\configs\env.properties
|
||||
echo project.version=%mydate% >> ems-core\src\main\resources\configs\env.properties
|
||||
|
||||
|
||||
git add . -A
|
||||
git commit -m "%mydate%"
|
||||
git tag "%mydate%"
|
||||
|
||||
|
||||
git push https://git.studioml.it/Integry/IntegryManagementSystem.git --tags
|
||||
git push https://git.studioml.it/Integry/IntegryManagementSystem.git --all
|
||||
153
build/update_tomcat.ps1
Normal file
153
build/update_tomcat.ps1
Normal file
@@ -0,0 +1,153 @@
|
||||
Param(
|
||||
[string]$serviceName, #Argomento passato dal chiamante
|
||||
[Int32]$httpPort, #Argomento passato dal chiamante
|
||||
[string]$updatedArtifactPath #Argomento passato dal chiamante
|
||||
)
|
||||
|
||||
$max_attempts = 48
|
||||
$attempt = 0
|
||||
$webappsPath = "C:\Program Files\$serviceName\webapps"
|
||||
|
||||
# Funzione per eseguire la chiamata GET e controllare lo status code
|
||||
function Check-Status {
|
||||
try {
|
||||
$request = Invoke-WebRequest -Uri "http://localhost:$httpPort/ems-api/system/ok" -Method Get -ErrorAction Stop
|
||||
$statusCode = $request.StatusCode
|
||||
if ($statusCode -eq 200) {
|
||||
Write-Host "Status code 200 ricevuto, processo completato."
|
||||
exit 0
|
||||
} else {
|
||||
Write-Host "Status code $statusCode ricevuto, continuo a provare..."
|
||||
}
|
||||
} catch {
|
||||
Write-Host "Errore: $_"
|
||||
}
|
||||
}
|
||||
|
||||
# Funzione per cancellare una cartella e un file
|
||||
function Delete-FilesAndFolder
|
||||
{
|
||||
param (
|
||||
[string]$folderPath,
|
||||
[string]$filePath
|
||||
)
|
||||
|
||||
try {
|
||||
# Cancellare la cartella specificata
|
||||
if (Test-Path -Path $folderPath) {
|
||||
Remove-Item -Path $folderPath -Recurse -Force
|
||||
Write-Host "Cartella $folderPath eliminata con successo."
|
||||
} else {
|
||||
Write-Host "La cartella $folderPath non esiste."
|
||||
}
|
||||
|
||||
# Cancellare il file specificato
|
||||
if (Test-Path -Path $filePath) {
|
||||
Remove-Item -Path $filePath -Force
|
||||
Write-Host "File $filePath eliminato con successo."
|
||||
} else {
|
||||
Write-Host "Il file $filePath non esiste."
|
||||
}
|
||||
|
||||
} catch {
|
||||
Write-Host "Errore nella cancellazione di file o cartella: $_"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
# Funzione per copiare un file
|
||||
function Copy-File {
|
||||
param (
|
||||
[string]$sourceFilePath,
|
||||
[string]$destinationFilePath
|
||||
)
|
||||
|
||||
try {
|
||||
if (Test-Path -Path $sourceFilePath) {
|
||||
Copy-Item -Path $sourceFilePath -Destination $destinationFilePath -Force
|
||||
Write-Host "File copiato da $sourceFilePath a $destinationFilePath con successo."
|
||||
} else {
|
||||
Write-Host "Il file sorgente $sourceFilePath non esiste."
|
||||
}
|
||||
} catch {
|
||||
Write-Host "Errore nella copia del file: $_"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
# Funzione per stoppare un servizio e attendere che sia completamente fermato
|
||||
function Stop-ServiceAndWait {
|
||||
param (
|
||||
[string]$serviceName
|
||||
)
|
||||
|
||||
# Tentativo di stoppare il servizio
|
||||
try {
|
||||
Write-Host "Sto stoppando il servizio $serviceName..."
|
||||
Stop-Service -Name $serviceName -Force
|
||||
|
||||
# Attesa finché il servizio non viene stoppato
|
||||
$service = Get-Service -Name $serviceName
|
||||
while ($service.Status -ne 'Stopped') {
|
||||
Write-Host "Attendo che il servizio $serviceName si fermi..."
|
||||
Start-Sleep -Seconds 5
|
||||
$service = Get-Service -Name $serviceName
|
||||
}
|
||||
|
||||
Write-Host "Il servizio $serviceName è stato fermato con successo."
|
||||
} catch {
|
||||
Write-Host "Errore nello stoppare il servizio ${serviceName}: $_"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
# Funzione per avviare nuovamente un servizio e attendere che sia in esecuzione
|
||||
function Start-ServiceAndWait {
|
||||
param (
|
||||
[string]$serviceName
|
||||
)
|
||||
|
||||
try {
|
||||
Write-Host "Sto avviando il servizio $serviceName..."
|
||||
Start-Service -Name $serviceName
|
||||
|
||||
# Attesa finché il servizio non viene avviato
|
||||
$service = Get-Service -Name $serviceName
|
||||
while ($service.Status -ne 'Running') {
|
||||
Write-Host "Attendo che il servizio $serviceName si avvii..."
|
||||
Start-Sleep -Seconds 5
|
||||
$service = Get-Service -Name $serviceName
|
||||
}
|
||||
|
||||
Write-Host "Il servizio $serviceName è stato avviato con successo."
|
||||
|
||||
} catch {
|
||||
Write-Host "Errore nell'avvio del servizio ${serviceName}: $_"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
# Chiamare la funzione per stoppare il servizio
|
||||
Stop-ServiceAndWait -serviceName $serviceName
|
||||
|
||||
# Subito dopo lo stop, cancellare la cartella e il file
|
||||
$emsApiPath = "$webappsPath\ems-api"
|
||||
$emsWarFilePath = "$webappsPath\ems-api.war"
|
||||
Delete-FilesAndFolder -folderPath $emsApiPath -filePath $emsWarFilePath
|
||||
|
||||
# Chiamare la funzione per copiare il file
|
||||
Write-Host "Copio $updatedArtifactPath in $emsWarFilePath"
|
||||
Copy-File -sourceFilePath $updatedArtifactPath -destinationFilePath $emsWarFilePath
|
||||
|
||||
# Avvia nuovamente il servizio
|
||||
Start-ServiceAndWait -serviceName $serviceName
|
||||
|
||||
# Ciclo fino a quando lo status code non è 200 o superiamo il numero massimo di tentativi
|
||||
while ($attempt -lt $max_attempts) {
|
||||
$attempt++
|
||||
Check-Status
|
||||
Start-Sleep -Seconds 5 # Attendere per 5 secondi prima di fare un altro tentativo
|
||||
}
|
||||
|
||||
Write-Host "Numero massimo di tentativi superato. Nessuna risposta 200 ricevuta."
|
||||
exit 1
|
||||
Reference in New Issue
Block a user