mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 22:36:31 +00:00
131 lines
5.5 KiB
Plaintext
131 lines
5.5 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('Detect or Create Zip') {
|
|
steps {
|
|
script {
|
|
echo "Starting 'Detect or Create Zip' stage."
|
|
dir("${env.MAIN_BUILD_ARTIFACTS_DIR}") {
|
|
powershell '''
|
|
$ErrorActionPreference = "Stop"
|
|
$sevenZipExe = "$env:SEVEN_ZIP_PATH\\7z.exe"
|
|
$defaultVersion = "1.0.0"
|
|
$exePattern = "AzaionSuite*.exe"
|
|
$binPattern = "AzaionSuite*.bin"
|
|
$zipPattern = "AzaionSuite*.zip"
|
|
|
|
if (-not (Test-Path $sevenZipExe)) {
|
|
Write-Error "7-Zip not found at $sevenZipExe"
|
|
exit 1
|
|
}
|
|
|
|
$existingZips = Get-ChildItem -Path . -Filter $zipPattern | Sort-Object LastWriteTime -Descending
|
|
$zipFilename = ""
|
|
|
|
if ($existingZips.Count -gt 0) {
|
|
$zipFilename = $existingZips[0].Name
|
|
Write-Host "Using existing zip file: $zipFilename"
|
|
$wasCreated = $false
|
|
} else {
|
|
$exeFile = Get-ChildItem -Recurse -Filter $exePattern | Select-Object -First 1
|
|
if (-not $exeFile) {
|
|
Write-Error "No EXE file found to create zip"
|
|
exit 1
|
|
}
|
|
|
|
$zipBaseFilename = $exeFile.BaseName
|
|
$timestamp = (Get-Date -Format "yyyyMMdd-HHmmss")
|
|
$zipFilename = "$zipBaseFilename-$timestamp.zip"
|
|
|
|
$filesToZip = Get-ChildItem -Recurse -Include $exePattern, $binPattern | Select-Object -ExpandProperty FullName
|
|
if ($filesToZip.Count -eq 0) {
|
|
Write-Error "No files found to zip."
|
|
exit 1
|
|
}
|
|
|
|
$args = @("a", "-tzip", "$zipFilename") + ($filesToZip | ForEach-Object { "`"$_`"" })
|
|
$process = Start-Process -FilePath $sevenZipExe -ArgumentList $args -Wait -NoNewWindow -PassThru
|
|
if ($process.ExitCode -ne 0) {
|
|
Write-Error "7-Zip failed with code $($process.ExitCode)"
|
|
exit $process.ExitCode
|
|
}
|
|
|
|
$wasCreated = $true
|
|
Write-Host "Created new zip file: $zipFilename"
|
|
}
|
|
|
|
# Save outputs without BOM
|
|
Set-Content -Path "zipfilename.txt" -Value $zipFilename -Encoding ASCII
|
|
Set-Content -Path "zip_created.txt" -Value $wasCreated -Encoding ASCII
|
|
'''
|
|
|
|
def zipFilename = readFile('zipfilename.txt').trim()
|
|
def zipCreated = readFile('zip_created.txt').trim().toBoolean()
|
|
|
|
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: 'zip_was_created.txt', text: zipCreated.toString()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
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 {
|
|
script {
|
|
echo "Archiving newly created zip file..."
|
|
dir("${env.MAIN_BUILD_ARTIFACTS_DIR}") {
|
|
def zipFilename = readFile('created_zip.txt').trim()
|
|
if (!fileExists(zipFilename)) {
|
|
error "Zip file '${zipFilename}' not found!"
|
|
}
|
|
archiveArtifacts artifacts: "${zipFilename}", fingerprint: true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
stage('Trigger Google Drive Upload') {
|
|
steps {
|
|
script {
|
|
echo "Triggering Google Drive Upload pipeline: ${env.GOOGLE_DRIVE_UPLOAD_JOB_NAME}"
|
|
build job: env.GOOGLE_DRIVE_UPLOAD_JOB_NAME
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
post {
|
|
success {
|
|
script {
|
|
def zipFilename = readFile("${env.MAIN_BUILD_ARTIFACTS_DIR}/created_zip.txt").trim()
|
|
echo "Pipeline completed successfully. Final zip: ${zipFilename}"
|
|
}
|
|
}
|
|
failure {
|
|
echo "Pipeline failed."
|
|
}
|
|
}
|
|
}
|