Files
annotations/build/jenkins/zip
T
2025-05-04 14:19:02 +03:00

156 lines
6.7 KiB
Plaintext

pipeline {
agent { label 'Win10-BuildMachine' }
tools {
git 'Default'
}
environment {
SEVEN_ZIP_PATH = "C:/Program Files/7-Zip"
PATH = "${SEVEN_ZIP_PATH};${env.PATH}"
GOOGLE_DRIVE_UPLOAD_JOB_NAME = 'GDrive Upload'
MAIN_BUILD_ARTIFACTS_DIR = 'C:/Jenkins/workspace/AzaionSuite/suite'
}
stages {
stage('Archive Build Artifacts (PowerShell/7-Zip)') {
steps {
script {
echo "Starting 'Archive Build Artifacts (PowerShell/7-Zip)' stage."
dir("${env.MAIN_BUILD_ARTIFACTS_DIR}") {
echo "Operating in directory: ${pwd()}"
powershell '''
$ErrorActionPreference = "Stop"
$sevenZipExe = "$env:SEVEN_ZIP_PATH\\7z.exe"
$defaultVersion = "1.0.0"
$exePattern = "AzaionSuite*.exe"
$binPattern = "AzaionSuite*.bin"
$zipPattern = "AzaionSuite*.zip"
Write-Host "Operating in directory: $(Get-Location)"
if (-not (Test-Path $sevenZipExe)) {
Write-Error "7-Zip executable not found at $sevenZipExe"
exit 1
}
$existingZips = Get-ChildItem -Path . -Filter $zipPattern |
Sort-Object LastWriteTime -Descending
$zipFilename = ""
if ($existingZips.Count -gt 0) {
$newestZip = $existingZips | Select-Object -First 1
$zipFilename = $newestZip.Name
Write-Host "Using newest existing zip file: '$zipFilename'."
} else {
Write-Host "No existing zip files found. Creating new zip file."
$foundFiles = Get-ChildItem -Recurse -Path . -Include $exePattern, $binPattern |
Select-Object -ExpandProperty FullName
if ($foundFiles.Count -eq 0) {
Write-Error "No files found to zip."
exit 1
}
$zipBaseFilename = "AzaionSuite.$defaultVersion"
$exeFile = Get-ChildItem -Recurse -Path . -Filter $exePattern | Select-Object -First 1
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) {
Write-Error "7-Zip failed with code $($process.ExitCode)"
exit $process.ExitCode
}
}
catch {
Write-Error "Zip creation failed: $_"
exit 1
}
}
if (-not (Test-Path $zipFilename)) {
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
Write-Host "Zip filename written to zipfilename.txt: $zipFilename"
exit 0
'''
// Read and clean the filename
def zipFilename = readFile('zipfilename.txt').trim()
echo "Read zip filename from file: ${zipFilename}"
// Save to file for next stage
writeFile file: 'created_zip.txt', text: zipFilename
}
}
}
}
stage('Archive Created Zip') {
steps {
script {
echo "Starting 'Archive Created Zip' stage."
dir("${env.MAIN_BUILD_ARTIFACTS_DIR}") {
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)) {
error "File ${zipFilename} does not exist."
}
echo "Archiving zip file: ${zipFilename}"
archiveArtifacts artifacts: "${zipFilename}", fingerprint: true
}
}
}
}
stage('Trigger Google Drive Upload') {
steps {
script {
echo "Triggering Google Drive Upload pipeline: ${env.GOOGLE_DRIVE_UPLOAD_JOB_NAME}"
try {
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."
}
}
}
}
}
post {
success {
script {
def zipFilename = readFile("${env.MAIN_BUILD_ARTIFACTS_DIR}/created_zip.txt").trim()
echo "Pipeline completed successfully. Created and archived zip: ${zipFilename}"
}
}
failure {
echo "Pipeline failed. See logs for details."
}
}
}