pipelines zip and gdrive upload

updated
This commit is contained in:
dzaitsev
2025-05-07 19:10:55 +03:00
parent e6ab8bde47
commit 66632a97c1
+24 -5
View File
@@ -17,17 +17,36 @@ pipeline {
echo "Target Google Drive folder: ${env.GOOGLE_DRIVE_FOLDER}"
dir("${params.buildPath}") {
def zipFilename = readFile('created_zip.txt').trim()
if (!fileExists(zipFilename)) {
error "Zip file '${zipFilename}' not found in ${params.buildPath}"
}
echo "Uploading '${zipFilename}' to Google Drive folder '${env.GOOGLE_DRIVE_FOLDER}'..."
// Check if file already exists on Google Drive
def alreadyExists = powershell(script: """
\$result = rclone ls remote:\"${env.GOOGLE_DRIVE_FOLDER}\" | Select-String "${zipFilename}"
if (\$result) { return 1 } else { return 0 }
""", returnStatus: true) == 1
// Add actual upload logic here (e.g., gsutil, rclone, or API)
// Example (placeholder):
if (alreadyExists) {
echo "Zip file '${zipFilename}' already exists on Google Drive. Skipping upload."
} else {
echo "Uploading '${zipFilename}' to Google Drive folder '${env.GOOGLE_DRIVE_FOLDER}'..."
powershell """
rclone copy \"${zipFilename}\" remote:\"${env.GOOGLE_DRIVE_FOLDER}\"
"""
}
// Retention logic keep only latest 5 ZIPs
echo "Cleaning up old ZIP files in Google Drive..."
powershell """
echo Uploading ${zipFilename} to Google Drive...
rclone copy \"${zipFilename}\" remote:\"${env.GOOGLE_DRIVE_FOLDER}\"
\$files = rclone lsf --files-only --format "t" --max-age 365d remote:\"${env.GOOGLE_DRIVE_FOLDER}\" | Sort-Object | Where-Object { \$_ -like "*.zip" }
if (\$files.Count -gt 5) {
\$filesToDelete = \$files | Select-Object -First (\$files.Count - 5)
foreach (\$file in \$filesToDelete) {
rclone delete remote:\"${env.GOOGLE_DRIVE_FOLDER}/\$file\"
}
}
"""
}
}