From 24324b5ffd9980c16956ce3827d7d6bdb94a2d68 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 14:21:29 +0300 Subject: [PATCH] zip update --- build/jenkins/zip | 113 ++++++++++++++++++---------------------------- 1 file changed, 44 insertions(+), 69 deletions(-) diff --git a/build/jenkins/zip b/build/jenkins/zip index 8d8a938..4abfc08 100644 --- a/build/jenkins/zip +++ b/build/jenkins/zip @@ -13,13 +13,11 @@ pipeline { } stages { - stage('Archive Build Artifacts (PowerShell/7-Zip)') { + stage('Detect or Create Zip') { steps { script { - echo "Starting 'Archive Build Artifacts (PowerShell/7-Zip)' stage." + echo "Starting 'Detect or Create Zip' stage." dir("${env.MAIN_BUILD_ARTIFACTS_DIR}") { - echo "Operating in directory: ${pwd()}" - powershell ''' $ErrorActionPreference = "Stop" $sevenZipExe = "$env:SEVEN_ZIP_PATH\\7z.exe" @@ -28,97 +26,80 @@ pipeline { $binPattern = "AzaionSuite*.bin" $zipPattern = "AzaionSuite*.zip" - Write-Host "Operating in directory: $(Get-Location)" - if (-not (Test-Path $sevenZipExe)) { - Write-Error "7-Zip executable not found at $sevenZipExe" + Write-Error "7-Zip not found at $sevenZipExe" exit 1 } - $existingZips = Get-ChildItem -Path . -Filter $zipPattern | - Sort-Object LastWriteTime -Descending + $existingZips = Get-ChildItem -Path . -Filter $zipPattern | Sort-Object LastWriteTime -Descending $zipFilename = "" if ($existingZips.Count -gt 0) { - $newestZip = $existingZips | Select-Object -First 1 - $zipFilename = $newestZip.Name - Write-Host "Using newest existing zip file: '$zipFilename'." + $zipFilename = $existingZips[0].Name + Write-Host "Using existing zip file: $zipFilename" + $wasCreated = $false } else { - Write-Host "No existing zip files found. Creating new zip file." + $exeFile = Get-ChildItem -Recurse -Filter $exePattern | Select-Object -First 1 + if (-not $exeFile) { + Write-Error "No EXE file found to create zip" + exit 1 + } - $foundFiles = Get-ChildItem -Recurse -Path . -Include $exePattern, $binPattern | - Select-Object -ExpandProperty FullName + $zipBaseFilename = $exeFile.BaseName + $timestamp = (Get-Date -Format "yyyyMMdd-HHmmss") + $zipFilename = "$zipBaseFilename-$timestamp.zip" - if ($foundFiles.Count -eq 0) { + $filesToZip = Get-ChildItem -Recurse -Include $exePattern, $binPattern | Select-Object -ExpandProperty FullName + if ($filesToZip.Count -eq 0) { Write-Error "No files found to zip." exit 1 } - $zipBaseFilename = "AzaionSuite.$defaultVersion" - $exeFile = Get-ChildItem -Recurse -Path . -Filter $exePattern | Select-Object -First 1 - if ($exeFile) { - $zipBaseFilename = $exeFile.BaseName + $args = @("a", "-tzip", "$zipFilename") + ($filesToZip | ForEach-Object { "`"$_`"" }) + $process = Start-Process -FilePath $sevenZipExe -ArgumentList $args -Wait -NoNewWindow -PassThru + if ($process.ExitCode -ne 0) { + Write-Error "7-Zip failed with code $($process.ExitCode)" + exit $process.ExitCode } - $timestamp = (Get-Date -Format "yyyyMMdd-HHmmss") - $zipFilename = "$zipBaseFilename-$timestamp.zip" - Write-Host "Creating zip archive: $zipFilename" - - try { - $sevenZipArgs = @("a", "-tzip", "$zipFilename") - $foundFilesQuoted = $foundFiles | ForEach-Object { "`"$_`"" } - $sevenZipArgs += $foundFilesQuoted - $process = Start-Process -FilePath $sevenZipExe -ArgumentList $sevenZipArgs -Wait -NoNewWindow -PassThru - if ($process.ExitCode -ne 0) { - Write-Error "7-Zip failed with code $($process.ExitCode)" - exit $process.ExitCode - } - } - catch { - Write-Error "Zip creation failed: $_" - exit 1 - } + $wasCreated = $true + Write-Host "Created new zip file: $zipFilename" } - if (-not (Test-Path $zipFilename)) { - Write-Error "Expected zip file $zipFilename does not exist" - exit 1 - } - - # Write zip filename WITHOUT BOM (ASCII encoding) + # Save outputs without BOM Set-Content -Path "zipfilename.txt" -Value $zipFilename -Encoding ASCII - Write-Host "Zip filename written to zipfilename.txt: $zipFilename" - exit 0 + Set-Content -Path "zip_created.txt" -Value $wasCreated -Encoding ASCII ''' - // Read and clean the filename def zipFilename = readFile('zipfilename.txt').trim() - echo "Read zip filename from file: ${zipFilename}" + def zipCreated = readFile('zip_created.txt').trim().toBoolean() - // Save to file for next stage + echo "Zip filename: ${zipFilename}" + echo "Was zip created this run? ${zipCreated}" + + // Save results for next stages writeFile file: 'created_zip.txt', text: zipFilename + writeFile file: 'zip_was_created.txt', text: zipCreated.toString() } } } } - stage('Archive Created Zip') { + stage('Archive Zip File (if new)') { + when { + expression { + def zipCreated = readFile("${env.MAIN_BUILD_ARTIFACTS_DIR}/zip_was_created.txt").trim().toBoolean() + return zipCreated + } + } steps { script { - echo "Starting 'Archive Created Zip' stage." + echo "Archiving newly created zip file..." dir("${env.MAIN_BUILD_ARTIFACTS_DIR}") { def zipFilename = readFile('created_zip.txt').trim() - echo "Operating in directory: ${pwd()}" - - if (!zipFilename) { - error "Zip filename not found or is empty." - } - if (!fileExists(zipFilename)) { - error "File ${zipFilename} does not exist." + error "Zip file '${zipFilename}' not found!" } - - echo "Archiving zip file: ${zipFilename}" archiveArtifacts artifacts: "${zipFilename}", fingerprint: true } } @@ -129,13 +110,7 @@ pipeline { steps { script { echo "Triggering Google Drive Upload pipeline: ${env.GOOGLE_DRIVE_UPLOAD_JOB_NAME}" - try { - build job: env.GOOGLE_DRIVE_UPLOAD_JOB_NAME - echo "Google Drive Upload pipeline triggered successfully." - } catch (Exception e) { - echo "Failed to trigger Google Drive Upload pipeline: ${e.message}" - error "Trigger failed. See logs." - } + build job: env.GOOGLE_DRIVE_UPLOAD_JOB_NAME } } } @@ -145,11 +120,11 @@ pipeline { success { script { def zipFilename = readFile("${env.MAIN_BUILD_ARTIFACTS_DIR}/created_zip.txt").trim() - echo "Pipeline completed successfully. Created and archived zip: ${zipFilename}" + echo "Pipeline completed successfully. Final zip: ${zipFilename}" } } failure { - echo "Pipeline failed. See logs for details." + echo "Pipeline failed." } } }