From 80e1877c181e5b87bd8ab26c1bcc61e20b4cd66f Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Wed, 7 May 2025 18:49:17 +0300 Subject: [PATCH] pipelines zip and gdrive upload updated --- build/jenkins/GDriveUpload | 123 +++++-------------------------------- build/jenkins/zip | 18 +++--- 2 files changed, 26 insertions(+), 115 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index afa9968..7dc713c 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -2,120 +2,34 @@ pipeline { agent { label 'Win10-BuildMachine' } parameters { - string(name: 'buildPath', defaultValue: 'C:/Jenkins/workspace/Azaion/suite', description: 'Build directory to zip from') - string(name: 'GOOGLE_DRIVE_FOLDER', defaultValue: 'AzaionSuiteBuilds', description: 'Target folder on Google Drive') - } - - tools { - git 'Default' + string(name: 'buildPath', defaultValue: 'C:/Jenkins/workspace/Azaion/suite', description: 'Path where the zip file is located') } environment { - SEVEN_ZIP_PATH = "C:/Program Files/7-Zip" - PATH = "${SEVEN_ZIP_PATH};${env.PATH}" - GOOGLE_DRIVE_UPLOAD_JOB_NAME = 'GDrive Upload' + GOOGLE_DRIVE_FOLDER = 'AzaionSuiteBuilds' } stages { - stage('Detect or Create Zip') { + stage('Upload to Google Drive') { 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..." + echo "Looking for ZIP in: ${params.buildPath}" + echo "Target Google Drive folder: ${env.GOOGLE_DRIVE_FOLDER}" dir("${params.buildPath}") { def zipFilename = readFile('created_zip.txt').trim() 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') { - 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), - string(name: 'GOOGLE_DRIVE_FOLDER', value: params.GOOGLE_DRIVE_FOLDER) - ] + echo "Uploading '${zipFilename}' to Google Drive folder '${env.GOOGLE_DRIVE_FOLDER}'..." + + // Add actual upload logic here (e.g., gsutil, rclone, or API) + // Example (placeholder): + powershell """ + echo Uploading ${zipFilename} to Google Drive... + # rclone copy \"${zipFilename}\" remote:\"${env.GOOGLE_DRIVE_FOLDER}\" + """ + } } } } @@ -123,13 +37,10 @@ pipeline { post { success { - script { - def zipFilename = readFile("${params.buildPath}/created_zip.txt").trim() - echo "Pipeline completed successfully. Final zip: ${zipFilename}" - } + echo "Upload completed." } failure { - echo "Pipeline failed." + echo "Upload failed." } } } diff --git a/build/jenkins/zip b/build/jenkins/zip index 59c4274..4ffed6b 100644 --- a/build/jenkins/zip +++ b/build/jenkins/zip @@ -107,17 +107,17 @@ pipeline { } } - 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), - string(name: 'GOOGLE_DRIVE_FOLDER', value: params.GOOGLE_DRIVE_FOLDER) - ] + 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 {