pipelines zip and gdrive upload

updated
This commit is contained in:
dzaitsev
2025-05-07 18:49:17 +03:00
parent e6ec904657
commit 80e1877c18
2 changed files with 26 additions and 115 deletions
+17 -106
View File
@@ -2,120 +2,34 @@ pipeline {
agent { label 'Win10-BuildMachine' } agent { label 'Win10-BuildMachine' }
parameters { parameters {
string(name: 'buildPath', defaultValue: 'C:/Jenkins/workspace/Azaion/suite', description: 'Build directory to zip from') string(name: 'buildPath', defaultValue: 'C:/Jenkins/workspace/Azaion/suite', description: 'Path where the zip file is located')
string(name: 'GOOGLE_DRIVE_FOLDER', defaultValue: 'AzaionSuiteBuilds', description: 'Target folder on Google Drive')
}
tools {
git 'Default'
} }
environment { environment {
SEVEN_ZIP_PATH = "C:/Program Files/7-Zip" GOOGLE_DRIVE_FOLDER = 'AzaionSuiteBuilds'
PATH = "${SEVEN_ZIP_PATH};${env.PATH}"
GOOGLE_DRIVE_UPLOAD_JOB_NAME = 'GDrive Upload'
} }
stages { stages {
stage('Detect or Create Zip') { stage('Upload to Google Drive') {
steps { steps {
script { script {
echo "Starting 'Detect or Create Zip' stage." echo "Looking for ZIP in: ${params.buildPath}"
echo "Using build path: ${params.buildPath}" echo "Target Google Drive folder: ${env.GOOGLE_DRIVE_FOLDER}"
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}") { dir("${params.buildPath}") {
def zipFilename = readFile('created_zip.txt').trim() def zipFilename = readFile('created_zip.txt').trim()
if (!fileExists(zipFilename)) { if (!fileExists(zipFilename)) {
error "Zip file '${zipFilename}' not found!" error "Zip file '${zipFilename}' not found in ${params.buildPath}"
} }
archiveArtifacts artifacts: "${zipFilename}", fingerprint: true
}
}
}
}
stage('Trigger Google Drive Upload') { echo "Uploading '${zipFilename}' to Google Drive folder '${env.GOOGLE_DRIVE_FOLDER}'..."
steps {
script { // Add actual upload logic here (e.g., gsutil, rclone, or API)
echo "Triggering Google Drive Upload pipeline: ${env.GOOGLE_DRIVE_UPLOAD_JOB_NAME}" // Example (placeholder):
build job: env.GOOGLE_DRIVE_UPLOAD_JOB_NAME, parameters: [ powershell """
string(name: 'buildPath', value: params.buildPath), echo Uploading ${zipFilename} to Google Drive...
string(name: 'GOOGLE_DRIVE_FOLDER', value: params.GOOGLE_DRIVE_FOLDER) # rclone copy \"${zipFilename}\" remote:\"${env.GOOGLE_DRIVE_FOLDER}\"
] """
}
} }
} }
} }
@@ -123,13 +37,10 @@ pipeline {
post { post {
success { success {
script { echo "Upload completed."
def zipFilename = readFile("${params.buildPath}/created_zip.txt").trim()
echo "Pipeline completed successfully. Final zip: ${zipFilename}"
}
} }
failure { failure {
echo "Pipeline failed." echo "Upload failed."
} }
} }
} }
+9 -9
View File
@@ -107,17 +107,17 @@ pipeline {
} }
} }
stage('Trigger Google Drive Upload') { stage('Trigger Google Drive Upload') {
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}"
build job: env.GOOGLE_DRIVE_UPLOAD_JOB_NAME, parameters: [ build job: env.GOOGLE_DRIVE_UPLOAD_JOB_NAME, parameters: [
string(name: 'buildPath', value: params.buildPath), string(name: 'buildPath', value: params.buildPath)
string(name: 'GOOGLE_DRIVE_FOLDER', value: params.GOOGLE_DRIVE_FOLDER) ]
] }
}
} }
} }
}
post { post {
success { success {