pipeline { agent { label 'windows' } stages { stage('Initialize Workspace') { steps { echo 'Initializing workspace on Windows agent...' powershell ''' $uploadDir = "temp_upload" if (-Not (Test-Path $uploadDir)) { New-Item -ItemType Directory -Path $uploadDir | Out-Null } ''' } } stage('Find Latest Zip and Upload') { steps { script { echo "Starting 'Find Latest Zip and Upload' stage." dir("C:/Jenkins/workspace/AzaionSuite/suite") { def output = powershell(returnStdout: true, script: ''' $pattern = "AzaionSuite*-*-*.zip" $zipFiles = Get-ChildItem -Filter $pattern | Sort-Object Name -Descending if ($zipFiles.Count -eq 0) { Write-Error "No ZIP files matching pattern '$pattern' were found." exit 1 } $latestZip = $zipFiles[0].Name Write-Output "::SET-ENV::LATEST_ZIP_FILENAME=$latestZip" ''').trim() def match = output =~ /::SET-ENV::LATEST_ZIP_FILENAME=(.+)/ if (!match) { error("Could not find the latest zip filename in the PowerShell output using marker.") } def zipFileName = match[0][1] echo "Latest zip file selected: ${zipFileName}" // Pass the variable into the environment for the next steps if needed env.LATEST_ZIP_FILENAME = zipFileName } } } } stage('Retention on Google Drive') { steps { echo "Uploading ${env.LATEST_ZIP_FILENAME} to Google Drive..." // Example command (replace with actual upload command) powershell """ \$filePath = "C:/Jenkins/workspace/AzaionSuite/suite/${env.LATEST_ZIP_FILENAME}" Write-Output "Would upload: \$filePath" # Add your actual GDrive upload logic here """ } } } post { always { echo 'Executing post-build cleanup...' powershell ''' $uploadDir = "temp_upload" if (Test-Path $uploadDir) { Remove-Item -Recurse -Force $uploadDir } ''' } failure { echo 'Pipeline failed. Check logs for details.' } } }