From eddd3f2052dca16e6954fd8cb3ab8d9829957069 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 15:19:34 +0300 Subject: [PATCH] gdrive update1 --- build/jenkins/GDriveUpload | 53 +++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 30 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index 6b629c2..5df6d13 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -10,7 +10,7 @@ pipeline { } environment { - RCLONE_CONFIG = 'C:/Program Files/rclone/rclone.conf' // Ensure this points to the correct location + RCLONE_CONFIG = 'C:/Program Files/rclone/rclone.conf' } stages { @@ -49,7 +49,6 @@ pipeline { def zipFileName = match[0][1] echo "Latest zip file selected: ${zipFileName}" - // Pass the variable into the environment for the next steps if needed env.LATEST_ZIP_FILENAME = zipFileName } } @@ -63,50 +62,44 @@ pipeline { \$filePath = "C:/Jenkins/workspace/AzaionSuite/suite/${env.LATEST_ZIP_FILENAME}" Write-Output "Preparing to upload: \$filePath" - # Display the contents of the rclone configuration file to ensure it's being read correctly Get-Content 'C:/Program Files/rclone/rclone.conf' - - # Explicitly set the rclone config path \$env:RCLONE_CONFIG = 'C:/Program Files/rclone/rclone.conf' - # Use rclone to upload the file to Google Drive rclone copy "\$filePath" AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --progress --drive-chunk-size 64M """ } } - 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 + stage('Cleanup Older Files on Google Drive') { + 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 - # Convert to array and sort by name descending (adjust if you want date sorting) - \$filesArray = \$files -split "`n" | Where-Object { \$_ -ne "" } | Sort-Object -Descending + \$filesArray = \$files -split "`n" | Where-Object { \$_ -ne "" } | Sort-Object -Descending - # Keep only the 3 latest files - \$filesToDelete = \$filesArray | Select-Object -Skip 3 + \$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 (\$filesToDelete.Count -gt 0) { - \$tempFile = [System.IO.Path]::GetTempFileName() - \$filesToDelete | Out-File -FilePath \$tempFile -Encoding utf8 + if (\$filesToDelete.Count -gt 0) { + \$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 + rclone delete AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --files-from \$tempFile --drive-chunk-size 64M - Remove-Item -Path \$tempFile - } else { - Write-Output "No files to delete." + Remove-Item -Path \$tempFile + } else { + Write-Output "No files to delete." + } + """ } - """ + } } -} post { always {