mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 08:36:29 +00:00
pipelines zip and gdrive upload
updated
This commit is contained in:
+38
-34
@@ -92,48 +92,52 @@ pipeline {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Cleanup Older Files on Google Drive') {
|
stage('Cleanup Older Files on Google Drive') {
|
||||||
when {
|
when {
|
||||||
expression { return env.LATEST_ZIP_FILENAME?.trim() }
|
expression { return env.LATEST_ZIP_FILENAME?.trim() }
|
||||||
}
|
}
|
||||||
steps {
|
steps {
|
||||||
echo "Cleaning up older files on Google Drive..."
|
echo "Cleaning up older files on Google Drive..."
|
||||||
powershell """
|
powershell """
|
||||||
Write-Output "Listing all files in the folder ${env.GOOGLE_DRIVE_FOLDER} on Google Drive..."
|
Write-Output "Listing all files in the folder ${params.GOOGLE_DRIVE_FOLDER} on Google Drive..."
|
||||||
\$files = rclone lsf --files-only AzaionGoogleDrive:${env.GOOGLE_DRIVE_FOLDER}
|
\$files = rclone lsf --files-only AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER}
|
||||||
Write-Output "Files found on Google Drive:"
|
Write-Output "Files found on Google Drive:"
|
||||||
Write-Output \$files
|
Write-Output \$files
|
||||||
|
|
||||||
\$filesArray = \$files -split "`n" | Where-Object { \$_ -ne "" }
|
\$filesArray = \$files -split "`n" | Where-Object { \$_ -ne "" }
|
||||||
if (\$filesArray.Count -gt 3) {
|
# Exclude the latest zip file from deletion
|
||||||
\$filesSorted = \$filesArray | Sort-Object -Descending
|
\$latestFile = "${env.LATEST_ZIP_FILENAME}"
|
||||||
\$filesToDelete = \$filesSorted | Select-Object -Skip 3
|
\$filesArray = \$filesArray | Where-Object { \$_ -ne \$latestFile }
|
||||||
|
|
||||||
Write-Output "Files to delete (older than 3 latest):"
|
if (\$filesArray.Count -gt 3) {
|
||||||
Write-Output \$filesToDelete
|
\$filesSorted = \$filesArray | Sort-Object -Descending
|
||||||
|
\$filesToDelete = \$filesSorted | Select-Object -Skip 3
|
||||||
|
|
||||||
if (\$filesToDelete.Count -gt 0) {
|
Write-Output "Files to delete (older than 3 latest):"
|
||||||
\$tempFile = [System.IO.Path]::GetTempFileName()
|
Write-Output \$filesToDelete
|
||||||
\$filesToDelete | Set-Content -Path \$tempFile -Encoding utf8
|
|
||||||
|
|
||||||
Write-Output "Contents of temporary delete list file (\$tempFile):"
|
if (\$filesToDelete.Count -gt 0) {
|
||||||
Get-Content \$tempFile
|
\$tempFile = [System.IO.Path]::GetTempFileName()
|
||||||
|
\$filesToDelete | Set-Content -Path \$tempFile -Encoding utf8
|
||||||
|
|
||||||
foreach (\$file in \$filesToDelete) {
|
Write-Output "Contents of temporary delete list file (\$tempFile):"
|
||||||
Write-Output "Deleting \$file..."
|
Get-Content \$tempFile
|
||||||
rclone deletefile AzaionGoogleDrive:${env.GOOGLE_DRIVE_FOLDER}/\$file
|
|
||||||
}
|
|
||||||
|
|
||||||
Remove-Item -Path \$tempFile
|
foreach (\$file in \$filesToDelete) {
|
||||||
} else {
|
Write-Output "Deleting \$file..."
|
||||||
Write-Output "No files to delete."
|
rclone deletefile AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER}/\$file
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Write-Output "No files found on Google Drive to clean up."
|
|
||||||
}
|
}
|
||||||
"""
|
|
||||||
|
Remove-Item -Path \$tempFile
|
||||||
|
} else {
|
||||||
|
Write-Output "No files to delete."
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Write-Output "No files found on Google Drive to clean up."
|
||||||
}
|
}
|
||||||
}
|
"""
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
post {
|
post {
|
||||||
|
|||||||
Reference in New Issue
Block a user