pipelines zip and gdrive upload

updated
This commit is contained in:
dzaitsev
2025-05-07 19:25:30 +03:00
parent 64c99d88ec
commit f7dd087fad
+38 -34
View File
@@ -92,48 +92,52 @@ pipeline {
}
}
stage('Cleanup Older Files on Google Drive') {
when {
expression { return env.LATEST_ZIP_FILENAME?.trim() }
}
steps {
echo "Cleaning up older files on Google Drive..."
powershell """
Write-Output "Listing all files in the folder ${env.GOOGLE_DRIVE_FOLDER} on Google Drive..."
\$files = rclone lsf --files-only AzaionGoogleDrive:${env.GOOGLE_DRIVE_FOLDER}
Write-Output "Files found on Google Drive:"
Write-Output \$files
stage('Cleanup Older Files on Google Drive') {
when {
expression { return env.LATEST_ZIP_FILENAME?.trim() }
}
steps {
echo "Cleaning up older files on Google Drive..."
powershell """
Write-Output "Listing all files in the folder ${params.GOOGLE_DRIVE_FOLDER} on Google Drive..."
\$files = rclone lsf --files-only AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER}
Write-Output "Files found on Google Drive:"
Write-Output \$files
\$filesArray = \$files -split "`n" | Where-Object { \$_ -ne "" }
if (\$filesArray.Count -gt 3) {
\$filesSorted = \$filesArray | Sort-Object -Descending
\$filesToDelete = \$filesSorted | Select-Object -Skip 3
\$filesArray = \$files -split "`n" | Where-Object { \$_ -ne "" }
# Exclude the latest zip file from deletion
\$latestFile = "${env.LATEST_ZIP_FILENAME}"
\$filesArray = \$filesArray | Where-Object { \$_ -ne \$latestFile }
Write-Output "Files to delete (older than 3 latest):"
Write-Output \$filesToDelete
if (\$filesArray.Count -gt 3) {
\$filesSorted = \$filesArray | Sort-Object -Descending
\$filesToDelete = \$filesSorted | Select-Object -Skip 3
if (\$filesToDelete.Count -gt 0) {
\$tempFile = [System.IO.Path]::GetTempFileName()
\$filesToDelete | Set-Content -Path \$tempFile -Encoding utf8
Write-Output "Files to delete (older than 3 latest):"
Write-Output \$filesToDelete
Write-Output "Contents of temporary delete list file (\$tempFile):"
Get-Content \$tempFile
if (\$filesToDelete.Count -gt 0) {
\$tempFile = [System.IO.Path]::GetTempFileName()
\$filesToDelete | Set-Content -Path \$tempFile -Encoding utf8
foreach (\$file in \$filesToDelete) {
Write-Output "Deleting \$file..."
rclone deletefile AzaionGoogleDrive:${env.GOOGLE_DRIVE_FOLDER}/\$file
}
Write-Output "Contents of temporary delete list file (\$tempFile):"
Get-Content \$tempFile
Remove-Item -Path \$tempFile
} else {
Write-Output "No files to delete."
}
} else {
Write-Output "No files found on Google Drive to clean up."
foreach (\$file in \$filesToDelete) {
Write-Output "Deleting \$file..."
rclone deletefile AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER}/\$file
}
"""
Remove-Item -Path \$tempFile
} else {
Write-Output "No files to delete."
}
} else {
Write-Output "No files found on Google Drive to clean up."
}
}
"""
}
}
}
post {