mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 19:56:31 +00:00
zip update
This commit is contained in:
+40
-68
@@ -30,7 +30,7 @@ pipeline {
|
|||||||
|
|
||||||
// Define the name of the created zip file as an environment variable
|
// Define the name of the created zip file as an environment variable
|
||||||
// This makes it easier to reference in later stages
|
// This makes it easier to reference in later stages
|
||||||
CREATED_ZIP_FILENAME = '' // This will be set dynamically by reading a temp file
|
CREATED_ZIP_FILENAME = '' // This will be set dynamically by capturing PowerShell output
|
||||||
}
|
}
|
||||||
|
|
||||||
stages {
|
stages {
|
||||||
@@ -39,17 +39,15 @@ pipeline {
|
|||||||
|
|
||||||
stage('Archive Build Artifacts (PowerShell/7-Zip)') {
|
stage('Archive Build Artifacts (PowerShell/7-Zip)') {
|
||||||
steps {
|
steps {
|
||||||
script { // Need script block for dir, powershell, and file operations
|
script { // Need script block for dir and powershell step
|
||||||
echo "Starting 'Archive Build Artifacts (PowerShell/7-Zip)' stage."
|
echo "Starting 'Archive Build Artifacts (PowerShell/7-Zip)' stage."
|
||||||
// Change directory to the main build job's artifacts folder
|
// Change directory to the main build job's artifacts folder
|
||||||
dir("${env.MAIN_BUILD_ARTIFACTS_DIR}") {
|
dir("${env.MAIN_BUILD_ARTIFACTS_DIR}") {
|
||||||
echo "Operating in directory: ${pwd()}"
|
echo "Operating in directory: ${pwd()}"
|
||||||
|
|
||||||
// Define the name for the temporary file to store the zip filename
|
// Use a powershell step to check for existing zip, or create a new one, then output the filename
|
||||||
def tempFilenameFile = "zip_filename.txt"
|
// Capture the output of the powershell script
|
||||||
|
def zipFilenameOutput = powershell returnStdout: true, script: '''
|
||||||
// Use a powershell step to check for existing zip, or create a new one, then write the filename to a temp file
|
|
||||||
powershell '''
|
|
||||||
$ErrorActionPreference = "Stop" # Stop the script on any error
|
$ErrorActionPreference = "Stop" # Stop the script on any error
|
||||||
|
|
||||||
$sevenZipExe = "$env:SEVEN_ZIP_PATH\\7z.exe"
|
$sevenZipExe = "$env:SEVEN_ZIP_PATH\\7z.exe"
|
||||||
@@ -57,7 +55,6 @@ pipeline {
|
|||||||
$exePattern = "AzaionSuite*.exe"
|
$exePattern = "AzaionSuite*.exe"
|
||||||
$binPattern = "AzaionSuite*.bin"
|
$binPattern = "AzaionSuite*.bin"
|
||||||
$zipPattern = "AzaionSuite*.zip" # Pattern for existing zip files
|
$zipPattern = "AzaionSuite*.zip" # Pattern for existing zip files
|
||||||
$tempFilenameFile = "''' + tempFilenameFile + '''" # Pass temp filename to PowerShell
|
|
||||||
|
|
||||||
Write-Host "Operating in directory: $(Get-Location)"
|
Write-Host "Operating in directory: $(Get-Location)"
|
||||||
|
|
||||||
@@ -90,112 +87,87 @@ pipeline {
|
|||||||
$newestZip = $existingZips | Select-Object -First 1
|
$newestZip = $existingZips | Select-Object -First 1
|
||||||
$zipFilename = $newestZip.Name
|
$zipFilename = $newestZip.Name
|
||||||
$zipFound = $true
|
$zipFound = $true
|
||||||
Write-Host "DEBUG: Using newest existing zip file: '$zipFilename'. Skipping creation process."
|
Write-Host "Using newest existing zip file: '$zipFilename'. Skipping creation process."
|
||||||
|
# Skip the rest of the script that creates a new zip
|
||||||
} else {
|
} else {
|
||||||
# No existing zip files, proceed with creation
|
# No existing zip files, proceed with creation
|
||||||
Write-Host "DEBUG: No existing zip files found. Proceeding with file finding and zipping process."
|
Write-Host "No existing zip files found. Proceeding with file finding and zipping process."
|
||||||
|
|
||||||
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
|
# 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) {
|
if (\$foundFiles.Count -eq 0) {
|
||||||
Write-Error "No files matching patterns $exePattern or $binPattern found in $(Get-Location)."
|
Write-Error "No files matching patterns \$exePattern or \$binPattern found in \$(Get-Location)."
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "Found $($foundFiles.Count) file(s) to archive."
|
Write-Host "Found \$(\$foundFiles.Count) file(s) to archive."
|
||||||
|
|
||||||
# --- Determine Base Filename for Zip (from .exe if present) ---
|
# --- Determine Base Filename for Zip (from .exe if present) ---
|
||||||
$zipBaseFilename = "AzaionSuite.$defaultVersion" # Default base filename
|
\$zipBaseFilename = "AzaionSuite.\$defaultVersion" # Default base filename
|
||||||
$exeFile = Get-ChildItem -Recurse -Path . -Filter $exePattern | Select-Object -First 1
|
\$exeFile = Get-ChildItem -Recurse -Path . -Filter \$exePattern | Select-Object -First 1
|
||||||
|
|
||||||
if ($exeFile) {
|
if (\$exeFile) {
|
||||||
Write-Host "Executable file found: '$($exeFile.FullName)'"
|
Write-Host "Executable file found: '\$(\$exeFile.FullName)'"
|
||||||
# Extract filename without extension
|
# Extract filename without extension
|
||||||
$zipBaseFilename = $exeFile.BaseName
|
\$zipBaseFilename = \$exeFile.BaseName
|
||||||
Write-Host "Using executable base filename for archive name: '$zipBaseFilename'"
|
Write-Host "Using executable base filename for archive name: '\$zipBaseFilename'"
|
||||||
} else {
|
} else {
|
||||||
Write-Warning "No executable found matching $exePattern. Using default base filename: '$zipBaseFilename'"
|
Write-Warning "No executable found matching \$exePattern. Using default base filename: '\$zipBaseFilename'"
|
||||||
}
|
}
|
||||||
|
|
||||||
# --- Zipping Logic ---
|
# --- Zipping Logic ---
|
||||||
|
|
||||||
# Get current date and time inYYYYMMDD-HHmmss format
|
# Get current date and time inYYYYMMDD-HHmmss format
|
||||||
$timestamp = (Get-Date -Format "yyyyMMdd-HHmmss")
|
\$timestamp = (Get-Date -Format "yyyyMMdd-HHmmss")
|
||||||
|
|
||||||
# Construct the zip filename using the base filename and timestamp
|
# Construct the zip filename using the base filename and timestamp
|
||||||
$zipFilename = "$zipBaseFilename-$timestamp.zip"
|
\$zipFilename = "\$zipBaseFilename-\$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
|
# Build the 7z command arguments
|
||||||
# Start with command, type, and quoted zip filename
|
# Start with command, type, and quoted zip filename
|
||||||
$sevenZipArgs = @("a", "-tzip", "$zipFilename")
|
\$sevenZipArgs = @("a", "-tzip", "\$zipFilename")
|
||||||
|
|
||||||
# Add the list of found files, ensuring each path is quoted
|
# Add the list of found files, ensuring each path is quoted
|
||||||
# Using backticks to escape quotes within the PowerShell string
|
# Using backticks to escape quotes within the PowerShell string
|
||||||
$foundFilesQuoted = $foundFiles | ForEach-Object { "`"$_`"" }
|
\$foundFilesQuoted = \$foundFiles | ForEach-Object { "\`"$_`"" }
|
||||||
$sevenZipArgs += $foundFilesQuoted
|
\$sevenZipArgs += \$foundFilesQuoted
|
||||||
|
|
||||||
# Construct the full command string for logging
|
# Construct the full command string for logging
|
||||||
$commandString = "$sevenZipExe $($sevenZipArgs -join ' ')"
|
\$commandString = "\$sevenZipExe \$(\$sevenZipArgs -join ' ')"
|
||||||
Write-Host "Executing command: $commandString"
|
Write-Host "Executing command: \$commandString"
|
||||||
|
|
||||||
# Execute the 7z command
|
# Execute the 7z command
|
||||||
# Using Start-Process with -Wait to ensure the script waits for 7z to finish
|
# Using Start-Process with -Wait to ensure the script waits for 7z to finish
|
||||||
# and capturing the exit code
|
# and capturing the exit code
|
||||||
$process = Start-Process -FilePath $sevenZipExe -ArgumentList $sevenZipArgs -Wait -PassThru
|
\$process = Start-Process -FilePath \$sevenZipExe -ArgumentList \$sevenZipArgs -Wait -PassThru
|
||||||
$exitCode = $process.ExitCode
|
\$exitCode = \$process.ExitCode
|
||||||
|
|
||||||
# Check the last exit code from the external command
|
# Check the last exit code from the external command
|
||||||
if ($exitCode -ne 0) {
|
if (\$exitCode -ne 0) {
|
||||||
Write-Error "Error creating zip archive with 7-Zip. 7z exit code: $exitCode"
|
Write-Error "Error creating zip archive with 7-Zip. 7z exit code: \$exitCode"
|
||||||
exit $exitCode
|
exit \$exitCode
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "Zip archive created successfully by 7-Zip: $zipFilename"
|
Write-Host "Zip archive created successfully by 7-Zip: \$zipFilename"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Write the determined zip filename to a temporary file
|
# Output the determined zip filename to standard output for the Groovy script to capture
|
||||||
Write-Host "Writing determined zip filename '$zipFilename' to temporary file '$tempFilenameFile'..."
|
# Ensure this is the very last thing written to the standard output stream
|
||||||
$zipFilename | Out-File -FilePath $tempFilenameFile -Encoding UTF8 -Force
|
# This output will be captured by returnStdout: true
|
||||||
|
Write-Output \$zipFilename
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
''' // End powershell script
|
''' // End powershell script
|
||||||
|
|
||||||
// Read the zip filename from the temporary file
|
// Capture the output and set the environment variable
|
||||||
def createdZipFilename = ""
|
// The PowerShell script is designed to output ONLY the zip filename to standard output
|
||||||
// The tempFilenameFile variable is already defined above
|
env.CREATED_ZIP_FILENAME = zipFilenameOutput.trim()
|
||||||
|
|
||||||
try {
|
|
||||||
echo "Attempting to read zip filename from temporary file: ${tempFilenameFile}"
|
|
||||||
createdZipFilename = readFile(tempFilenameFile).trim()
|
|
||||||
echo "Successfully read zip filename: ${createdZipFilename}"
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
// This might happen if the PowerShell script failed before writing the file
|
|
||||||
echo "Warning: Temporary filename file '${tempFilenameFile}' not found. Zip creation might have failed."
|
|
||||||
} finally {
|
|
||||||
// Clean up the temporary file using a powershell step
|
|
||||||
try {
|
|
||||||
echo "Cleaning up temporary filename file: ${tempFilenameFile} using powershell"
|
|
||||||
powershell "Remove-Item -Path '${tempFilenameFile}' -Force"
|
|
||||||
echo "Temporary filename file cleaned up."
|
|
||||||
} catch (Exception e) {
|
|
||||||
echo "Warning: Failed to clean up temporary filename file '${tempFilenameFile}': ${e.getMessage()}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Set the environment variable for subsequent stages
|
|
||||||
if (createdZipFilename && !createdZipFilename.trim().isEmpty()) {
|
|
||||||
env.CREATED_ZIP_FILENAME = createdZipFilename
|
|
||||||
echo "Set CREATED_ZIP_FILENAME environment variable to: ${env.CREATED_ZIP_FILENAME}"
|
echo "Set CREATED_ZIP_FILENAME environment variable to: ${env.CREATED_ZIP_FILENAME}"
|
||||||
} else {
|
|
||||||
error "Captured zip filename was empty or could not be read from the temporary file. Cannot archive."
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} // End dir block
|
} // End dir block
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user