zip update

This commit is contained in:
dzaitsev
2025-05-04 14:19:02 +03:00
parent 08f93c775b
commit 71e8f088a0
+28 -75
View File
@@ -1,31 +1,15 @@
// This pipeline job is triggered by the main AzaionSuite build pipeline.
// It operates directly within the main build job's artifact directory,
// zips the artifacts using PowerShell and 7-Zip, and then triggers the Google Drive upload pipeline.
pipeline { pipeline {
// Agent should be your Windows VM agent
// This job MUST run on the SAME agent as the main build job
agent { label 'Win10-BuildMachine' } agent { label 'Win10-BuildMachine' }
tools { tools {
// Git tool might be needed if this Jenkinsfile is in SCM
git 'Default' git 'Default'
} }
environment { environment {
// 7-Zip path (assuming default installation) SEVEN_ZIP_PATH = "C:/Program Files/7-Zip"
SEVEN_ZIP_PATH = "C:/Program Files/7-Zip" // Adjust if 7-Zip is installed elsewhere
// Set the PATH environment variable including 7-Zip
PATH = "${SEVEN_ZIP_PATH};${env.PATH}" PATH = "${SEVEN_ZIP_PATH};${env.PATH}"
// Define the name of your existing Google Drive upload pipeline job
GOOGLE_DRIVE_UPLOAD_JOB_NAME = 'GDrive Upload' GOOGLE_DRIVE_UPLOAD_JOB_NAME = 'GDrive Upload'
// Define the source directory for artifacts from the main build job's workspace
MAIN_BUILD_ARTIFACTS_DIR = 'C:/Jenkins/workspace/AzaionSuite/suite' MAIN_BUILD_ARTIFACTS_DIR = 'C:/Jenkins/workspace/AzaionSuite/suite'
// Define the name of the created zip file as an environment variable
CREATED_ZIP_FILENAME = ''
} }
stages { stages {
@@ -36,12 +20,8 @@ pipeline {
dir("${env.MAIN_BUILD_ARTIFACTS_DIR}") { dir("${env.MAIN_BUILD_ARTIFACTS_DIR}") {
echo "Operating in directory: ${pwd()}" echo "Operating in directory: ${pwd()}"
// Use a powershell step with improved error handling and robustness
// First, create a PowerShell script to find the zip file using standard output
powershell ''' powershell '''
$ErrorActionPreference = "Stop" # Stop the script on any error $ErrorActionPreference = "Stop"
# Define key variables
$sevenZipExe = "$env:SEVEN_ZIP_PATH\\7z.exe" $sevenZipExe = "$env:SEVEN_ZIP_PATH\\7z.exe"
$defaultVersion = "1.0.0" $defaultVersion = "1.0.0"
$exePattern = "AzaionSuite*.exe" $exePattern = "AzaionSuite*.exe"
@@ -50,100 +30,73 @@ pipeline {
Write-Host "Operating in directory: $(Get-Location)" Write-Host "Operating in directory: $(Get-Location)"
# Check if 7-Zip exists
if (-not (Test-Path $sevenZipExe)) { if (-not (Test-Path $sevenZipExe)) {
Write-Error "7-Zip executable not found at $sevenZipExe" Write-Error "7-Zip executable not found at $sevenZipExe"
exit 1 exit 1
} }
# Check for existing zip files
$existingZips = Get-ChildItem -Path . -Filter $zipPattern | $existingZips = Get-ChildItem -Path . -Filter $zipPattern |
Sort-Object LastWriteTime -Descending Sort-Object LastWriteTime -Descending
$zipFilename = "" $zipFilename = ""
if ($existingZips.Count -gt 0) { if ($existingZips.Count -gt 0) {
# Found existing zip files, use the newest one
$newestZip = $existingZips | Select-Object -First 1 $newestZip = $existingZips | Select-Object -First 1
$zipFilename = $newestZip.Name $zipFilename = $newestZip.Name
Write-Host "Using newest existing zip file: '$zipFilename'." Write-Host "Using newest existing zip file: '$zipFilename'."
} else { } else {
# No existing zip files, proceed with creation
Write-Host "No existing zip files found. Creating new zip file." Write-Host "No existing zip files found. Creating new zip file."
# Find all files matching the patterns
$foundFiles = Get-ChildItem -Recurse -Path . -Include $exePattern, $binPattern | $foundFiles = Get-ChildItem -Recurse -Path . -Include $exePattern, $binPattern |
Select-Object -ExpandProperty FullName 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 found to zip."
exit 1 exit 1
} }
Write-Host "Found $($foundFiles.Count) file(s) to archive." $zipBaseFilename = "AzaionSuite.$defaultVersion"
$exeFile = Get-ChildItem -Recurse -Path . -Filter $exePattern | Select-Object -First 1
# Determine Base Filename for Zip (from .exe if present)
$zipBaseFilename = "AzaionSuite.$defaultVersion" # Default
$exeFile = Get-ChildItem -Recurse -Path . -Filter $exePattern |
Select-Object -First 1
if ($exeFile) { if ($exeFile) {
$zipBaseFilename = $exeFile.BaseName $zipBaseFilename = $exeFile.BaseName
Write-Host "Using executable base filename: '$zipBaseFilename'"
} else {
Write-Host "No executable found. Using default: '$zipBaseFilename'"
} }
# Get timestamp for filename
$timestamp = (Get-Date -Format "yyyyMMdd-HHmmss") $timestamp = (Get-Date -Format "yyyyMMdd-HHmmss")
$zipFilename = "$zipBaseFilename-$timestamp.zip" $zipFilename = "$zipBaseFilename-$timestamp.zip"
Write-Host "Creating zip archive: $zipFilename" Write-Host "Creating zip archive: $zipFilename"
try { try {
# Build the 7z command arguments
$sevenZipArgs = @("a", "-tzip", "$zipFilename") $sevenZipArgs = @("a", "-tzip", "$zipFilename")
$foundFilesQuoted = $foundFiles | ForEach-Object { "`"$_`"" } $foundFilesQuoted = $foundFiles | ForEach-Object { "`"$_`"" }
$sevenZipArgs += $foundFilesQuoted $sevenZipArgs += $foundFilesQuoted
# Execute the 7z command
$process = Start-Process -FilePath $sevenZipExe -ArgumentList $sevenZipArgs -Wait -NoNewWindow -PassThru $process = Start-Process -FilePath $sevenZipExe -ArgumentList $sevenZipArgs -Wait -NoNewWindow -PassThru
$exitCode = $process.ExitCode if ($process.ExitCode -ne 0) {
Write-Error "7-Zip failed with code $($process.ExitCode)"
if ($exitCode -ne 0) { exit $process.ExitCode
Write-Error "Error creating zip archive. 7z exit code: $exitCode"
exit $exitCode
} }
Write-Host "Zip archive created successfully: $zipFilename"
} }
catch { catch {
Write-Error "Exception occurred during zip creation: $_" Write-Error "Zip creation failed: $_"
exit 1 exit 1
} }
} }
# Verify the zip file exists before returning
if (-not (Test-Path $zipFilename)) { if (-not (Test-Path $zipFilename)) {
Write-Error "Expected zip file $zipFilename does not exist" Write-Error "Expected zip file $zipFilename does not exist"
exit 1 exit 1
} }
# CRITICAL: Write the filename to a temporary file that we can read in Jenkins # Write zip filename WITHOUT BOM (ASCII encoding)
$zipFilename | Out-File -FilePath "zipfilename.txt" -Encoding utf8 -NoNewline Set-Content -Path "zipfilename.txt" -Value $zipFilename -Encoding ASCII
Write-Host "Wrote zip filename to zipfilename.txt: $zipFilename" Write-Host "Zip filename written to zipfilename.txt: $zipFilename"
exit 0 exit 0
''' '''
// Now read the file directly using readFile step // Read and clean the filename
def zipFilename = readFile(file: 'zipfilename.txt').trim() def zipFilename = readFile('zipfilename.txt').trim()
echo "Read zip filename from file: ${zipFilename}" echo "Read zip filename from file: ${zipFilename}"
// Set the environment variable // Save to file for next stage
env.CREATED_ZIP_FILENAME = zipFilename writeFile file: 'created_zip.txt', text: zipFilename
echo "Set CREATED_ZIP_FILENAME to: ${env.CREATED_ZIP_FILENAME}"
// Nothing needed here since we now write the filename to a file and read it directly
} }
} }
} }
@@ -154,22 +107,19 @@ pipeline {
script { script {
echo "Starting 'Archive Created Zip' stage." echo "Starting 'Archive Created Zip' stage."
dir("${env.MAIN_BUILD_ARTIFACTS_DIR}") { dir("${env.MAIN_BUILD_ARTIFACTS_DIR}") {
def zipFilename = readFile('created_zip.txt').trim()
echo "Operating in directory: ${pwd()}" echo "Operating in directory: ${pwd()}"
// Verify zip filename was set properly if (!zipFilename) {
if (!env.CREATED_ZIP_FILENAME?.trim()) { error "Zip filename not found or is empty."
error "CREATED_ZIP_FILENAME environment variable was not set properly."
} }
// Verify the file exists before attempting to archive if (!fileExists(zipFilename)) {
def fileExists = fileExists env.CREATED_ZIP_FILENAME error "File ${zipFilename} does not exist."
if (!fileExists) {
error "File ${env.CREATED_ZIP_FILENAME} does not exist at ${pwd()}."
} }
echo "Archiving zip file: ${env.CREATED_ZIP_FILENAME}" echo "Archiving zip file: ${zipFilename}"
archiveArtifacts artifacts: "${env.CREATED_ZIP_FILENAME}", fingerprint: true archiveArtifacts artifacts: "${zipFilename}", fingerprint: true
echo "Archive step completed."
} }
} }
} }
@@ -184,7 +134,7 @@ pipeline {
echo "Google Drive Upload pipeline triggered successfully." echo "Google Drive Upload pipeline triggered successfully."
} catch (Exception e) { } catch (Exception e) {
echo "Failed to trigger Google Drive Upload pipeline: ${e.message}" echo "Failed to trigger Google Drive Upload pipeline: ${e.message}"
error "Failed to trigger Google Drive Upload pipeline. See console log for details." error "Trigger failed. See logs."
} }
} }
} }
@@ -193,7 +143,10 @@ pipeline {
post { post {
success { success {
echo "Pipeline completed successfully. Created and archived zip: ${env.CREATED_ZIP_FILENAME}" script {
def zipFilename = readFile("${env.MAIN_BUILD_ARTIFACTS_DIR}/created_zip.txt").trim()
echo "Pipeline completed successfully. Created and archived zip: ${zipFilename}"
}
} }
failure { failure {
echo "Pipeline failed. See logs for details." echo "Pipeline failed. See logs for details."