diff --git a/build/jenkins/zip b/build/jenkins/zip index 9886a48..5aea3ff 100644 --- a/build/jenkins/zip +++ b/build/jenkins/zip @@ -46,104 +46,105 @@ pipeline { echo "Operating in directory: ${pwd()}" // Define the expected artifact patterns relative to the current directory (MAIN_BUILD_ARTIFACTS_DIR) - def exePattern = 'AzaionSuite*.exe' - def binPattern = 'AzaionSuite*.bin' + // These are now defined as literals within the PowerShell script string + // def exePattern = 'AzaionSuite*.exe' + // def binPattern = 'AzaionSuite*.bin' // Define defaultVersion here, used if version extraction fails - def defaultVersion = '1.0.0' + // def defaultVersion = '1.0.0' + // Use a powershell step to perform file finding, version extraction, timestamp generation, and zipping - powershell """ - \$ErrorActionPreference = "Stop" # Stop the script on any error + powershell ''' + $ErrorActionPreference = "Stop" # Stop the script on any error - \$sevenZipExe = "\$env:SEVEN_ZIP_PATH\\7z.exe" - \$defaultVersion = "${defaultVersion}" - \$exePattern = "${exePattern}" - \$binPattern = "${binPattern}" + $sevenZipExe = "$env:SEVEN_ZIP_PATH\\7z.exe" + $defaultVersion = "1.0.0" # Default version if extraction fails + $exePattern = "AzaionSuite*.exe" + $binPattern = "AzaionSuite*.bin" - Write-Host "Searching for files matching \$exePattern and \$binPattern in the current directory for zipping..." + Write-Host "Searching for files matching $exePattern and $binPattern in the current directory for zipping..." # Find all files matching the patterns - \$foundFiles = Get-ChildItem -Recurse -Path . -Include \$exePattern, \$binPattern | Select-Object -ExpandProperty FullName + $foundFiles = Get-ChildItem -Recurse -Path . -Include $exePattern, $binPattern | Select-Object -ExpandProperty FullName - if (\$foundFiles.Count -eq 0) { - Write-Error "No files matching patterns \$exePattern or \$binPattern found in \$(Get-Location)." + if ($foundFiles.Count -eq 0) { + Write-Error "No files matching patterns $exePattern or $binPattern found in $(Get-Location)." exit 1 } - Write-Host "Found \$(\$foundFiles.Count) file(s) to archive." + Write-Host "Found $($foundFiles.Count) file(s) to archive." # --- Version Extraction (from .exe if present) --- - \$version = \$defaultVersion - \$exeFile = Get-ChildItem -Recurse -Path . -Filter \$exePattern | Select-Object -First 1 + $version = $defaultVersion + $exeFile = Get-ChildItem -Recurse -Path . -Filter $exePattern | Select-Object -First 1 - if (\$exeFile) { - Write-Host "Attempting to extract version from '\$($exeFile.FullName)'..." + if ($exeFile) { + Write-Host "Attempting to extract version from '$($exeFile.FullName)'..." try { # Get file version info - \$versionInfo = Get-ItemProperty -Path \$exeFile.FullName -Name VersionInfo + $versionInfo = Get-ItemProperty -Path $exeFile.FullName -Name VersionInfo # Prefer ProductVersion, fallback to FileVersion - if (\$versionInfo.ProductVersion) { - \$version = \$versionInfo.ProductVersion - Write-Host "Extracted ProductVersion: \$version" - } elseif (\$versionInfo.FileVersion) { - \$version = \$versionInfo.FileVersion - Write-Host "Extracted FileVersion: \$version" + if ($versionInfo.ProductVersion) { + $version = $versionInfo.ProductVersion + Write-Host "Extracted ProductVersion: $version" + } elseif ($versionInfo.FileVersion) { + $version = $versionInfo.FileVersion + Write-Host "Extracted FileVersion: $version" } else { - Write-Warning "Could not extract ProductVersion or FileVersion from '\$($exeFile.Name)'. Using default: \$version" + Write-Warning "Could not extract ProductVersion or FileVersion from '$($exeFile.Name)'. Using default: $version" } } catch { - Write-Warning "Error extracting version from '\$($exeFile.Name)': \$_\nUsing default: \$version" + Write-Warning "Error extracting version from '$($exeFile.Name)': $_`nUsing default: $version" } } else { - Write-Warning "No executable found matching \$exePattern to extract version. Using default: \$version" + Write-Warning "No executable found matching $exePattern to extract version. Using default: $version" } # --- Zipping Logic --- # Get current date and time in YYYYMMDD-HHmmss format - \$timestamp = (Get-Date -Format "yyyyMMdd-HHmmss") + $timestamp = (Get-Date -Format "yyyyMMdd-HHmmss") # Construct the zip filename using extracted version and timestamp - \$zipFilename = "AzaionSuite.\$version-\$timestamp.zip" + $zipFilename = "AzaionSuite.$version-$timestamp.zip" - Write-Host "Creating zip archive: \$zipFilename using 7-Zip." + Write-Host "Creating zip archive: $zipFilename using 7-Zip." # Build the 7z command arguments # Start with command, type, and quoted zip filename - \$sevenZipArgs = @("a", "-tzip", "\$zipFilename") + $sevenZipArgs = @("a", "-tzip", "$zipFilename") - # Add the list of found files (which are already quoted and space-separated in the Batch script, - # but Get-ChildItem returns objects, so we need to handle quoting for the command) - # Joining the array elements with spaces, ensuring each path is quoted - \$foundFilesQuoted = \$foundFiles | ForEach-Object { "\`"\$_\`"" } - \$sevenZipArgs += \$foundFilesQuoted + # Add the list of found files, ensuring each path is quoted + # Using backticks to escape quotes within the PowerShell string + $foundFilesQuoted = $foundFiles | ForEach-Object { "`"$_`"" } + $sevenZipArgs += $foundFilesQuoted # Construct the full command string for logging - \$commandString = "\$sevenZipExe \$(\$sevenZipArgs -join ' ')" - Write-Host "Executing command: \$commandString" + $commandString = "$sevenZipExe $($sevenZipArgs -join ' ')" + Write-Host "Executing command: $commandString" # Execute the 7z command # Using Start-Process with -Wait to ensure the script waits for 7z to finish # and capturing the exit code - \$process = Start-Process -FilePath \$sevenZipExe -ArgumentList \$sevenZipArgs -Wait -PassThru - \$exitCode = \$process.ExitCode + $process = Start-Process -FilePath $sevenZipExe -ArgumentList $sevenZipArgs -Wait -PassThru + $exitCode = $process.ExitCode # Check the last exit code from the external command - if (\$exitCode -ne 0) { - Write-Error "Error creating zip archive with 7-Zip. 7z exit code: \$exitCode" - exit \$exitCode + if ($exitCode -ne 0) { + Write-Error "Error creating zip archive with 7-Zip. 7z exit code: $exitCode" + exit $exitCode } - Write-Host "Zip archive created successfully by 7-Zip: \$zipFilename" + Write-Host "Zip archive created successfully by 7-Zip: $zipFilename" # Output the zip filename and set it as an environment variable for Jenkins # This uses the Jenkins 'set context' feature - Write-Host "::SET-ZIP-FILENAME::\$zipFilename" - Write-Host "::SET-ENV::CREATED_ZIP_FILENAME=\$zipFilename" + Write-Host "::SET-ZIP-FILENAME::$zipFilename" + Write-Host "::SET-ENV::CREATED_ZIP_FILENAME=$zipFilename" exit 0 - """ // End powershell script + ''' // End powershell script } // End dir block } }