diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index 8cd44f6..dff3731 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -74,6 +74,27 @@ pipeline { """ } } + + stage('Cleanup Older Files on Google Drive') { + steps { + echo "Cleaning up older files on Google Drive..." + powershell """ + # Get the list of files in the Google Drive folder + \$files = rclone lsf --files-only --dirs-only --max-depth 1 AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --format "tp" | Sort-Object -Descending + + # Keep only the 3 latest files + \$filesToDelete = \$files | Select-Object -Skip 3 + + # If there are files to delete, remove them + if (\$filesToDelete.Count -gt 0) { + Write-Output "Deleting files: \$filesToDelete" + rclone delete AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --files-from <(echo \$filesToDelete) --drive-chunk-size 64M + } else { + Write-Output "No files to delete." + } + """ + } + } } post {