diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index 5ebb9a0..b4ea2aa 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -32,10 +32,19 @@ pipeline { script { echo "Finding latest zip file in: C:/Jenkins/workspace/Azaion/suite" dir('C:/Jenkins/workspace/Azaion/suite') { - // Find the latest zip file using shell command - def latestZip = bat(script: 'dir /b /od *.zip | findstr /r /c:"AzaionSuite.Iterative.*.zip"', returnStdout: true).trim() - env.LATEST_ZIP_FILENAME = latestZip - echo "✅ Latest zip file selected: ${env.LATEST_ZIP_FILENAME}" + // Debug output to confirm current directory contents + echo "Listing .zip files in the directory:" + bat(script: 'dir /b *.zip', returnStdout: true).trim() + + // Get the most recent .zip file based on modification date + def latestZip = bat(script: 'dir /b /od *.zip | head -n 1', returnStdout: true).trim() + + if (latestZip) { + env.LATEST_ZIP_FILENAME = latestZip + echo "✅ Latest zip file selected: ${env.LATEST_ZIP_FILENAME}" + } else { + error "No valid zip files found in the directory!" + } } } } @@ -47,15 +56,15 @@ pipeline { powershell """ # Check if file exists on Google Drive \$existingFiles = rclone lsf --files-only AzaionGoogleDrive:${GOOGLE_DRIVE_FOLDER} - if (\$existingFiles -contains "${env.LATEST_ZIP_FILENAME}") { - Write-Output "File ${env.LATEST_ZIP_FILENAME} already exists on Google Drive, skipping upload." + if (\$existingFiles -contains "${LATEST_ZIP_FILENAME}") { + Write-Output "File ${LATEST_ZIP_FILENAME} already exists on Google Drive, skipping upload." } else { - Write-Output "Uploading ${env.LATEST_ZIP_FILENAME} to Google Drive..." - rclone copy C:/Jenkins/workspace/Azaion/suite/${env.LATEST_ZIP_FILENAME} AzaionGoogleDrive:${GOOGLE_DRIVE_FOLDER} + Write-Output "Uploading ${LATEST_ZIP_FILENAME} to Google Drive..." + rclone copy C:/Jenkins/workspace/Azaion/suite/${LATEST_ZIP_FILENAME} AzaionGoogleDrive:${GOOGLE_DRIVE_FOLDER} } # Always remove the local file after uploading - Remove-Item "C:/Jenkins/workspace/Azaion/suite/${env.LATEST_ZIP_FILENAME}" + Remove-Item "C:/Jenkins/workspace/Azaion/suite/${LATEST_ZIP_FILENAME}" """ } } @@ -78,7 +87,7 @@ pipeline { # Split files by line and exclude the latest zip file \$filesArray = \$files -split "`n" | Where-Object { \$_ -ne "" } - \$latestFile = "${env.LATEST_ZIP_FILENAME}" + \$latestFile = "${LATEST_ZIP_FILENAME}" \$filesArray = \$filesArray | Where-Object { \$_ -ne \$latestFile } # If more than 3 files exist, delete the oldest ones