Files
annotations/build/jenkins/GDriveUpload
T
2025-05-07 19:14:09 +03:00

69 lines
2.7 KiB
Plaintext

pipeline {
agent { label 'Win10-BuildMachine' }
parameters {
string(name: 'buildPath', defaultValue: 'C:/Jenkins/workspace/Azaion/suite', description: 'Path where the zip file is located')
}
environment {
GOOGLE_DRIVE_FOLDER = 'AzaionSuiteBuilds'
}
stages {
stage('Upload to Google Drive') {
steps {
script {
echo "Looking for ZIP in: ${params.buildPath}"
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}"
}
// Replace 'your-working-remote' with your actual working rclone remote name
def remoteName = 'your-working-remote'
// Check if file already exists
def alreadyExists = powershell(script: """
\$result = rclone ls ${remoteName}:${env.GOOGLE_DRIVE_FOLDER} | Select-String "${zipFilename}"
if (\$result) { return 1 } else { return 0 }
""", returnStatus: true) == 1
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}\" ${remoteName}:${env.GOOGLE_DRIVE_FOLDER}
"""
}
// Retention: keep only latest 5
echo "Cleaning up old ZIP files in Google Drive..."
powershell """
\$files = rclone lsf --files-only ${remoteName}:${env.GOOGLE_DRIVE_FOLDER} | Sort-Object
if (\$files.Count -gt 5) {
\$filesToDelete = \$files | Select-Object -First (\$files.Count - 5)
foreach (\$file in \$filesToDelete) {
rclone delete ${remoteName}:${env.GOOGLE_DRIVE_FOLDER}/\$file
}
}
"""
}
}
}
}
}
post {
success {
echo "Upload completed."
}
failure {
echo "Upload failed."
}
}
}