Files
annotations/build/jenkins/GDriveUpload
T
dzaitsev 83e5eb04e3 Revert "new" .. revert
This reverts commit 9becf663
2025-05-04 13:08:28 +03:00

135 lines
6.9 KiB
Plaintext

// This pipeline job is triggered by the main AzaionSuite build pipeline.
// It copies build artifacts, zips them, and then triggers the Google Drive upload pipeline.
pipeline {
agent { label 'Win10-BuildMachine' }
tools {
// Git tool might be needed if this Jenkinsfile is in SCM
git 'Default'
// dotnetsdk is not needed here as we only process artifacts
}
environment {
// 7-Zip path (assuming default installation)
SEVEN_ZIP_PATH = "C:/Program Files/7-Zip" // Adjust if 7-Zip is installed elsewhere
// Set the PATH environment variable including 7-Zip
PATH = "${SEVEN_ZIP_PATH};${env.PATH}" // Add 7-Zip to PATH
// Define the name of your existing Google Drive upload pipeline job
// ** IMPORTANT: Replace 'YourGoogleDriveUploadPipelineName' with the actual name **
GOOGLE_DRIVE_UPLOAD_JOB_NAME = 'YourGoogleDriveUploadPipelineName' // <<== UPDATE THIS
}
stages {
stage('Copy Build Artifacts') {
steps {
script {
echo "Starting 'Copy Build Artifacts' stage."
// Copy artifacts from the upstream build job
// Replace 'AzaionSuite' with the actual name of your main build pipeline job
copyArtifacts(
projectName: 'AzaionSuite', // <<== UPDATE THIS if your main build job name is different
selector: lastSuccessful(), // Copy from the last successful build
// Specify which files to copy. These should match the files produced by the build.
// Assuming artifacts are in the 'suite' directory relative to the upstream workspace root.
filter: 'suite/AzaionSuite*.exe, suite/AzaionSuite*.bin'
// By default, artifacts are copied to the current job's workspace root.
)
echo "Artifacts copied successfully."
}
}
}
stage('Archive Copied Artifacts (7-Zip)') {
steps {
script {
echo "Starting 'Archive Copied Artifacts (7-Zip)' stage."
// The copied artifacts are now in the root of this job's workspace.
def artifactsDirectory = '.' // Artifacts are in the current workspace root
def version = '1.0.0' // Default version
def filesToArchive = []
def exeFound = false
// Find all relevant files in the current workspace root
def foundFiles = findFiles(glob: 'AzaionSuite*.exe') + findFiles(glob: 'AzaionSuite*.bin')
filesToArchive = foundFiles.collect { it.path } // Get list of paths relative to the workspace root
// --- Version Extraction (only from .exe if present) ---
def exeFiles = findFiles(glob: 'AzaionSuite*.exe')
if (exeFiles.size() > 0) {
exeFound = true
def exeFilePath = exeFiles[0].path // Use path from the first found exe
// Regex to find version like 1.2.3 or 1.2.3-4 followed by .exe
// Match against the full path (which is relative to workspace root here)
def matcher = (exeFilePath =~ /AzaionSuite(\d+\.\d+\.\d+(-\d+)?)\.exe/)
if (matcher.find()) {
version = matcher.group(1)
echo "Found version for archive: ${version}"
} else {
echo "Warning: Could not extract version from '${exeFiles[0].name}'. Using default: ${version}"
}
} else {
echo "Warning: No executable found to extract version for archive. Using default: ${version}"
}
// --- Zipping Logic ---
if (filesToArchive.size() > 0) {
// Get current date and time in YYYYMMdd-HHMMSS format using PowerShell
// Using a separate bat call to ensure output is captured cleanly
def timestamp = bat(
script: 'powershell -Command "Get-Date -Format YYYYMMdd-HHmmss"',
returnStdout: true
).trim() // Trim to remove potential newline characters
def zipFilename = "AzaionSuite.${version}-${timestamp}.zip"
// 7-Zip command requires quoting paths with spaces.
// We provide full paths relative to the workspace root.
def filesListString = filesToArchive.collect { "\"${it}\"" }.join(' ') // Quote each file path and join
echo "Creating zip archive: ${zipFilename} using 7-Zip."
echo "Files to include (full paths): ${filesListString}"
// Construct the full 7z command string in Groovy
def sevenZipCommand = "7z a -tzip \"${zipFilename}\" ${filesListString}"
// Execute the constructed command string using a single bat step
bat """
@echo off
echo Zipping files with 7-Zip...
${sevenZipCommand}
if %errorlevel% neq 0 (
echo Error creating zip archive with 7-Zip. 7z exit code: %errorlevel%
exit /b %errorlevel%
)
echo Zip archive created successfully by 7-Zip.
"""
// Archive the created zip file using Jenkins built-in step
// This makes the zip available for the downstream Google Drive upload job
archiveArtifacts artifacts: "${zipFilename}", fingerprint: true
echo "Archive step completed."
} else {
error "No files (.exe or .bin) found in the copied artifacts to archive. Cannot create zip."
}
}
}
}
stage('Trigger Google Drive Upload') {
steps {
script {
echo "Triggering Google Drive Upload pipeline: ${env.GOOGLE_DRIVE_UPLOAD_JOB_NAME}"
// Trigger the Google Drive upload pipeline
// This assumes the Google Drive job is configured to copy artifacts
// from THIS job (the one creating the zip).
build job: env.GOOGLE_DRIVE_UPLOAD_JOB_NAME
}
}
}
}
// No post section needed for this job, post actions will be handled by the triggered job
}
//test