From 838cd1b8ecfecc9519cf894d29859076fa47364a Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 15:18:50 +0300 Subject: [PATCH] gdrive update1 --- build/jenkins/GDriveUpload | 60 +++++++++++++++----------------------- 1 file changed, 24 insertions(+), 36 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index 449261c..6b629c2 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -75,50 +75,38 @@ pipeline { } } - stage('Cleanup Older Files on Google Drive') { - steps { - echo "Cleaning up older files on Google Drive..." - powershell """ - # List all files in the Google Drive folder - 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} --format "tp" --max-depth 1 - Write-Output "Files found on Google Drive:" - Write-Output \$files + stage('Cleanup Older Files on Google Drive') { + steps { + echo "Cleaning up older files on Google Drive..." + powershell """ + # List all files in the Google Drive folder (only filenames) + 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 - # If files were found - if (\$files.Count -gt 0) { - # Sort the files by date in descending order - \$filesSorted = \$files | Sort-Object -Descending + # Convert to array and sort by name descending (adjust if you want date sorting) + \$filesArray = \$files -split "`n" | Where-Object { \$_ -ne "" } | Sort-Object -Descending - # Keep only the 3 latest files - \$filesToDelete = \$filesSorted | Select-Object -Skip 3 + # Keep only the 3 latest files + \$filesToDelete = \$filesArray | Select-Object -Skip 3 - Write-Output "Files to delete (older than 3 latest):" - Write-Output \$filesToDelete + Write-Output "Files to delete (older than 3 latest):" + Write-Output \$filesToDelete - # If there are files to delete, remove them - if (\$filesToDelete.Count -gt 0) { - Write-Output "Deleting files: \$filesToDelete" + if (\$filesToDelete.Count -gt 0) { + \$tempFile = [System.IO.Path]::GetTempFileName() + \$filesToDelete | Out-File -FilePath \$tempFile -Encoding utf8 - # Create a temporary file to store the list of files to delete - \$tempFile = [System.IO.Path]::GetTempFileName() - \$filesToDelete | Out-File -FilePath \$tempFile -Encoding utf8 + rclone delete AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --files-from \$tempFile --drive-chunk-size 64M - # Use rclone to delete the files - rclone delete AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --files-from \$tempFile --drive-chunk-size 64M - - # Clean up the temporary file - Remove-Item -Path \$tempFile - } else { - Write-Output "No files to delete." - } - } else { - Write-Output "No files found on Google Drive to clean up." - } - """ + Remove-Item -Path \$tempFile + } else { + Write-Output "No files to delete." } - } + """ } +} post { always {