gdrive update1

This commit is contained in:
dzaitsev
2025-05-04 15:18:50 +03:00
parent bfe620d85e
commit 838cd1b8ec
+6 -18
View File
@@ -79,46 +79,34 @@ pipeline {
steps { steps {
echo "Cleaning up older files on Google Drive..." echo "Cleaning up older files on Google Drive..."
powershell """ powershell """
# List all files in the Google Drive folder # 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..." 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 \$files = rclone lsf --files-only AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER}
Write-Output "Files found on Google Drive:" Write-Output "Files found on Google Drive:"
Write-Output \$files Write-Output \$files
# If files were found # Convert to array and sort by name descending (adjust if you want date sorting)
if (\$files.Count -gt 0) { \$filesArray = \$files -split "`n" | Where-Object { \$_ -ne "" } | Sort-Object -Descending
# Sort the files by date in descending order
\$filesSorted = \$files | Sort-Object -Descending
# Keep only the 3 latest files # Keep only the 3 latest files
\$filesToDelete = \$filesSorted | Select-Object -Skip 3 \$filesToDelete = \$filesArray | Select-Object -Skip 3
Write-Output "Files to delete (older than 3 latest):" Write-Output "Files to delete (older than 3 latest):"
Write-Output \$filesToDelete Write-Output \$filesToDelete
# If there are files to delete, remove them
if (\$filesToDelete.Count -gt 0) { if (\$filesToDelete.Count -gt 0) {
Write-Output "Deleting files: \$filesToDelete"
# Create a temporary file to store the list of files to delete
\$tempFile = [System.IO.Path]::GetTempFileName() \$tempFile = [System.IO.Path]::GetTempFileName()
\$filesToDelete | Out-File -FilePath \$tempFile -Encoding utf8 \$filesToDelete | Out-File -FilePath \$tempFile -Encoding utf8
# Use rclone to delete the files
rclone delete AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --files-from \$tempFile --drive-chunk-size 64M rclone delete AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --files-from \$tempFile --drive-chunk-size 64M
# Clean up the temporary file
Remove-Item -Path \$tempFile Remove-Item -Path \$tempFile
} else { } else {
Write-Output "No files to delete." Write-Output "No files to delete."
} }
} else {
Write-Output "No files found on Google Drive to clean up."
}
""" """
} }
} }
}
post { post {
always { always {