latest fixes for Gdrive upload

This commit is contained in:
dzaitsev
2025-05-04 18:52:08 +03:00
parent 1acfab9b87
commit 961c750f1f
+17 -9
View File
@@ -32,29 +32,34 @@ pipeline {
echo "Finding latest zip file..." echo "Finding latest zip file..."
dir("C:/Jenkins/workspace/AzaionSuite/suite") { dir("C:/Jenkins/workspace/AzaionSuite/suite") {
def output = powershell(returnStdout: true, script: ''' def output = powershell(returnStdout: true, script: '''
$pattern = "AzaionSuite.*-*-*.zip" $pattern = "AzaionSuite*-*-*.zip"
$zipFiles = Get-ChildItem -Filter $pattern | Sort-Object Name -Descending $zipFiles = Get-ChildItem -Filter $pattern | Sort-Object Name -Descending
if ($zipFiles.Count -eq 0) { if ($zipFiles.Count -gt 0) {
Write-Error "No ZIP files matching pattern '$pattern' were found."
exit 1
}
$latestZip = $zipFiles[0].Name $latestZip = $zipFiles[0].Name
Write-Output "::SET-ENV::LATEST_ZIP_FILENAME=$latestZip" Write-Output "::SET-ENV::LATEST_ZIP_FILENAME=$latestZip"
} else {
Write-Output "::SET-ENV::LATEST_ZIP_FILENAME="
}
''').trim() ''').trim()
def match = output =~ /::SET-ENV::LATEST_ZIP_FILENAME=(.+)/ def match = output =~ /::SET-ENV::LATEST_ZIP_FILENAME=(.+)/
if (!match) { if (!match || !match[0][1]?.trim()) {
error("Could not find the latest zip filename in the PowerShell output using marker.") echo "⚠️ No ZIP files matching the pattern were found. Skipping upload and cleanup stages."
} env.LATEST_ZIP_FILENAME = ''
} else {
def zipFileName = match[0][1] def zipFileName = match[0][1]
echo "Latest zip file selected: ${zipFileName}" echo "Latest zip file selected: ${zipFileName}"
env.LATEST_ZIP_FILENAME = zipFileName env.LATEST_ZIP_FILENAME = zipFileName
} }
} }
} }
} }
}
stage('Upload If Not Exists & Always Remove Local') { stage('Upload If Not Exists & Always Remove Local') {
when {
expression { return env.LATEST_ZIP_FILENAME?.trim() }
}
steps { steps {
echo "Checking Google Drive for existing ZIP and uploading if needed..." echo "Checking Google Drive for existing ZIP and uploading if needed..."
powershell """ powershell """
@@ -87,6 +92,9 @@ pipeline {
} }
stage('Cleanup Older Files on Google Drive') { stage('Cleanup Older Files on Google Drive') {
when {
expression { return env.LATEST_ZIP_FILENAME?.trim() }
}
steps { steps {
echo "Cleaning up older files on Google Drive..." echo "Cleaning up older files on Google Drive..."
powershell """ powershell """