latest fixes for Gdrive upload

This commit is contained in:
dzaitsev
2025-05-04 15:31:12 +03:00
parent 4703c73a24
commit 7fc51e19ee
+35 -19
View File
@@ -10,7 +10,7 @@ pipeline {
} }
environment { 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 { stages {
@@ -57,18 +57,25 @@ pipeline {
stage('Upload to Google Drive using rclone') { stage('Upload to Google Drive using rclone') {
steps { steps {
echo "Uploading ${env.LATEST_ZIP_FILENAME} to Google Drive..." echo "Checking if ${env.LATEST_ZIP_FILENAME} already exists on Google Drive..."
powershell """ powershell """
\$filePath = "C:/Jenkins/workspace/AzaionSuite/suite/${env.LATEST_ZIP_FILENAME}" \$fileName = "${env.LATEST_ZIP_FILENAME}"
Write-Output "Preparing to upload: \$filePath" \$folder = "${params.GOOGLE_DRIVE_FOLDER}"
\$rcloneRemote = "AzaionGoogleDrive:\$folder"
# Display the contents of the rclone configuration file to ensure it's being read correctly Write-Output "Checking for existing files in: \$rcloneRemote"
Get-Content 'C:/Program Files/rclone/rclone.conf' \$existingFiles = rclone lsf --files-only \$rcloneRemote
Write-Output "Existing files:"
Write-Output \$existingFiles
if (\$existingFiles -match "^\$fileName\$") {
Write-Output "File '\$fileName' already exists on Google Drive. Skipping upload."
} else {
Write-Output "Uploading '\$fileName' to Google Drive..."
\$filePath = "C:/Jenkins/workspace/AzaionSuite/suite/\$fileName"
\$env:RCLONE_CONFIG = 'C:/Program Files/rclone/rclone.conf' \$env:RCLONE_CONFIG = 'C:/Program Files/rclone/rclone.conf'
rclone copy "\$filePath" \$rcloneRemote --progress --drive-chunk-size 64M
# Use rclone to upload the file to Google Drive }
rclone copy "\$filePath" AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --progress --drive-chunk-size 64M
""" """
} }
} }
@@ -77,25 +84,34 @@ pipeline {
steps { steps {
echo "Cleaning up older files on Google Drive..." echo "Cleaning up older files on Google Drive..."
powershell """ powershell """
\$driveFolder = '${params.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}
# List all files in the Google Drive folder
Write-Output "Listing all files in the folder \$driveFolder on Google Drive..."
\$files = rclone lsf AzaionGoogleDrive:\$driveFolder --files-only --max-depth 1
Write-Output "Files found on Google Drive:" Write-Output "Files found on Google Drive:"
Write-Output \$files Write-Output \$files
if (\$files.Count -gt 0) { \$filesArray = \$files -split "`n" | Where-Object { \$_ -ne "" }
\$filesSorted = \$files | Sort-Object -Descending if (\$filesArray.Count -gt 3) {
\$filesSorted = \$filesArray | Sort-Object -Descending
\$filesToDelete = \$filesSorted | Select-Object -Skip 3 \$filesToDelete = \$filesSorted | 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 (\$filesToDelete.Count -gt 0) {
\$tempFile = [System.IO.Path]::GetTempFileName()
\$filesToDelete | Set-Content -Path \$tempFile -Encoding utf8
Write-Output "Contents of temporary delete list file (\$tempFile):"
Get-Content \$tempFile
foreach (\$file in \$filesToDelete) { foreach (\$file in \$filesToDelete) {
\$trimmedFile = \$file.Trim() Write-Output "Deleting \$file..."
Write-Output "Deleting file: \$trimmedFile" rclone deletefile AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER}/\$file
rclone deletefile AzaionGoogleDrive:\$driveFolder/\$trimmedFile }
Remove-Item -Path \$tempFile
} else {
Write-Output "No files to delete."
} }
} else { } else {
Write-Output "No files found on Google Drive to clean up." Write-Output "No files found on Google Drive to clean up."