mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 21:46:30 +00:00
zip update
This commit is contained in:
+41
-66
@@ -13,13 +13,11 @@ pipeline {
|
|||||||
}
|
}
|
||||||
|
|
||||||
stages {
|
stages {
|
||||||
stage('Archive Build Artifacts (PowerShell/7-Zip)') {
|
stage('Detect or Create Zip') {
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
echo "Starting 'Archive Build Artifacts (PowerShell/7-Zip)' stage."
|
echo "Starting 'Detect or Create Zip' stage."
|
||||||
dir("${env.MAIN_BUILD_ARTIFACTS_DIR}") {
|
dir("${env.MAIN_BUILD_ARTIFACTS_DIR}") {
|
||||||
echo "Operating in directory: ${pwd()}"
|
|
||||||
|
|
||||||
powershell '''
|
powershell '''
|
||||||
$ErrorActionPreference = "Stop"
|
$ErrorActionPreference = "Stop"
|
||||||
$sevenZipExe = "$env:SEVEN_ZIP_PATH\\7z.exe"
|
$sevenZipExe = "$env:SEVEN_ZIP_PATH\\7z.exe"
|
||||||
@@ -28,97 +26,80 @@ pipeline {
|
|||||||
$binPattern = "AzaionSuite*.bin"
|
$binPattern = "AzaionSuite*.bin"
|
||||||
$zipPattern = "AzaionSuite*.zip"
|
$zipPattern = "AzaionSuite*.zip"
|
||||||
|
|
||||||
Write-Host "Operating in directory: $(Get-Location)"
|
|
||||||
|
|
||||||
if (-not (Test-Path $sevenZipExe)) {
|
if (-not (Test-Path $sevenZipExe)) {
|
||||||
Write-Error "7-Zip executable not found at $sevenZipExe"
|
Write-Error "7-Zip not found at $sevenZipExe"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
$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) {
|
||||||
$newestZip = $existingZips | Select-Object -First 1
|
$zipFilename = $existingZips[0].Name
|
||||||
$zipFilename = $newestZip.Name
|
Write-Host "Using existing zip file: $zipFilename"
|
||||||
Write-Host "Using newest existing zip file: '$zipFilename'."
|
$wasCreated = $false
|
||||||
} else {
|
} else {
|
||||||
Write-Host "No existing zip files found. Creating new zip file."
|
$exeFile = Get-ChildItem -Recurse -Filter $exePattern | Select-Object -First 1
|
||||||
|
if (-not $exeFile) {
|
||||||
|
Write-Error "No EXE file found to create zip"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
$foundFiles = Get-ChildItem -Recurse -Path . -Include $exePattern, $binPattern |
|
$zipBaseFilename = $exeFile.BaseName
|
||||||
Select-Object -ExpandProperty FullName
|
$timestamp = (Get-Date -Format "yyyyMMdd-HHmmss")
|
||||||
|
$zipFilename = "$zipBaseFilename-$timestamp.zip"
|
||||||
|
|
||||||
if ($foundFiles.Count -eq 0) {
|
$filesToZip = Get-ChildItem -Recurse -Include $exePattern, $binPattern | Select-Object -ExpandProperty FullName
|
||||||
|
if ($filesToZip.Count -eq 0) {
|
||||||
Write-Error "No files found to zip."
|
Write-Error "No files found to zip."
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
$zipBaseFilename = "AzaionSuite.$defaultVersion"
|
$args = @("a", "-tzip", "$zipFilename") + ($filesToZip | ForEach-Object { "`"$_`"" })
|
||||||
$exeFile = Get-ChildItem -Recurse -Path . -Filter $exePattern | Select-Object -First 1
|
$process = Start-Process -FilePath $sevenZipExe -ArgumentList $args -Wait -NoNewWindow -PassThru
|
||||||
if ($exeFile) {
|
|
||||||
$zipBaseFilename = $exeFile.BaseName
|
|
||||||
}
|
|
||||||
|
|
||||||
$timestamp = (Get-Date -Format "yyyyMMdd-HHmmss")
|
|
||||||
$zipFilename = "$zipBaseFilename-$timestamp.zip"
|
|
||||||
Write-Host "Creating zip archive: $zipFilename"
|
|
||||||
|
|
||||||
try {
|
|
||||||
$sevenZipArgs = @("a", "-tzip", "$zipFilename")
|
|
||||||
$foundFilesQuoted = $foundFiles | ForEach-Object { "`"$_`"" }
|
|
||||||
$sevenZipArgs += $foundFilesQuoted
|
|
||||||
$process = Start-Process -FilePath $sevenZipExe -ArgumentList $sevenZipArgs -Wait -NoNewWindow -PassThru
|
|
||||||
if ($process.ExitCode -ne 0) {
|
if ($process.ExitCode -ne 0) {
|
||||||
Write-Error "7-Zip failed with code $($process.ExitCode)"
|
Write-Error "7-Zip failed with code $($process.ExitCode)"
|
||||||
exit $process.ExitCode
|
exit $process.ExitCode
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch {
|
$wasCreated = $true
|
||||||
Write-Error "Zip creation failed: $_"
|
Write-Host "Created new zip file: $zipFilename"
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (-not (Test-Path $zipFilename)) {
|
# Save outputs without BOM
|
||||||
Write-Error "Expected zip file $zipFilename does not exist"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# Write zip filename WITHOUT BOM (ASCII encoding)
|
|
||||||
Set-Content -Path "zipfilename.txt" -Value $zipFilename -Encoding ASCII
|
Set-Content -Path "zipfilename.txt" -Value $zipFilename -Encoding ASCII
|
||||||
Write-Host "Zip filename written to zipfilename.txt: $zipFilename"
|
Set-Content -Path "zip_created.txt" -Value $wasCreated -Encoding ASCII
|
||||||
exit 0
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
// Read and clean the filename
|
|
||||||
def zipFilename = readFile('zipfilename.txt').trim()
|
def zipFilename = readFile('zipfilename.txt').trim()
|
||||||
echo "Read zip filename from file: ${zipFilename}"
|
def zipCreated = readFile('zip_created.txt').trim().toBoolean()
|
||||||
|
|
||||||
// Save to file for next stage
|
echo "Zip filename: ${zipFilename}"
|
||||||
|
echo "Was zip created this run? ${zipCreated}"
|
||||||
|
|
||||||
|
// Save results for next stages
|
||||||
writeFile file: 'created_zip.txt', text: zipFilename
|
writeFile file: 'created_zip.txt', text: zipFilename
|
||||||
|
writeFile file: 'zip_was_created.txt', text: zipCreated.toString()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Archive Created Zip') {
|
stage('Archive Zip File (if new)') {
|
||||||
|
when {
|
||||||
|
expression {
|
||||||
|
def zipCreated = readFile("${env.MAIN_BUILD_ARTIFACTS_DIR}/zip_was_created.txt").trim().toBoolean()
|
||||||
|
return zipCreated
|
||||||
|
}
|
||||||
|
}
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
echo "Starting 'Archive Created Zip' stage."
|
echo "Archiving newly created zip file..."
|
||||||
dir("${env.MAIN_BUILD_ARTIFACTS_DIR}") {
|
dir("${env.MAIN_BUILD_ARTIFACTS_DIR}") {
|
||||||
def zipFilename = readFile('created_zip.txt').trim()
|
def zipFilename = readFile('created_zip.txt').trim()
|
||||||
echo "Operating in directory: ${pwd()}"
|
|
||||||
|
|
||||||
if (!zipFilename) {
|
|
||||||
error "Zip filename not found or is empty."
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!fileExists(zipFilename)) {
|
if (!fileExists(zipFilename)) {
|
||||||
error "File ${zipFilename} does not exist."
|
error "Zip file '${zipFilename}' not found!"
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "Archiving zip file: ${zipFilename}"
|
|
||||||
archiveArtifacts artifacts: "${zipFilename}", fingerprint: true
|
archiveArtifacts artifacts: "${zipFilename}", fingerprint: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -129,13 +110,7 @@ pipeline {
|
|||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
echo "Triggering Google Drive Upload pipeline: ${env.GOOGLE_DRIVE_UPLOAD_JOB_NAME}"
|
echo "Triggering Google Drive Upload pipeline: ${env.GOOGLE_DRIVE_UPLOAD_JOB_NAME}"
|
||||||
try {
|
|
||||||
build job: env.GOOGLE_DRIVE_UPLOAD_JOB_NAME
|
build job: env.GOOGLE_DRIVE_UPLOAD_JOB_NAME
|
||||||
echo "Google Drive Upload pipeline triggered successfully."
|
|
||||||
} catch (Exception e) {
|
|
||||||
echo "Failed to trigger Google Drive Upload pipeline: ${e.message}"
|
|
||||||
error "Trigger failed. See logs."
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -145,11 +120,11 @@ pipeline {
|
|||||||
success {
|
success {
|
||||||
script {
|
script {
|
||||||
def zipFilename = readFile("${env.MAIN_BUILD_ARTIFACTS_DIR}/created_zip.txt").trim()
|
def zipFilename = readFile("${env.MAIN_BUILD_ARTIFACTS_DIR}/created_zip.txt").trim()
|
||||||
echo "Pipeline completed successfully. Created and archived zip: ${zipFilename}"
|
echo "Pipeline completed successfully. Final zip: ${zipFilename}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
failure {
|
failure {
|
||||||
echo "Pipeline failed. See logs for details."
|
echo "Pipeline failed."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user