mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 22:26:31 +00:00
80e1877c18
updated
134 lines
5.5 KiB
Plaintext
134 lines
5.5 KiB
Plaintext
pipeline {
|
|
agent { label 'Win10-BuildMachine' }
|
|
|
|
parameters {
|
|
string(name: 'buildPath', defaultValue: 'C:/Jenkins/workspace/Azaion/suite', description: 'Build directory to zip from')
|
|
}
|
|
|
|
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'
|
|
}
|
|
|
|
stages {
|
|
stage('Detect or Create Zip') {
|
|
steps {
|
|
script {
|
|
echo "Starting 'Detect or Create Zip' stage."
|
|
echo "Using build path: ${params.buildPath}"
|
|
dir("${params.buildPath}") {
|
|
powershell '''
|
|
$ErrorActionPreference = "Stop"
|
|
$sevenZipExe = "$env:SEVEN_ZIP_PATH\\7z.exe"
|
|
$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"
|
|
}
|
|
|
|
Set-Content -Path "zipfilename.txt" -Value $zipFilename -Encoding ASCII
|
|
Set-Content -Path "zip_was_created.txt" -Value $wasCreated -Encoding ASCII
|
|
'''
|
|
|
|
def zipFilename = readFile('zipfilename.txt').trim()
|
|
def zipCreated = readFile('zip_was_created.txt').trim().toBoolean()
|
|
|
|
echo "Zip filename: ${zipFilename}"
|
|
echo "Was zip created this run? ${zipCreated}"
|
|
|
|
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("${params.buildPath}/zip_was_created.txt").trim().toBoolean()
|
|
return zipCreated
|
|
}
|
|
}
|
|
steps {
|
|
script {
|
|
echo "Archiving newly created zip file..."
|
|
dir("${params.buildPath}") {
|
|
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, parameters: [
|
|
string(name: 'buildPath', value: params.buildPath)
|
|
]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
post {
|
|
success {
|
|
script {
|
|
def zipFilename = readFile("${params.buildPath}/created_zip.txt").trim()
|
|
echo "Pipeline completed successfully. Final zip: ${zipFilename}"
|
|
}
|
|
}
|
|
failure {
|
|
echo "Pipeline failed."
|
|
}
|
|
}
|
|
}
|