mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 08:36:29 +00:00
latest fixes for Gdrive upload
This commit is contained in:
+37
-21
@@ -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
|
||||||
|
|
||||||
\$env:RCLONE_CONFIG = 'C:/Program Files/rclone/rclone.conf'
|
if (\$existingFiles -match "^\$fileName\$") {
|
||||||
|
Write-Output "File '\$fileName' already exists on Google Drive. Skipping upload."
|
||||||
# Use rclone to upload the file to Google Drive
|
} else {
|
||||||
rclone copy "\$filePath" AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --progress --drive-chunk-size 64M
|
Write-Output "Uploading '\$fileName' to Google Drive..."
|
||||||
|
\$filePath = "C:/Jenkins/workspace/AzaionSuite/suite/\$fileName"
|
||||||
|
\$env:RCLONE_CONFIG = 'C:/Program Files/rclone/rclone.conf'
|
||||||
|
rclone copy "\$filePath" \$rcloneRemote --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
|
||||||
|
|
||||||
foreach (\$file in \$filesToDelete) {
|
if (\$filesToDelete.Count -gt 0) {
|
||||||
\$trimmedFile = \$file.Trim()
|
\$tempFile = [System.IO.Path]::GetTempFileName()
|
||||||
Write-Output "Deleting file: \$trimmedFile"
|
\$filesToDelete | Set-Content -Path \$tempFile -Encoding utf8
|
||||||
rclone deletefile AzaionGoogleDrive:\$driveFolder/\$trimmedFile
|
|
||||||
|
Write-Output "Contents of temporary delete list file (\$tempFile):"
|
||||||
|
Get-Content \$tempFile
|
||||||
|
|
||||||
|
foreach (\$file in \$filesToDelete) {
|
||||||
|
Write-Output "Deleting \$file..."
|
||||||
|
rclone deletefile AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER}/\$file
|
||||||
|
}
|
||||||
|
|
||||||
|
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."
|
||||||
|
|||||||
Reference in New Issue
Block a user