mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 11:16:30 +00:00
zip update
This commit is contained in:
+78
-59
@@ -53,7 +53,7 @@ pipeline {
|
||||
// def defaultVersion = '1.0.0'
|
||||
|
||||
|
||||
// Use a powershell step to perform file finding, filename extraction, timestamp generation, and zipping
|
||||
// Use a powershell step to check for existing zip, or create a new one, then output the filename
|
||||
// Capture the output of the powershell script
|
||||
def zipFilenameOutput = powershell returnStdout: true, script: '''
|
||||
$ErrorActionPreference = "Stop" # Stop the script on any error
|
||||
@@ -62,72 +62,91 @@ pipeline {
|
||||
$defaultVersion = "1.0.0" # Default version if no exe is found
|
||||
$exePattern = "AzaionSuite*.exe"
|
||||
$binPattern = "AzaionSuite*.bin"
|
||||
$zipPattern = "AzaionSuite*.zip" # Pattern for existing zip files
|
||||
|
||||
Write-Host "Searching for files matching $exePattern and $binPattern in the current directory for zipping..."
|
||||
Write-Host "Operating in directory: $(Get-Location)"
|
||||
|
||||
# Find all files matching the patterns
|
||||
$foundFiles = Get-ChildItem -Recurse -Path . -Include $exePattern, $binPattern | Select-Object -ExpandProperty FullName
|
||||
# --- Check for existing zip files ---
|
||||
Write-Host "Checking for existing zip files matching '$zipPattern'..."
|
||||
$existingZips = Get-ChildItem -Path . -Include $zipPattern | Sort-Object LastWriteTime -Descending
|
||||
|
||||
if ($foundFiles.Count -eq 0) {
|
||||
Write-Error "No files matching patterns $exePattern or $binPattern found in $(Get-Location)."
|
||||
exit 1
|
||||
}
|
||||
$zipFilename = ""
|
||||
$zipFound = $false
|
||||
|
||||
Write-Host "Found $($foundFiles.Count) file(s) to archive."
|
||||
|
||||
# --- Determine Base Filename for Zip (from .exe if present) ---
|
||||
$zipBaseFilename = "AzaionSuite.$defaultVersion" # Default base filename
|
||||
$exeFile = Get-ChildItem -Recurse -Path . -Filter $exePattern | Select-Object -First 1
|
||||
|
||||
if ($exeFile) {
|
||||
Write-Host "Executable file found: '$($exeFile.FullName)'"
|
||||
# Extract filename without extension
|
||||
$zipBaseFilename = $exeFile.BaseName
|
||||
Write-Host "Using executable base filename for archive name: '$zipBaseFilename'"
|
||||
if ($existingZips.Count -gt 0) {
|
||||
# Found existing zip files, use the newest one
|
||||
$newestZip = $existingZips | Select-Object -First 1
|
||||
$zipFilename = $newestZip.Name
|
||||
$zipFound = $true
|
||||
Write-Host "Found existing zip file: '$zipFilename'. Skipping creation."
|
||||
} else {
|
||||
Write-Warning "No executable found matching $exePattern. Using default base filename: '$zipBaseFilename'"
|
||||
# No existing zip files, proceed with creation
|
||||
Write-Host "No existing zip files found. Proceeding with creation."
|
||||
|
||||
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
|
||||
|
||||
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."
|
||||
|
||||
# --- Determine Base Filename for Zip (from .exe if present) ---
|
||||
$zipBaseFilename = "AzaionSuite.$defaultVersion" # Default base filename
|
||||
$exeFile = Get-ChildItem -Recurse -Path . -Filter $exePattern | Select-Object -First 1
|
||||
|
||||
if ($exeFile) {
|
||||
Write-Host "Executable file found: '$($exeFile.FullName)'"
|
||||
# Extract filename without extension
|
||||
$zipBaseFilename = $exeFile.BaseName
|
||||
Write-Host "Using executable base filename for archive name: '$zipBaseFilename'"
|
||||
} else {
|
||||
Write-Warning "No executable found matching $exePattern. Using default base filename: '$zipBaseFilename'"
|
||||
}
|
||||
|
||||
# --- Zipping Logic ---
|
||||
|
||||
# Get current date and time inYYYYMMDD-HHmmss format
|
||||
$timestamp = (Get-Date -Format "yyyyMMdd-HHmmss")
|
||||
|
||||
# Construct the zip filename using the base filename and timestamp
|
||||
$zipFilename = "$zipBaseFilename-$timestamp.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")
|
||||
|
||||
# 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"
|
||||
|
||||
# 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
|
||||
|
||||
# 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
|
||||
}
|
||||
|
||||
Write-Host "Zip archive created successfully by 7-Zip: $zipFilename"
|
||||
}
|
||||
|
||||
# --- Zipping Logic ---
|
||||
|
||||
# Get current date and time inYYYYMMDD-HHmmss format
|
||||
$timestamp = (Get-Date -Format "yyyyMMdd-HHmmss")
|
||||
|
||||
# Construct the zip filename using the base filename and timestamp
|
||||
$zipFilename = "$zipBaseFilename-$timestamp.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")
|
||||
|
||||
# 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"
|
||||
|
||||
# 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
|
||||
|
||||
# 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
|
||||
}
|
||||
|
||||
Write-Host "Zip archive created successfully by 7-Zip: $zipFilename"
|
||||
|
||||
# Output the zip filename to standard output for the Groovy script to capture
|
||||
# Write-Host "::SET-ZIP-FILENAME::$zipFilename" # Removed, using Write-Output instead
|
||||
# Write-Host "::SET-ENV::CREATED_ZIP_FILENAME=$zipFilename" # Removed, using Write-Output instead
|
||||
Write-Output $zipFilename
|
||||
|
||||
exit 0
|
||||
|
||||
Reference in New Issue
Block a user