mirror of
https://github.com/azaion/annotations.git
synced 2026-04-23 00:46:31 +00:00
gdrive update1
This commit is contained in:
+15
-30
@@ -77,60 +77,45 @@ pipeline {
|
|||||||
|
|
||||||
stage('Cleanup Older Files on Google Drive') {
|
stage('Cleanup Older Files on Google Drive') {
|
||||||
steps {
|
steps {
|
||||||
script {
|
echo "Cleaning up older files on Google Drive..."
|
||||||
// Writing PowerShell cleanup script to a temporary file
|
powershell """
|
||||||
def cleanupScript = '''
|
|
||||||
# List all files in the Google Drive folder
|
# List all files in the Google Drive folder
|
||||||
Write-Output "Listing all files in the folder ${params.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:${params.GOOGLE_DRIVE_FOLDER} --format "tp" --max-depth 1
|
\$files = rclone lsf --files-only AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --format "tp" --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 were found
|
# If files were found
|
||||||
if ($files.Count -gt 0) {
|
if (\$files.Count -gt 0) {
|
||||||
# Sort the files by date in descending order
|
# Sort the files by date in descending order
|
||||||
$filesSorted = $files | Sort-Object -Descending
|
\$filesSorted = \$files | Sort-Object -Descending
|
||||||
|
|
||||||
# Keep only the 3 latest files
|
# Keep only the 3 latest files
|
||||||
$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 there are files to delete, remove them
|
# If there are files to delete, remove them
|
||||||
if ($filesToDelete.Count -gt 0) {
|
if (\$filesToDelete.Count -gt 0) {
|
||||||
Write-Output "Deleting files: $filesToDelete"
|
Write-Output "Deleting files: \$filesToDelete"
|
||||||
|
|
||||||
# Extract file names (without timestamps)
|
|
||||||
$fileNamesToDelete = $filesToDelete -replace '^\S+ ', ''
|
|
||||||
|
|
||||||
# Create a temporary file to store the list of files to delete
|
# Create a temporary file to store the list of files to delete
|
||||||
$tempFile = [System.IO.Path]::GetTempFileName()
|
\$tempFile = [System.IO.Path]::GetTempFileName()
|
||||||
$fileNamesToDelete | Out-File -FilePath $tempFile -Encoding utf8
|
\$filesToDelete | Out-File -FilePath \$tempFile -Encoding utf8
|
||||||
|
|
||||||
# Use rclone to delete the files
|
# Use rclone to delete the files
|
||||||
rclone delete AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --files-from $tempFile --drive-chunk-size 64M
|
rclone delete AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --files-from \$tempFile --drive-chunk-size 64M
|
||||||
|
|
||||||
# Clean up the temporary file
|
# Clean up the temporary file
|
||||||
Remove-Item -Path $tempFile
|
Remove-Item -Path \$tempFile
|
||||||
} else {
|
} else {
|
||||||
Write-Output "No files to delete."
|
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."
|
||||||
}
|
}
|
||||||
'''
|
"""
|
||||||
|
|
||||||
// Write the PowerShell cleanup script to a temporary file
|
|
||||||
def tempScriptFile = "cleanup_script.ps1"
|
|
||||||
writeFile file: tempScriptFile, text: cleanupScript
|
|
||||||
|
|
||||||
// Run the PowerShell script
|
|
||||||
powershell script: tempScriptFile
|
|
||||||
|
|
||||||
// Clean up the temporary PowerShell script file
|
|
||||||
deleteFile tempScriptFile
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user