zip update

This commit is contained in:
dzaitsev
2025-05-04 14:16:49 +03:00
parent 98d99ec7be
commit 08f93c775b
+12 -51
View File
@@ -37,7 +37,8 @@ pipeline {
echo "Operating in directory: ${pwd()}"
// Use a powershell step with improved error handling and robustness
def zipFilenameOutput = powershell returnStdout: true, script: '''
// First, create a PowerShell script to find the zip file using standard output
powershell '''
$ErrorActionPreference = "Stop" # Stop the script on any error
# Define key variables
@@ -128,61 +129,21 @@ pipeline {
exit 1
}
# This is the critical fix - we need to make sure this is the last thing output
# And ensure it's on its own line with no other text
Write-Host "ZIPFILENAME=$zipFilename"
# CRITICAL: Write the filename to a temporary file that we can read in Jenkins
$zipFilename | Out-File -FilePath "zipfilename.txt" -Encoding utf8 -NoNewline
Write-Host "Wrote zip filename to zipfilename.txt: $zipFilename"
exit 0
'''
// Debug: Print raw PowerShell output to see what we're getting
echo "Raw PowerShell output: ${zipFilenameOutput}"
// Now read the file directly using readFile step
def zipFilename = readFile(file: 'zipfilename.txt').trim()
echo "Read zip filename from file: ${zipFilename}"
// The output may have Windows line endings, split by any common line ending
def outputLines = zipFilenameOutput.split('(?:\\r\\n|\\n|\\r)')
echo "Found ${outputLines.size()} lines in output"
// Set the environment variable
env.CREATED_ZIP_FILENAME = zipFilename
echo "Set CREATED_ZIP_FILENAME to: ${env.CREATED_ZIP_FILENAME}"
def zipFilename = null
// Debug: Print each line of output
for (int i = 0; i < outputLines.size(); i++) {
echo "Line ${i}: ${outputLines[i]}"
if (outputLines[i].trim().contains("ZIPFILENAME=")) {
zipFilename = outputLines[i].trim().substring(outputLines[i].trim().indexOf("ZIPFILENAME=") + 11)
echo "Found zip filename in line ${i}: ${zipFilename}"
break
}
}
if (zipFilename) {
env.CREATED_ZIP_FILENAME = zipFilename.trim()
echo "Setting CREATED_ZIP_FILENAME to: ${env.CREATED_ZIP_FILENAME}"
} else {
// If we can't find the ZIPFILENAME marker, try a fallback approach
// Look for the line containing "Using newest existing zip file:" or "Zip archive created successfully:"
for (int i = 0; i < outputLines.size(); i++) {
def line = outputLines[i].trim()
if (line.contains("Using newest existing zip file: '") && line.contains(".zip'")) {
def start = line.indexOf("'") + 1
def end = line.lastIndexOf("'")
if (start > 0 && end > start) {
zipFilename = line.substring(start, end)
echo "Extracted zip filename from 'Using newest' line: ${zipFilename}"
break
}
} else if (line.contains("Zip archive created successfully: ") && line.contains(".zip")) {
def start = line.indexOf("Zip archive created successfully: ") + 30
zipFilename = line.substring(start).trim()
echo "Extracted zip filename from 'created successfully' line: ${zipFilename}"
break
}
}
if (zipFilename) {
env.CREATED_ZIP_FILENAME = zipFilename.trim()
echo "Setting CREATED_ZIP_FILENAME using fallback to: ${env.CREATED_ZIP_FILENAME}"
} else {
error "Failed to extract zip filename from PowerShell output after multiple attempts. Check PowerShell script."
}
}
// Nothing needed here since we now write the filename to a file and read it directly
}
}
}