Files
annotations/build/jenkins/pipeline
T
2025-05-03 15:18:13 +03:00

239 lines
12 KiB
Plaintext

// Add this into polling for 2 minutes ----- */2 * * * *
pipeline {
agent { label 'Win10-BuildMachine' }
tools {
git 'Default' // your Git installation name
dotnetsdk 'dotnet-sdk' // the .NET SDK tool you configured
}
environment {
REPO_ANNOTATOR_URL = 'git@github.com:azaion/annotator.git'
REPO_GPS_DENIED_URL = 'git@github.com:azaion/gps-denied.git'
PROJECT_PATH = 'Azaion.Suite/suite/Azaion.Suite.csproj'
CONFIGURATION = 'Release'
nexusUrl = 'http://192.168.1.101:8081'
nexusRepo = 'AzaionSuite'
nexusCreds = 'a42c7b91-bf8e-4229-be4c-c7edf518dd50' // Jenkins credential ID for Nexus
// CUDA environment variables
CUDA_PATH = "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.2" // Path to CUDA Toolkit
CUDNN_INCLUDE_DIR = "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.2/include" // cuDNN include path (optional)
CUDNN_LIB_DIR = "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.2/lib/x64" // cuDNN library path (optional)
// Inno Setup Compiler path
INNO_SETUP_PATH = "C:/Program Files (x86)/Inno Setup 6" // Path where Inno Setup is installed
// 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 combining CUDA, cuDNN (if applicable), Inno Setup, and 7-Zip paths
PATH = "${SEVEN_ZIP_PATH};${INNO_SETUP_PATH};${CUDA_PATH}/bin;${CUDNN_INCLUDE_DIR};${CUDNN_LIB_DIR};${env.PATH}" // Add 7-Zip, Inno Setup, CUDA, and cuDNN to PATH
}
stages {
stage('Checkout') {
steps {
// Checkout Suite repo using SSH
sshagent(credentials: ['DZ-id']) {
checkout([
$class: 'GitSCM',
branches: [[name: '*/dev']],
userRemoteConfigs: [[
url: "${env.REPO_ANNOTATOR_URL}", // Use SSH URL
]],
extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'suite']]
])
}
// Checkout GPS-Denied repo using SSH
sshagent(credentials: ['DZ-id']) {
checkout([
$class: 'GitSCM',
branches: [[name: '*/image-matcher']],
userRemoteConfigs: [[
url: "${env.REPO_GPS_DENIED_URL}", // Use SSH URL
]],
extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'gps-denied']]
])
}
}
}
stage('Compile Gps Denied') {
steps {
// Run build.cmd in the gps-denied\image-matcher directory
bat 'gps-denied\\image-matcher\\build.cmd'
}
}
stage('Run publish.cmd') {
steps {
// Run publish.cmd in the suite\build directory
// Assuming this script places the build artifacts (.exe and .bin files)
// into the 'suite' directory or a subdirectory within it.
bat 'suite\\build\\publish.cmd'
}
}
stage('Archive Build Artifacts (7-Zip)') {
steps {
script {
echo "Starting 'Archive Build Artifacts (7-Zip)' stage."
def artifactsDirectory = 'suite' // Directory containing the build artifacts relative to workspace
def version = '1.0.0' // Default version
def filesToArchive = []
def exeFound = false
dir(artifactsDirectory) {
// Find all relevant files
def foundFiles = findFiles(glob: 'AzaionSuite*.exe') + findFiles(glob: 'AzaionSuite*.bin')
filesToArchive = foundFiles.collect { it.path } // Get list of paths
// --- 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
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
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
def filesListString = filesToArchive.collect { "\"${it}\"" }.join(' ') // Quote each file path and join
echo "Creating zip archive: ${zipFilename} using 7-Zip."
echo "Files to include: ${filesListString}"
// Use 7z command to create a zip archive
// a: Add files to archive
// -tzip: Specify zip format
// Note: Requires 7-Zip to be installed and 7z.exe in the PATH
bat """
@echo off
echo Zipping files with 7-Zip...
7z a -tzip "${zipFilename}" ${filesListString}
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
archiveArtifacts artifacts: "${zipFilename}", fingerprint: true
echo "Archive step completed."
} else {
echo "No files (.exe or .bin) found in '${artifactsDirectory}' to archive."
}
}
}
}
}
stage('Deploy to Nexus RAW') {
steps {
script {
echo "Starting 'Deploy to Nexus RAW' stage."
def targetDirectory = 'C:/Jenkins/workspace/AzaionSuite/suite' // Assuming this is the workspace path on the agent
def version = '1.0.0' // Default version
def filesToUpload = []
// Define the date formatter (for folder name)
def dateTimeFormat = new java.text.SimpleDateFormat("yyyyMMdd-HHmmss")
dir(targetDirectory) {
// Find both exe and bin files (returns an array)
def exeFiles = findFiles(glob: 'AzaionSuite*.exe')
def binFiles = findFiles(glob: 'AzaionSuite*.bin')
filesToUpload = exeFiles + binFiles // Combine arrays
// --- Version Extraction (only from .exe if present) ---
if (exeFiles.size() > 0) {
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
def matcher = (exeFilePath =~ /AzaionSuite(\d+\.\d+\.\d+(-\d+)?)/)
if (matcher.find()) {
version = matcher.group(1)
echo "Found version for Nexus deployment: ${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 Nexus deployment. Using default: ${version}"
}
// --- Upload Logic ---
if (filesToUpload.size() > 0) {
def now = new Date()
def buildDateTime = dateTimeFormat.format(now) // Format the current date
def uploadFolderName = "AzaionSuite.${version}-${buildDateTime}"
echo "Preparing to upload ${filesToUpload.size()} file(s) to Nexus folder: ${uploadFolderName}"
withCredentials([usernamePassword(credentialsId: nexusCreds, usernameVariable: 'NEXUS_USER', passwordVariable: 'NEXUS_PASSWORD')]) {
filesToUpload.each { file ->
def fileName = file.getName()
def filePath = file.path // file.path should give the full agent path
def uploadUrl = "${nexusUrl}/repository/${nexusRepo}/${uploadFolderName}/${fileName}"
echo "Uploading: ${fileName} to ${uploadUrl}" // Single log per file upload start
// Use bat step for Windows agent commands
bat """
@echo off
echo Uploading "${filePath}" to "${uploadUrl}"
curl -v -f -X PUT -u "${NEXUS_USER}:${NEXUS_PASSWORD}" --upload-file "${filePath}" "${uploadUrl}"
if %errorlevel% neq 0 (
echo Error uploading ${fileName}. Curl exit code: %errorlevel%
exit /b %errorlevel%
)
"""
}
}
} else {
echo "No files to upload to Nexus."
}
}
}
}
}
}
post {
success {
echo 'Build successful. Triggering Google Drive upload pipeline...'
// Trigger the Google Drive upload pipeline
// Replace 'YourGoogleDriveUploadPipelineName' with the actual name of your Google Drive upload pipeline job
build job: 'GoogleDriveUpload'
}
failure {
echo 'Build failed. Google Drive upload pipeline will not be triggered.'
// Optional: Add other actions for failure, like sending notifications
}
// Optional: Add always, unstable, etc. blocks if needed
}
}