From 2ad40e165d0e3374f29ce105e3be71e5340bc335 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 13:21:46 +0300 Subject: [PATCH 01/85] 1111 --- build/jenkins/GDriveUpload | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index 994e256..48bee74 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -132,4 +132,4 @@ pipeline { } // No post section needed for this job, post actions will be handled by the triggered job } -//test \ No newline at end of file +//test1111 \ No newline at end of file From 6a336e90c5b82b795c089df18bc428e0fc56e9af Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 13:24:13 +0300 Subject: [PATCH 02/85] added zip --- build/jenkins/zip | 201 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 201 insertions(+) create mode 100644 build/jenkins/zip diff --git a/build/jenkins/zip b/build/jenkins/zip new file mode 100644 index 0000000..5a673f3 --- /dev/null +++ b/build/jenkins/zip @@ -0,0 +1,201 @@ +// This pipeline job is triggered by the main AzaionSuite build pipeline. +// It operates directly within the main build job's artifact directory, +// zips the artifacts using Batch and 7-Zip, and then triggers the Google Drive upload pipeline. +pipeline { + // Agent should be your Windows VM agent + // This job MUST run on the SAME agent as the main build job + 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 = 'GDrive Upload' // <<== UPDATE THIS + + // Define the source directory for artifacts from the main build job's workspace + // This is the directory this pipeline will change into to operate. + // ** IMPORTANT: Replace 'C:/Jenkins/workspace/AzaionSuite/suite' with the actual path ** + MAIN_BUILD_ARTIFACTS_DIR = 'C:/Jenkins/workspace/AzaionSuite/suite' // <<== UPDATE THIS + + // Define the name of the created zip file as an environment variable + // This makes it easier to reference in later stages + CREATED_ZIP_FILENAME = '' // This will be set dynamically + } + + stages { + // Removed the 'Copy Build Artifacts' stage. + // This pipeline will now operate directly in the MAIN_BUILD_ARTIFACTS_DIR. + + stage('Archive Build Artifacts (Batch/7-Zip)') { + steps { + script { // Need script block for dir and bat step + echo "Starting 'Archive Build Artifacts (Batch/7-Zip)' stage." + // Change directory to the main build job's artifacts folder + dir("${env.MAIN_BUILD_ARTIFACTS_DIR}") { + echo "Operating in directory: ${pwd()}" + + // Define the expected artifact patterns relative to the current directory (MAIN_BUILD_ARTIFACTS_DIR) + def exePattern = 'AzaionSuite*.exe' + def binPattern = 'AzaionSuite*.bin' + // Define defaultVersion here, as it's used within the bat script + def defaultVersion = '1.0.0' + + + // Use a bat step to perform file finding, version extraction, timestamp generation, and zipping + bat """ + @echo off + setlocal enabledelayedexpansion + + set "SEVEN_ZIP_EXE=%SEVEN_ZIP_PATH%\\7z.exe" + set "DEFAULT_VERSION=${defaultVersion}" + set "EXE_PATTERN=${exePattern}" + set "BIN_PATTERN=${binPattern}" + + echo Searching for files matching %EXE_PATTERN% and %BIN_PATTERN% in the current directory for zipping... + + set "FOUND_FILES=" + set "EXE_FILE=" + rem Find .exe and .bin files and build a list of quoted paths + for /R . %%F in (%EXE_PATTERN% %BIN_PATTERN%) do ( + rem Add the quoted full path to FOUND_FILES + set "FOUND_FILES=!FOUND_FILES! "%%F"" + rem Check if it's an exe for version extraction and store the first one found + echo "%%F" | findstr /I /E "\\\\.exe" >nul && if not defined EXE_FILE set "EXE_FILE=%%F" + ) + + if not defined FOUND_FILES ( + echo No files matching patterns %EXE_PATTERN% or %BIN_PATTERN% found in %CD%. + exit /b 1 + ) + + rem Count files (basic count based on spaces, might be inaccurate with complex paths) + set "file_count=0" + for %%F in (%FOUND_FILES%) do set /a file_count+=1 + echo Found !file_count! file(s) to archive. + + + rem --- Version Extraction (only from .exe if present) --- + set "VERSION=%DEFAULT_VERSION%" + if defined EXE_FILE ( + echo Attempting to extract version from "%EXE_FILE%"... + rem Extract filename from full path + for %%I in ("%EXE_FILE%") do set "EXE_FILENAME=%%~nxI" + rem Extract part after AzaionSuite and before .exe + rem Assumes format AzaionSuite.exe + set "TEMP_VERSION=!EXE_FILENAME:AzaionSuite=!" + set "VERSION=!TEMP_VERSION:.exe=!" + rem Basic check if extraction was successful + if "!VERSION!" == "!TEMP_VERSION!" ( + echo Warning: Could not extract version from "%EXE_FILENAME%". Using default: %VERSION% + set "VERSION=%DEFAULT_VERSION%" + ) else ( + echo Found version for archive: %VERSION% + ) + ) else ( + echo Warning: No executable found to extract version for archive. Using default: %VERSION% + ) + + + rem --- Zipping Logic --- + + rem Get current date and time inMMDD-HHmmss format using wmic + rem wmic output format is LocalDateTime=YYYYMMDDHHMMSS.milliseconds+UTCoffset + for /f "tokens=2 delims==" %%a in ('wmic os get localdatetime /value') do set "dt=%%a" + set "YYYY=%dt:~0,4%" + set "MM=%dt:~4,2%" + set "DD=%dt:~6,2%" + set "HH=%dt:~8,2%" + set "mm=%dt:~10,2%" + set "SS=%dt:~12,2%" + set "timestamp=%YYYY%%MM%%DD%-%HH%%mm%%SS%" + + set "ZIP_FILENAME=AzaionSuite.%VERSION%-%timestamp%.zip" + + echo Creating zip archive: %ZIP_FILENAME% using 7-Zip. + + rem Build the 7z command string correctly + rem Start with quoted executable path, command, type, and quoted zip filename + set "SEVEN_ZIP_COMMAND=""%SEVEN_ZIP_EXE%" a -tzip "%ZIP_FILENAME%"" + + rem Append the list of found files (which are already quoted and space-separated) + set "SEVEN_ZIP_COMMAND=%SEVEN_ZIP_COMMAND%%FOUND_FILES%" + + + echo Executing command: %SEVEN_ZIP_COMMAND% + + rem Execute the constructed command string + %SEVEN_ZIP_COMMAND% + + rem Check the last exit code from the external command + 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: %ZIP_FILENAME% + + rem Output the zip filename and set it as an environment variable for Jenkins + rem This uses the Jenkins 'set context' feature + echo ::SET-ZIP-FILENAME::%ZIP_FILENAME% + echo ::SET-ENV::CREATED_ZIP_FILENAME=%ZIP_FILENAME% + + exit /b 0 + """ // End bat script + } // End dir block + } + } + } + stage('Archive Created Zip') { + steps { + script { // Need script block for dir and accessing environment variables set by Batch + echo "Starting 'Archive Created Zip' stage." + // Change directory back to the main build job's artifacts folder to archive the zip + dir("${env.MAIN_BUILD_ARTIFACTS_DIR}") { + echo "Operating in directory: ${pwd()}" + // The zip filename was set as an environment variable in the previous stage + def createdZipFilename = env.CREATED_ZIP_FILENAME + + if (createdZipFilename) { + echo "Identified created zip file for archiving: ${createdZipFilename}" + // Archive the created zip file using Jenkins built-in step + // The zip file is created in the MAIN_BUILD_ARTIFACTS_DIR by the Batch script + archiveArtifacts artifacts: "${createdZipFilename}", fingerprint: true + echo "Archive step completed." + } else { + error "CREATED_ZIP_FILENAME environment variable was not set. Cannot archive." + } + } // End dir block + } + } + } + + + stage('Trigger Google Drive Upload') { + steps { + script { // This stage still requires a script block for the build step + echo "Triggering Google Drive Upload pipeline: ${env.GOOGLE_DRIVE_UPLOAD_JOB_NAME}" + // build job is a Jenkins Pipeline step, cannot be replaced by Batch directly. + // 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 and archiving it). + // The 'build' step executes from the current directory, which is inside the dir block. + dir("${env.MAIN_BUILD_ARTIFACTS_DIR}") { + echo "Operating in directory: ${pwd()}" + build job: env.GOOGLE_DRIVE_UPLOAD_JOB_NAME + } // End dir block + } // End script block + } // End steps block + } // End stage block + } // End of stages block +} // End of pipeline block From 44769ca422238e70ac109cb63c3d00c311a8cb9f Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 13:25:55 +0300 Subject: [PATCH 03/85] gdrive update zip update --- build/jenkins/GDriveUpload | 387 +++++++++++++++++++++++++++---------- build/jenkins/zip | 2 +- 2 files changed, 282 insertions(+), 107 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index 48bee74..0c1c158 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -1,135 +1,310 @@ -// 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. +// Jenkins Pipeline script to directly copy the zip file from an upstream job's workspace, +// derive build identifier from the zip filename, and upload to Google Drive with retention. +// Retention is based on the timestamp embedded in the filename and performed entirely in PowerShell. +// Designed to run on a Windows agent. +// Assumes rclone is installed and its directory is added to the system's PATH on the Windows agent. + pipeline { + // Agent should be your Windows VM agent + agent { label 'Win10-BuildMachine' } // Replace with your Windows agent label if different - 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 - } + // Removed parameters block as we don't need upstream job name/build number parameters anymore environment { - // 7-Zip path (assuming default installation) - SEVEN_ZIP_PATH = "C:/Program Files/7-Zip" // Adjust if 7-Zip is installed elsewhere + GDRIVE_REMOTE = 'AzaionGoogleDrive:AzaionSuiteBuilds' // Your rclone remote name and path + // Use a relative path within the workspace for the temporary directory on Windows + // This temporary directory will hold the copied zip file before upload + TMP_UPLOAD_DIR = 'temp_upload' + // Path to rclone.conf on the Windows agent. + // Adjust this path if your rclone.conf is located elsewhere on the Windows VM. + // Using a relative path from the workspace root is often best practice. + RCLONE_CONFIG = 'rclone.conf' // Assuming rclone.conf is in the workspace root - // Set the PATH environment variable including 7-Zip - PATH = "${SEVEN_ZIP_PATH};${env.PATH}" // Add 7-Zip to PATH + // Define the FULL path to the upstream job's workspace on the SAME agent + // This assumes both jobs run on the same agent and you know the workspace path structure + UPSTREAM_WORKSPACE = 'C:\\Jenkins\\workspace\\AzaionSuite' // **Adjust this path if necessary** - // 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 + // Define the path to the zip file relative to the upstream workspace + // Based on your description: C:\Jenkins\workspace\AzaionSuite\suite\AzaionSuite.1.4.5-YYYYMMDD-HHMMSS.zip + // We'll use a wildcard to find the specific timestamped zip + UPSTREAM_ZIP_PATH_RELATIVE = 'suite\\*.zip' // **Reverted filter to only look for .zip** + + // Number of latest files to keep on Google Drive + FILES_TO_KEEP = 3 } stages { - stage('Copy Build Artifacts') { + stage('Initialize') { 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." - } + echo "Initializing workspace on Windows agent..." + + // Use standard Windows PowerShell for directory creation and cleanup + // Ensure paths are quoted for safety + powershell """ + # Create temporary upload directory + New-Item -ItemType Directory -Force -Path "${env:WORKSPACE}\\\\${env:TMP_UPLOAD_DIR}" + + # Clean up previous temporary files in the upload directory + Remove-Item -Recurse -Force "${env:WORKSPACE}\\\\${env:TMP_UPLOAD_DIR}\\\\*" -ErrorAction SilentlyContinue + """ } } - stage('Archive Copied Artifacts (7-Zip)') { + // Removed the 'Copy Last Stable Artifact' stage + + stage('Copy and Upload Build') { // Combined stage for copying, finding name, and conditional upload 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 + script { // Wrap steps in a script block + echo "Starting Copy and Upload Build stage..." - // 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 + def upstreamZipFullPath = null + def copiedZipFilename = null + def copiedZipFilePath = null + def expectedZipFilenameOnDrive = null + + // --- Find the full path of the zip file in the upstream workspace --- + try { + echo "Attempting to find the zip file in upstream workspace: ${env.UPSTREAM_WORKSPACE}\\\\${env.UPSTREAM_ZIP_PATH_RELATIVE}" + // Use PowerShell to find the first file matching the pattern (.zip only) + // Use -ErrorAction Stop to ensure the error is caught by Groovy try/catch + // Ensure paths are quoted for safety + upstreamZipFullPath = powershell(script: "Get-ChildItem -Path \"${env:UPSTREAM_WORKSPACE}\\\\${env:UPSTREAM_ZIP_PATH_RELATIVE}\" -ErrorAction Stop | Select-Object -First 1 -ExpandProperty FullName", returnStdout: true).trim() + + if (upstreamZipFullPath) { + echo "Found upstream file: ${upstreamZipFullPath}" + // Extract just the filename from the full path + copiedZipFilename = upstreamZipFullPath.substring(upstreamZipFullPath.lastIndexOf('\\') + 1) + echo "Derived filename: ${copiedZipFilename}" + // DEBUG: Show the derived filename explicitly + echo "DEBUG: Derived copiedZipFilename = '${copiedZipFilename}'" + + // --- Removed Workaround: Remove trailing .zip if it's .zip.zip --- + copiedZipFilePath = "${env:WORKSPACE}\\\\${env:TMP_UPLOAD_DIR}\\\\${copiedZipFilename}" // Path where it will be copied in THIS workspace + expectedZipFilenameOnDrive = copiedZipFilename // The name on Google Drive is the same as the original filename - // --- 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}" + // Updated error message to reflect looking for .zip only + error("No *.zip file found in the upstream workspace '${env.UPSTREAM_WORKSPACE}\\\\${env.UPSTREAM_ZIP_PATH_RELATIVE}'. Cannot proceed.") + return // Exit script block safely + } + } catch (e) { + echo "Error finding upstream file: ${e.message}" + error("Failed to find the zip file in the upstream workspace.") + return // Exit script block safely + } + // --- End Find upstream zip file name --- + + echo "Target copy path in this workspace: ${copiedZipFilePath}" + echo "Expected zip filename on Google Drive: ${expectedZipFilenameOnDrive}" + + + // --- Get list of existing zip files on Google Drive --- + def existingZipFiles = [] + try { + echo "Checking for existing zip files on Google Drive: ${GDRIVE_REMOTE}..." + // Use standard Windows PowerShell to execute rclone (now in PATH) + // Ensure config path and remote path are quoted, and use backslashes for Windows paths + def rcloneListCommand = """ + rclone --config "${env:WORKSPACE}\\\\${RCLONE_CONFIG}" lsjson "${GDRIVE_REMOTE}" + """ + def rcloneListOutput = powershell(script: rcloneListCommand, returnStdout: true).trim() ?: '[]' + + if (!rcloneListOutput.startsWith('[') || !rcloneListOutput.endsWith(']')) { + echo "Warning: rclone lsjson did not return a valid JSON array for existing files check. Output: ${rcloneListOutput}" + // Continue, but assume no existing files to be safe + existingZipFiles = [] + } else { + def allFilesJson = readJSON text: rcloneListOutput + // Filter for zip files and ensure Name exists + // Removed workaround application here + existingZipFiles = allFilesJson.findAll { it.Name?.endsWith(".zip") }.collect { it.Name } + // DEBUG: Print the exact list of existing zip files found (without workaround) + echo "DEBUG: Exact list of existing zip files on Google Drive: ${existingZipFiles}" + } + } catch (e) { + echo "An error occurred while checking existing files on Google Drive: ${e}" + // Continue, but assume no existing files to be safe + existingZipFiles = [] + } + // --- End getting existing files list --- + + // DEBUG: Print the exact expected zip filename being checked + echo "DEBUG: Checking for existence of expected zip file: ${expectedZipFilenameOnDrive}" + + // --- Manual Check if the zip file already exists on Google Drive --- + def fileExistsOnDrive = false + for (existingFile in existingZipFiles) { + // Compare the original filename to the list from Google Drive (without workaround) + if (existingFile == expectedZipFilenameOnDrive) { + fileExistsOnDrive = true + break // Found a match, no need to check further + } + } + // --- End Manual Check --- + + if (!fileExistsOnDrive) { // Use the result of the manual check + // If we reach here, the zip file does NOT exist on Google Drive, so proceed with copying and uploading + + echo "Zip file ${expectedZipFilenameOnDrive} does not exist on Google Drive. Proceeding with copying and uploading." + + try { + // --- Copy the zip file from the upstream workspace --- + // Use the original upstreamZipFullPath for the source path + echo "Copying zip file from '${upstreamZipFullPath}' to '${copiedZipFilePath}'..." + // DEBUG: Show source and destination paths for Copy-Item + echo "DEBUG: Copy-Item Source: '${upstreamZipFullPath}'" + echo "DEBUG: Copy-Item Destination: '${copiedZipFilePath}'" + // Use standard Windows PowerShell Copy-Item + // Ensure paths are quoted for safety and use backslashes + powershell "Copy-Item -Path \"${upstreamZipFullPath}\" -Destination \"${copiedZipFilePath}\" -Force" + echo "Successfully copied zip file." + + // --- Upload the copied ZIP archive to Google Drive --- + // Use the original filename for the upload source path + echo "Starting upload of '${copiedZipFilename}' to ${GDRIVE_REMOTE}..." + // DEBUG: Show source path for rclone copy + echo "DEBUG: rclone copy Source: '${copiedZipFilePath}'" + // Use standard Windows PowerShell to execute rclone (now in PATH) + powershell """ + rclone --config "${env:WORKSPACE}\\\\${RCLONE_CONFIG}" copy \"${copiedZipFilePath}\" \"${GDRIVE_REMOTE}\" + """ + echo "Finished uploading ${copiedZipFilename}." + + } catch (e) { + echo "ERROR processing build (copy/upload): ${e}" + // Consider adding a flag here to mark that at least one build failed processing + // This could be checked in a later post block to decide if the overall build should be marked as unstable + error("Failed to copy or upload build: ${e.message}") // Fail the stage on error + } finally { + // Clean up the copied zip file after upload attempt + // Use standard Windows PowerShell Remove-Item + echo "Cleaning up copied zip file: ${copiedZipFilePath}" + powershell "Remove-Item -Force \"${copiedZipFilePath}\" -ErrorAction SilentlyContinue" } } else { - echo "Warning: No executable found to extract version for archive. Using default: ${version}" + // If the file DOES exist on Google Drive, print the skipping message + echo "Skipping upload: ${expectedZipFilenameOnDrive} already exists on Google Drive." + // No file was copied in this case, so no cleanup needed in finally } + } // end script + } // end steps + } // end stage - // --- 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 + stage('Retention on Google Drive') { + steps { + script { // Wrap script logic in a script block + echo "Starting Google Drive retention process (using PowerShell)..." + // Ensure rclone is installed and in PATH on the Windows agent, + // and the Jenkins agent user has read access to '${env:WORKSPACE}\\\\${RCLONE_CONFIG}'. - 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 + // PowerShell script block for retention logic + powershell """ + \$rcloneRemote = "${env:GDRIVE_REMOTE}" + \$rcloneConfig = "${env:WORKSPACE}\\\\${env:RCLONE_CONFIG}" + \$filesToKeep = ${env.FILES_TO_KEEP} - echo "Creating zip archive: ${zipFilename} using 7-Zip." - echo "Files to include (full paths): ${filesListString}" + # Get list of files from Google Drive as JSON + \$rcloneListOutput = rclone --config "\$rcloneConfig" lsjson "\$rcloneRemote" | Out-String - // Construct the full 7z command string in Groovy - def sevenZipCommand = "7z a -tzip \"${zipFilename}\" ${filesListString}" + # Parse JSON output + # ConvertFrom-Json will throw an error if the input is not valid JSON, + # which will cause the PowerShell step and the stage to fail. + \$allFilesJson = \$rcloneListOutput | ConvertFrom-Json - // 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. - """ + # Filter for zip files + \$zipFiles = \$allFilesJson | Where-Object { \$_.Name -ne \$null -and \$_.Name.EndsWith(".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." + Write-Host "Found \$(\$zipFiles.Count) total ZIP files on Google Drive." - } else { - error "No files (.exe or .bin) found in the copied artifacts to archive. Cannot create zip." - } - } - } + # --- Sorting of ZIP Files by Filename Timestamp (in PowerShell) --- + Write-Host "Sorting ZIP files on Google Drive by filename timestamp (YYYYMMDD-HHMMSS)..." + + # Regex to extract the timestamp from the filename + \$timestampRegex = '.*-(\\d{8}-\\d{6})\\.zip' + + # Sort the files by extracting the timestamp and converting to DateTime for accurate sorting + # Sort-Object -Descending ensures newest are first + \$sortedZipFiles = \$zipFiles | Sort-Object -Descending { + \$name = \$_.Name + \$match = [regex]::Match(\$name, \$timestampRegex) + if (\$match.Success -and \$match.Groups.Count -gt 1) { + \$timestampStr = \$match.Groups[1].Value + # Attempt to parse the timestamp string into a DateTime object + try { + [DateTime]::ParseExact(\$timestampStr, "yyyyMMdd-HHmmss", \$null) + } catch { + Write-Host "Warning: Could not parse timestamp from filename '\$name': \$(\$_.Exception.Message)" + # Handle parsing errors - treat as the oldest possible date (e.g., 1/1/0001) + # This ensures unparseable dates are placed at the end (oldest) + [DateTime]::MinValue + } + } else { + Write-Host "Warning: Filename '\$name' does not match timestamp regex." + # Handle non-matching filenames - treat as the oldest possible date + [DateTime]::MinValue + } + } + # --- End Sorting --- + + # DEBUG: Print the sorted list by filename timestamp with each file on a new line + Write-Host "DEBUG: ZIP files on Google Drive sorted by filename timestamp (newest first):" + \$sortedZipFiles | ForEach-Object { Write-Host \$_.Name } + + + # Keep the latest N files, identify the rest for deletion + if (\$sortedZipFiles.Count -gt \$filesToKeep) { + # Select the files to delete (from index FILES_TO_KEEP to the end) + \$filesToDelete = \$sortedZipFiles | Select-Object -Skip \$filesToKeep + + Write-Host "Applying retention: Keeping \$filesToKeep newest files, deleting \$(\$filesToDelete.Count) older files." + # DEBUG: Print the list of files identified for deletion + Write-Host "DEBUG: Files identified for deletion:" + \$filesToDelete | ForEach-Object { Write-Host \$_.Name } + + + # Loop through files to delete and execute rclone delete + foreach (\$oldZipInfo in \$filesToDelete) { + \$oldZipName = \$oldZipInfo.Name + Write-Host "Deleting old ZIP from Google Drive: \$oldZipName" + # Ensure filenames are quoted for safety, especially if they contain spaces + # Use errorHanding: 'ignore' if you want to continue even if a delete fails + rclone --config "\$rcloneConfig" delete "\$rcloneRemote/\$oldZipName" --drive-use-trash=false + } + } else { + Write-Host "Retention check: Found \$(\$sortedZipFiles.Count) ZIP files, which is not more than \$filesToKeep. No files deleted." + } + """ // End PowerShell script block + } // end script + } // end steps + } // end stage + + } // End of main 'stages' block + + post { + always { + script { // Wrap steps in a script block + echo "Executing post-build cleanup..." + // Use standard Windows PowerShell Remove-Item for cleanup + // Quote TMP_UPLOAD_DIR path for safety and use backslashes for Windows paths + powershell """ + echo 'Cleaning up temporary upload directory: ${env:WORKSPACE}\\\\${env:TMP_UPLOAD_DIR}' + Remove-Item -Recurse -Force "${env:WORKSPACE}\\\\${env:TMP_UPLOAD_DIR}" -ErrorAction SilentlyContinue + """ + // Removed cleanup for copied artifacts directory as files are cleaned up individually now. + } // end script } - - 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 - } - } + success { + script { // Wrap steps in a script block + echo "Pipeline finished successfully." + // Add any success-specific notifications or actions here + } // end script } - } - // No post section needed for this job, post actions will be handled by the triggered job -} -//test1111 \ No newline at end of file + failure { + script { // Wrap steps in a script block + echo "Pipeline failed. Check logs for details." + // Add any failure-specific notifications or actions here + } // end script + } + } // End of 'post' block + +} // End of 'pipeline' block diff --git a/build/jenkins/zip b/build/jenkins/zip index 5a673f3..2a6bd8c 100644 --- a/build/jenkins/zip +++ b/build/jenkins/zip @@ -126,7 +126,7 @@ pipeline { rem Build the 7z command string correctly rem Start with quoted executable path, command, type, and quoted zip filename - set "SEVEN_ZIP_COMMAND=""%SEVEN_ZIP_EXE%" a -tzip "%ZIP_FILENAME%"" + set "SEVEN_ZIP_COMMAND="%SEVEN_ZIP_EXE%" a -tzip "%ZIP_FILENAME%"" rem Append the list of found files (which are already quoted and space-separated) set "SEVEN_ZIP_COMMAND=%SEVEN_ZIP_COMMAND%%FOUND_FILES%" From c999acd12074310a0c5a4f796ec2f3e6f5aaa684 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 13:27:45 +0300 Subject: [PATCH 04/85] gdrive update zip update --- build/jenkins/zip | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/build/jenkins/zip b/build/jenkins/zip index 2a6bd8c..78a7676 100644 --- a/build/jenkins/zip +++ b/build/jenkins/zip @@ -48,7 +48,7 @@ pipeline { // Define the expected artifact patterns relative to the current directory (MAIN_BUILD_ARTIFACTS_DIR) def exePattern = 'AzaionSuite*.exe' def binPattern = 'AzaionSuite*.bin' - // Define defaultVersion here, as it's used within the bat script + // Define defaultVersion here, as it's used within the bat script if no exe is found def defaultVersion = '1.0.0' @@ -85,31 +85,22 @@ pipeline { echo Found !file_count! file(s) to archive. - rem --- Version Extraction (only from .exe if present) --- - set "VERSION=%DEFAULT_VERSION%" + rem --- Determine Base Filename for Zip --- + set "ZIP_BASE_FILENAME=" if defined EXE_FILE ( - echo Attempting to extract version from "%EXE_FILE%"... - rem Extract filename from full path - for %%I in ("%EXE_FILE%") do set "EXE_FILENAME=%%~nxI" - rem Extract part after AzaionSuite and before .exe - rem Assumes format AzaionSuite.exe - set "TEMP_VERSION=!EXE_FILENAME:AzaionSuite=!" - set "VERSION=!TEMP_VERSION:.exe=!" - rem Basic check if extraction was successful - if "!VERSION!" == "!TEMP_VERSION!" ( - echo Warning: Could not extract version from "%EXE_FILENAME%". Using default: %VERSION% - set "VERSION=%DEFAULT_VERSION%" - ) else ( - echo Found version for archive: %VERSION% - ) + echo Using executable filename as base for archive name: "%EXE_FILE%"... + rem Extract filename without extension from full path + for %%I in ("%EXE_FILE%") do set "ZIP_BASE_FILENAME=%%~nI" + echo Extracted base filename: !ZIP_BASE_FILENAME! ) else ( - echo Warning: No executable found to extract version for archive. Using default: %VERSION% + echo Warning: No executable found. Using default base filename: AzaionSuite.!DEFAULT_VERSION! + set "ZIP_BASE_FILENAME=AzaionSuite.!DEFAULT_VERSION!" ) rem --- Zipping Logic --- - rem Get current date and time inMMDD-HHmmss format using wmic + rem Get current date and time in YYYYMMDD-HHmmss format using wmic rem wmic output format is LocalDateTime=YYYYMMDDHHMMSS.milliseconds+UTCoffset for /f "tokens=2 delims==" %%a in ('wmic os get localdatetime /value') do set "dt=%%a" set "YYYY=%dt:~0,4%" @@ -120,7 +111,8 @@ pipeline { set "SS=%dt:~12,2%" set "timestamp=%YYYY%%MM%%DD%-%HH%%mm%%SS%" - set "ZIP_FILENAME=AzaionSuite.%VERSION%-%timestamp%.zip" + rem Construct the final zip filename using the base filename and timestamp + set "ZIP_FILENAME=!ZIP_BASE_FILENAME!.%timestamp%.zip" echo Creating zip archive: %ZIP_FILENAME% using 7-Zip. From 2d9381351975bd9854aaa89dd5cb486ada940393 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 13:30:11 +0300 Subject: [PATCH 05/85] zip update --- build/jenkins/zip | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/build/jenkins/zip b/build/jenkins/zip index 78a7676..d4180f0 100644 --- a/build/jenkins/zip +++ b/build/jenkins/zip @@ -68,12 +68,23 @@ pipeline { set "EXE_FILE=" rem Find .exe and .bin files and build a list of quoted paths for /R . %%F in (%EXE_PATTERN% %BIN_PATTERN%) do ( + rem DEBUG: Show file found + echo DEBUG: Found file: "%%F" rem Add the quoted full path to FOUND_FILES set "FOUND_FILES=!FOUND_FILES! "%%F"" rem Check if it's an exe for version extraction and store the first one found + rem Using findstr to check if the full path ends with .exe (case-insensitive) echo "%%F" | findstr /I /E "\\\\.exe" >nul && if not defined EXE_FILE set "EXE_FILE=%%F" ) + rem DEBUG: Show EXE_FILE after loop + if defined EXE_FILE ( + echo DEBUG: EXE_FILE set to: "%EXE_FILE%" + ) else ( + echo DEBUG: EXE_FILE remains undefined. + ) + + if not defined FOUND_FILES ( echo No files matching patterns %EXE_PATTERN% or %BIN_PATTERN% found in %CD%. exit /b 1 @@ -97,10 +108,13 @@ pipeline { set "ZIP_BASE_FILENAME=AzaionSuite.!DEFAULT_VERSION!" ) + rem DEBUG: Show ZIP_BASE_FILENAME before constructing zip name + echo DEBUG: ZIP_BASE_FILENAME is: !ZIP_BASE_FILENAME! + rem --- Zipping Logic --- - rem Get current date and time in YYYYMMDD-HHmmss format using wmic + rem Get current date and time inYYYYMMDD-HHmmss format using wmic rem wmic output format is LocalDateTime=YYYYMMDDHHMMSS.milliseconds+UTCoffset for /f "tokens=2 delims==" %%a in ('wmic os get localdatetime /value') do set "dt=%%a" set "YYYY=%dt:~0,4%" From 348eca50806303cae01d7a3c1094931eb3fd7101 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 13:31:50 +0300 Subject: [PATCH 06/85] zip update --- build/jenkins/zip | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/build/jenkins/zip b/build/jenkins/zip index d4180f0..7cfb170 100644 --- a/build/jenkins/zip +++ b/build/jenkins/zip @@ -72,9 +72,10 @@ pipeline { echo DEBUG: Found file: "%%F" rem Add the quoted full path to FOUND_FILES set "FOUND_FILES=!FOUND_FILES! "%%F"" - rem Check if it's an exe for version extraction and store the first one found + rem Check if it's an exe and store the first one found rem Using findstr to check if the full path ends with .exe (case-insensitive) - echo "%%F" | findstr /I /E "\\\\.exe" >nul && if not defined EXE_FILE set "EXE_FILE=%%F" + rem Corrected findstr pattern + echo "%%F" | findstr /I /E ".exe" >nul && if not defined EXE_FILE set "EXE_FILE=%%F" ) rem DEBUG: Show EXE_FILE after loop From 926345efafa4da6f0fa422e5a9f3d1c0cc2c4a4c Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 13:37:18 +0300 Subject: [PATCH 07/85] zip update --- build/jenkins/zip | 173 +++++++++++++++++++++------------------------- 1 file changed, 79 insertions(+), 94 deletions(-) diff --git a/build/jenkins/zip b/build/jenkins/zip index 7cfb170..9886a48 100644 --- a/build/jenkins/zip +++ b/build/jenkins/zip @@ -1,6 +1,6 @@ // This pipeline job is triggered by the main AzaionSuite build pipeline. // It operates directly within the main build job's artifact directory, -// zips the artifacts using Batch and 7-Zip, and then triggers the Google Drive upload pipeline. +// zips the artifacts using PowerShell and 7-Zip, and then triggers the Google Drive upload pipeline. pipeline { // Agent should be your Windows VM agent // This job MUST run on the SAME agent as the main build job @@ -37,10 +37,10 @@ pipeline { // Removed the 'Copy Build Artifacts' stage. // This pipeline will now operate directly in the MAIN_BUILD_ARTIFACTS_DIR. - stage('Archive Build Artifacts (Batch/7-Zip)') { + stage('Archive Build Artifacts (PowerShell/7-Zip)') { steps { - script { // Need script block for dir and bat step - echo "Starting 'Archive Build Artifacts (Batch/7-Zip)' stage." + script { // Need script block for dir and powershell step + echo "Starting 'Archive Build Artifacts (PowerShell/7-Zip)' stage." // Change directory to the main build job's artifacts folder dir("${env.MAIN_BUILD_ARTIFACTS_DIR}") { echo "Operating in directory: ${pwd()}" @@ -48,124 +48,109 @@ pipeline { // Define the expected artifact patterns relative to the current directory (MAIN_BUILD_ARTIFACTS_DIR) def exePattern = 'AzaionSuite*.exe' def binPattern = 'AzaionSuite*.bin' - // Define defaultVersion here, as it's used within the bat script if no exe is found + // Define defaultVersion here, used if version extraction fails def defaultVersion = '1.0.0' + // Use a powershell step to perform file finding, version extraction, timestamp generation, and zipping + powershell """ + \$ErrorActionPreference = "Stop" # Stop the script on any error - // Use a bat step to perform file finding, version extraction, timestamp generation, and zipping - bat """ - @echo off - setlocal enabledelayedexpansion + \$sevenZipExe = "\$env:SEVEN_ZIP_PATH\\7z.exe" + \$defaultVersion = "${defaultVersion}" + \$exePattern = "${exePattern}" + \$binPattern = "${binPattern}" - set "SEVEN_ZIP_EXE=%SEVEN_ZIP_PATH%\\7z.exe" - set "DEFAULT_VERSION=${defaultVersion}" - set "EXE_PATTERN=${exePattern}" - set "BIN_PATTERN=${binPattern}" + Write-Host "Searching for files matching \$exePattern and \$binPattern in the current directory for zipping..." - echo Searching for files matching %EXE_PATTERN% and %BIN_PATTERN% in the current directory for zipping... + # Find all files matching the patterns + \$foundFiles = Get-ChildItem -Recurse -Path . -Include \$exePattern, \$binPattern | Select-Object -ExpandProperty FullName - set "FOUND_FILES=" - set "EXE_FILE=" - rem Find .exe and .bin files and build a list of quoted paths - for /R . %%F in (%EXE_PATTERN% %BIN_PATTERN%) do ( - rem DEBUG: Show file found - echo DEBUG: Found file: "%%F" - rem Add the quoted full path to FOUND_FILES - set "FOUND_FILES=!FOUND_FILES! "%%F"" - rem Check if it's an exe and store the first one found - rem Using findstr to check if the full path ends with .exe (case-insensitive) - rem Corrected findstr pattern - echo "%%F" | findstr /I /E ".exe" >nul && if not defined EXE_FILE set "EXE_FILE=%%F" - ) + if (\$foundFiles.Count -eq 0) { + Write-Error "No files matching patterns \$exePattern or \$binPattern found in \$(Get-Location)." + exit 1 + } - rem DEBUG: Show EXE_FILE after loop - if defined EXE_FILE ( - echo DEBUG: EXE_FILE set to: "%EXE_FILE%" - ) else ( - echo DEBUG: EXE_FILE remains undefined. - ) + Write-Host "Found \$(\$foundFiles.Count) file(s) to archive." + # --- Version Extraction (from .exe if present) --- + \$version = \$defaultVersion + \$exeFile = Get-ChildItem -Recurse -Path . -Filter \$exePattern | Select-Object -First 1 - if not defined FOUND_FILES ( - echo No files matching patterns %EXE_PATTERN% or %BIN_PATTERN% found in %CD%. - exit /b 1 - ) + if (\$exeFile) { + Write-Host "Attempting to extract version from '\$($exeFile.FullName)'..." + try { + # Get file version info + \$versionInfo = Get-ItemProperty -Path \$exeFile.FullName -Name VersionInfo - rem Count files (basic count based on spaces, might be inaccurate with complex paths) - set "file_count=0" - for %%F in (%FOUND_FILES%) do set /a file_count+=1 - echo Found !file_count! file(s) to archive. + # Prefer ProductVersion, fallback to FileVersion + if (\$versionInfo.ProductVersion) { + \$version = \$versionInfo.ProductVersion + Write-Host "Extracted ProductVersion: \$version" + } elseif (\$versionInfo.FileVersion) { + \$version = \$versionInfo.FileVersion + Write-Host "Extracted FileVersion: \$version" + } else { + Write-Warning "Could not extract ProductVersion or FileVersion from '\$($exeFile.Name)'. Using default: \$version" + } + } catch { + Write-Warning "Error extracting version from '\$($exeFile.Name)': \$_\nUsing default: \$version" + } + } else { + Write-Warning "No executable found matching \$exePattern to extract version. Using default: \$version" + } + # --- Zipping Logic --- - rem --- Determine Base Filename for Zip --- - set "ZIP_BASE_FILENAME=" - if defined EXE_FILE ( - echo Using executable filename as base for archive name: "%EXE_FILE%"... - rem Extract filename without extension from full path - for %%I in ("%EXE_FILE%") do set "ZIP_BASE_FILENAME=%%~nI" - echo Extracted base filename: !ZIP_BASE_FILENAME! - ) else ( - echo Warning: No executable found. Using default base filename: AzaionSuite.!DEFAULT_VERSION! - set "ZIP_BASE_FILENAME=AzaionSuite.!DEFAULT_VERSION!" - ) + # Get current date and time in YYYYMMDD-HHmmss format + \$timestamp = (Get-Date -Format "yyyyMMdd-HHmmss") - rem DEBUG: Show ZIP_BASE_FILENAME before constructing zip name - echo DEBUG: ZIP_BASE_FILENAME is: !ZIP_BASE_FILENAME! + # Construct the zip filename using extracted version and timestamp + \$zipFilename = "AzaionSuite.\$version-\$timestamp.zip" + Write-Host "Creating zip archive: \$zipFilename using 7-Zip." - rem --- Zipping Logic --- + # Build the 7z command arguments + # Start with command, type, and quoted zip filename + \$sevenZipArgs = @("a", "-tzip", "\$zipFilename") - rem Get current date and time inYYYYMMDD-HHmmss format using wmic - rem wmic output format is LocalDateTime=YYYYMMDDHHMMSS.milliseconds+UTCoffset - for /f "tokens=2 delims==" %%a in ('wmic os get localdatetime /value') do set "dt=%%a" - set "YYYY=%dt:~0,4%" - set "MM=%dt:~4,2%" - set "DD=%dt:~6,2%" - set "HH=%dt:~8,2%" - set "mm=%dt:~10,2%" - set "SS=%dt:~12,2%" - set "timestamp=%YYYY%%MM%%DD%-%HH%%mm%%SS%" + # Add the list of found files (which are already quoted and space-separated in the Batch script, + # but Get-ChildItem returns objects, so we need to handle quoting for the command) + # Joining the array elements with spaces, ensuring each path is quoted + \$foundFilesQuoted = \$foundFiles | ForEach-Object { "\`"\$_\`"" } + \$sevenZipArgs += \$foundFilesQuoted - rem Construct the final zip filename using the base filename and timestamp - set "ZIP_FILENAME=!ZIP_BASE_FILENAME!.%timestamp%.zip" + # Construct the full command string for logging + \$commandString = "\$sevenZipExe \$(\$sevenZipArgs -join ' ')" + Write-Host "Executing command: \$commandString" - echo Creating zip archive: %ZIP_FILENAME% using 7-Zip. + # Execute the 7z command + # Using Start-Process with -Wait to ensure the script waits for 7z to finish + # and capturing the exit code + \$process = Start-Process -FilePath \$sevenZipExe -ArgumentList \$sevenZipArgs -Wait -PassThru + \$exitCode = \$process.ExitCode - rem Build the 7z command string correctly - rem Start with quoted executable path, command, type, and quoted zip filename - set "SEVEN_ZIP_COMMAND="%SEVEN_ZIP_EXE%" a -tzip "%ZIP_FILENAME%"" + # Check the last exit code from the external command + if (\$exitCode -ne 0) { + Write-Error "Error creating zip archive with 7-Zip. 7z exit code: \$exitCode" + exit \$exitCode + } - rem Append the list of found files (which are already quoted and space-separated) - set "SEVEN_ZIP_COMMAND=%SEVEN_ZIP_COMMAND%%FOUND_FILES%" + Write-Host "Zip archive created successfully by 7-Zip: \$zipFilename" + # Output the zip filename and set it as an environment variable for Jenkins + # This uses the Jenkins 'set context' feature + Write-Host "::SET-ZIP-FILENAME::\$zipFilename" + Write-Host "::SET-ENV::CREATED_ZIP_FILENAME=\$zipFilename" - echo Executing command: %SEVEN_ZIP_COMMAND% - - rem Execute the constructed command string - %SEVEN_ZIP_COMMAND% - - rem Check the last exit code from the external command - 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: %ZIP_FILENAME% - - rem Output the zip filename and set it as an environment variable for Jenkins - rem This uses the Jenkins 'set context' feature - echo ::SET-ZIP-FILENAME::%ZIP_FILENAME% - echo ::SET-ENV::CREATED_ZIP_FILENAME=%ZIP_FILENAME% - - exit /b 0 - """ // End bat script + exit 0 + """ // End powershell script } // End dir block } } } stage('Archive Created Zip') { steps { - script { // Need script block for dir and accessing environment variables set by Batch + script { // Need script block for dir and accessing environment variables set by PowerShell echo "Starting 'Archive Created Zip' stage." // Change directory back to the main build job's artifacts folder to archive the zip dir("${env.MAIN_BUILD_ARTIFACTS_DIR}") { From 1277ebffc6b2fb5cb46d61c60d8f0ea2a34cf536 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 13:38:15 +0300 Subject: [PATCH 08/85] zip update --- build/jenkins/zip | 97 ++++++++++++++++++++++++----------------------- 1 file changed, 49 insertions(+), 48 deletions(-) diff --git a/build/jenkins/zip b/build/jenkins/zip index 9886a48..5aea3ff 100644 --- a/build/jenkins/zip +++ b/build/jenkins/zip @@ -46,104 +46,105 @@ pipeline { echo "Operating in directory: ${pwd()}" // Define the expected artifact patterns relative to the current directory (MAIN_BUILD_ARTIFACTS_DIR) - def exePattern = 'AzaionSuite*.exe' - def binPattern = 'AzaionSuite*.bin' + // These are now defined as literals within the PowerShell script string + // def exePattern = 'AzaionSuite*.exe' + // def binPattern = 'AzaionSuite*.bin' // Define defaultVersion here, used if version extraction fails - def defaultVersion = '1.0.0' + // def defaultVersion = '1.0.0' + // Use a powershell step to perform file finding, version extraction, timestamp generation, and zipping - powershell """ - \$ErrorActionPreference = "Stop" # Stop the script on any error + powershell ''' + $ErrorActionPreference = "Stop" # Stop the script on any error - \$sevenZipExe = "\$env:SEVEN_ZIP_PATH\\7z.exe" - \$defaultVersion = "${defaultVersion}" - \$exePattern = "${exePattern}" - \$binPattern = "${binPattern}" + $sevenZipExe = "$env:SEVEN_ZIP_PATH\\7z.exe" + $defaultVersion = "1.0.0" # Default version if extraction fails + $exePattern = "AzaionSuite*.exe" + $binPattern = "AzaionSuite*.bin" - Write-Host "Searching for files matching \$exePattern and \$binPattern in the current directory for zipping..." + Write-Host "Searching for files matching $exePattern and $binPattern in the current directory for zipping..." # Find all files matching the patterns - \$foundFiles = Get-ChildItem -Recurse -Path . -Include \$exePattern, \$binPattern | Select-Object -ExpandProperty FullName + $foundFiles = Get-ChildItem -Recurse -Path . -Include $exePattern, $binPattern | Select-Object -ExpandProperty FullName - if (\$foundFiles.Count -eq 0) { - Write-Error "No files matching patterns \$exePattern or \$binPattern found in \$(Get-Location)." + if ($foundFiles.Count -eq 0) { + Write-Error "No files matching patterns $exePattern or $binPattern found in $(Get-Location)." exit 1 } - Write-Host "Found \$(\$foundFiles.Count) file(s) to archive." + Write-Host "Found $($foundFiles.Count) file(s) to archive." # --- Version Extraction (from .exe if present) --- - \$version = \$defaultVersion - \$exeFile = Get-ChildItem -Recurse -Path . -Filter \$exePattern | Select-Object -First 1 + $version = $defaultVersion + $exeFile = Get-ChildItem -Recurse -Path . -Filter $exePattern | Select-Object -First 1 - if (\$exeFile) { - Write-Host "Attempting to extract version from '\$($exeFile.FullName)'..." + if ($exeFile) { + Write-Host "Attempting to extract version from '$($exeFile.FullName)'..." try { # Get file version info - \$versionInfo = Get-ItemProperty -Path \$exeFile.FullName -Name VersionInfo + $versionInfo = Get-ItemProperty -Path $exeFile.FullName -Name VersionInfo # Prefer ProductVersion, fallback to FileVersion - if (\$versionInfo.ProductVersion) { - \$version = \$versionInfo.ProductVersion - Write-Host "Extracted ProductVersion: \$version" - } elseif (\$versionInfo.FileVersion) { - \$version = \$versionInfo.FileVersion - Write-Host "Extracted FileVersion: \$version" + if ($versionInfo.ProductVersion) { + $version = $versionInfo.ProductVersion + Write-Host "Extracted ProductVersion: $version" + } elseif ($versionInfo.FileVersion) { + $version = $versionInfo.FileVersion + Write-Host "Extracted FileVersion: $version" } else { - Write-Warning "Could not extract ProductVersion or FileVersion from '\$($exeFile.Name)'. Using default: \$version" + Write-Warning "Could not extract ProductVersion or FileVersion from '$($exeFile.Name)'. Using default: $version" } } catch { - Write-Warning "Error extracting version from '\$($exeFile.Name)': \$_\nUsing default: \$version" + Write-Warning "Error extracting version from '$($exeFile.Name)': $_`nUsing default: $version" } } else { - Write-Warning "No executable found matching \$exePattern to extract version. Using default: \$version" + Write-Warning "No executable found matching $exePattern to extract version. Using default: $version" } # --- Zipping Logic --- # Get current date and time in YYYYMMDD-HHmmss format - \$timestamp = (Get-Date -Format "yyyyMMdd-HHmmss") + $timestamp = (Get-Date -Format "yyyyMMdd-HHmmss") # Construct the zip filename using extracted version and timestamp - \$zipFilename = "AzaionSuite.\$version-\$timestamp.zip" + $zipFilename = "AzaionSuite.$version-$timestamp.zip" - Write-Host "Creating zip archive: \$zipFilename using 7-Zip." + Write-Host "Creating zip archive: $zipFilename using 7-Zip." # Build the 7z command arguments # Start with command, type, and quoted zip filename - \$sevenZipArgs = @("a", "-tzip", "\$zipFilename") + $sevenZipArgs = @("a", "-tzip", "$zipFilename") - # Add the list of found files (which are already quoted and space-separated in the Batch script, - # but Get-ChildItem returns objects, so we need to handle quoting for the command) - # Joining the array elements with spaces, ensuring each path is quoted - \$foundFilesQuoted = \$foundFiles | ForEach-Object { "\`"\$_\`"" } - \$sevenZipArgs += \$foundFilesQuoted + # Add the list of found files, ensuring each path is quoted + # Using backticks to escape quotes within the PowerShell string + $foundFilesQuoted = $foundFiles | ForEach-Object { "`"$_`"" } + $sevenZipArgs += $foundFilesQuoted # Construct the full command string for logging - \$commandString = "\$sevenZipExe \$(\$sevenZipArgs -join ' ')" - Write-Host "Executing command: \$commandString" + $commandString = "$sevenZipExe $($sevenZipArgs -join ' ')" + Write-Host "Executing command: $commandString" # Execute the 7z command # Using Start-Process with -Wait to ensure the script waits for 7z to finish # and capturing the exit code - \$process = Start-Process -FilePath \$sevenZipExe -ArgumentList \$sevenZipArgs -Wait -PassThru - \$exitCode = \$process.ExitCode + $process = Start-Process -FilePath $sevenZipExe -ArgumentList $sevenZipArgs -Wait -PassThru + $exitCode = $process.ExitCode # Check the last exit code from the external command - if (\$exitCode -ne 0) { - Write-Error "Error creating zip archive with 7-Zip. 7z exit code: \$exitCode" - exit \$exitCode + if ($exitCode -ne 0) { + Write-Error "Error creating zip archive with 7-Zip. 7z exit code: $exitCode" + exit $exitCode } - Write-Host "Zip archive created successfully by 7-Zip: \$zipFilename" + Write-Host "Zip archive created successfully by 7-Zip: $zipFilename" # Output the zip filename and set it as an environment variable for Jenkins # This uses the Jenkins 'set context' feature - Write-Host "::SET-ZIP-FILENAME::\$zipFilename" - Write-Host "::SET-ENV::CREATED_ZIP_FILENAME=\$zipFilename" + Write-Host "::SET-ZIP-FILENAME::$zipFilename" + Write-Host "::SET-ENV::CREATED_ZIP_FILENAME=$zipFilename" exit 0 - """ // End powershell script + ''' // End powershell script } // End dir block } } From 30d97c62446d6c36cb41288e3ade9eaa713c2139 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 13:40:28 +0300 Subject: [PATCH 09/85] zip update --- build/jenkins/zip | 36 +++++++++++------------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/build/jenkins/zip b/build/jenkins/zip index 5aea3ff..1f8f2e8 100644 --- a/build/jenkins/zip +++ b/build/jenkins/zip @@ -53,12 +53,12 @@ pipeline { // def defaultVersion = '1.0.0' - // Use a powershell step to perform file finding, version extraction, timestamp generation, and zipping + // Use a powershell step to perform file finding, filename extraction, timestamp generation, and zipping powershell ''' $ErrorActionPreference = "Stop" # Stop the script on any error $sevenZipExe = "$env:SEVEN_ZIP_PATH\\7z.exe" - $defaultVersion = "1.0.0" # Default version if extraction fails + $defaultVersion = "1.0.0" # Default version if no exe is found $exePattern = "AzaionSuite*.exe" $binPattern = "AzaionSuite*.bin" @@ -74,31 +74,17 @@ pipeline { Write-Host "Found $($foundFiles.Count) file(s) to archive." - # --- Version Extraction (from .exe if present) --- - $version = $defaultVersion + # --- Determine Base Filename for Zip (from .exe if present) --- + $zipBaseFilename = "AzaionSuite.$defaultVersion" # Default base filename $exeFile = Get-ChildItem -Recurse -Path . -Filter $exePattern | Select-Object -First 1 if ($exeFile) { - Write-Host "Attempting to extract version from '$($exeFile.FullName)'..." - try { - # Get file version info - $versionInfo = Get-ItemProperty -Path $exeFile.FullName -Name VersionInfo - - # Prefer ProductVersion, fallback to FileVersion - if ($versionInfo.ProductVersion) { - $version = $versionInfo.ProductVersion - Write-Host "Extracted ProductVersion: $version" - } elseif ($versionInfo.FileVersion) { - $version = $versionInfo.FileVersion - Write-Host "Extracted FileVersion: $version" - } else { - Write-Warning "Could not extract ProductVersion or FileVersion from '$($exeFile.Name)'. Using default: $version" - } - } catch { - Write-Warning "Error extracting version from '$($exeFile.Name)': $_`nUsing default: $version" - } + Write-Host "Executable file found: '$($exeFile.FullName)'" + # Extract filename without extension + $zipBaseFilename = $exeFile.BaseName + Write-Host "Using executable base filename for archive name: '$zipBaseFilename'" } else { - Write-Warning "No executable found matching $exePattern to extract version. Using default: $version" + Write-Warning "No executable found matching $exePattern. Using default base filename: '$zipBaseFilename'" } # --- Zipping Logic --- @@ -106,8 +92,8 @@ pipeline { # Get current date and time in YYYYMMDD-HHmmss format $timestamp = (Get-Date -Format "yyyyMMdd-HHmmss") - # Construct the zip filename using extracted version and timestamp - $zipFilename = "AzaionSuite.$version-$timestamp.zip" + # Construct the zip filename using the base filename and timestamp + $zipFilename = "$zipBaseFilename-$timestamp.zip" Write-Host "Creating zip archive: $zipFilename using 7-Zip." From f100ed638d91bc2cc0d1042f22c9681bba0e8831 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 13:48:21 +0300 Subject: [PATCH 10/85] zip update --- build/jenkins/GDriveUpload | 263 +++++++++++++++++-------------------- build/jenkins/zip | 27 ++-- 2 files changed, 135 insertions(+), 155 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index 0c1c158..8ad4a11 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -1,47 +1,46 @@ -// Jenkins Pipeline script to directly copy the zip file from an upstream job's workspace, -// derive build identifier from the zip filename, and upload to Google Drive with retention. +// Jenkins Pipeline script to find the latest zip file directly in the artifacts directory +// and upload it to Google Drive with retention. // Retention is based on the timestamp embedded in the filename and performed entirely in PowerShell. -// Designed to run on a Windows agent. +// Designed to run on a Windows agent, specifically on the machine where the main build creates artifacts. // Assumes rclone is installed and its directory is added to the system's PATH on the Windows agent. pipeline { - // Agent should be your Windows VM agent + // Agent should be the SAME Windows VM agent where the main build job runs + // and creates the artifacts in the MAIN_BUILD_ARTIFACTS_DIR. agent { label 'Win10-BuildMachine' } // Replace with your Windows agent label if different - // Removed parameters block as we don't need upstream job name/build number parameters anymore - environment { + // Google Drive settings GDRIVE_REMOTE = 'AzaionGoogleDrive:AzaionSuiteBuilds' // Your rclone remote name and path // Use a relative path within the workspace for the temporary directory on Windows - // This temporary directory will hold the copied zip file before upload + // This temporary directory is still useful for rclone's internal operations and cleanup TMP_UPLOAD_DIR = 'temp_upload' // Path to rclone.conf on the Windows agent. // Adjust this path if your rclone.conf is located elsewhere on the Windows VM. // Using a relative path from the workspace root is often best practice. RCLONE_CONFIG = 'rclone.conf' // Assuming rclone.conf is in the workspace root - // Define the FULL path to the upstream job's workspace on the SAME agent - // This assumes both jobs run on the same agent and you know the workspace path structure - UPSTREAM_WORKSPACE = 'C:\\Jenkins\\workspace\\AzaionSuite' // **Adjust this path if necessary** - - // Define the path to the zip file relative to the upstream workspace - // Based on your description: C:\Jenkins\workspace\AzaionSuite\suite\AzaionSuite.1.4.5-YYYYMMDD-HHMMSS.zip - // We'll use a wildcard to find the specific timestamped zip - UPSTREAM_ZIP_PATH_RELATIVE = 'suite\\*.zip' // **Reverted filter to only look for .zip** - // Number of latest files to keep on Google Drive FILES_TO_KEEP = 3 + + // Define the FULL path to the directory containing the zip files. + // This job will operate directly within this directory. + // ** IMPORTANT: Replace 'C:/Jenkins/workspace/AzaionSuite/suite' with the actual path ** + TARGET_ARTIFACTS_DIR = 'C:/Jenkins/workspace/AzaionSuite/suite' // <<== UPDATE THIS + + // Define the name of the latest zip file found as an environment variable + // This makes it easier to reference in later stages + LATEST_ZIP_FILENAME = '' // This will be set dynamically in the 'Find Latest Zip and Upload' stage } stages { - stage('Initialize') { + stage('Initialize Workspace') { steps { echo "Initializing workspace on Windows agent..." - // Use standard Windows PowerShell for directory creation and cleanup - // Ensure paths are quoted for safety + // Ensure paths are quoted for safety and use backslashes for Windows paths powershell """ - # Create temporary upload directory + # Create temporary upload directory within THIS job's workspace New-Item -ItemType Directory -Force -Path "${env:WORKSPACE}\\\\${env:TMP_UPLOAD_DIR}" # Clean up previous temporary files in the upload directory @@ -50,142 +49,114 @@ pipeline { } } - // Removed the 'Copy Last Stable Artifact' stage - - stage('Copy and Upload Build') { // Combined stage for copying, finding name, and conditional upload + stage('Find Latest Zip and Upload') { // Renamed stage steps { script { // Wrap steps in a script block - echo "Starting Copy and Upload Build stage..." + echo "Starting 'Find Latest Zip and Upload' stage." - def upstreamZipFullPath = null - def copiedZipFilename = null - def copiedZipFilePath = null - def expectedZipFilenameOnDrive = null + // Change directory to the target artifacts folder where the zip files are located + dir("${env.TARGET_ARTIFACTS_DIR}") { + echo "Operating in directory: ${pwd()}" - // --- Find the full path of the zip file in the upstream workspace --- - try { - echo "Attempting to find the zip file in upstream workspace: ${env.UPSTREAM_WORKSPACE}\\\\${env.UPSTREAM_ZIP_PATH_RELATIVE}" - // Use PowerShell to find the first file matching the pattern (.zip only) - // Use -ErrorAction Stop to ensure the error is caught by Groovy try/catch - // Ensure paths are quoted for safety - upstreamZipFullPath = powershell(script: "Get-ChildItem -Path \"${env:UPSTREAM_WORKSPACE}\\\\${env:UPSTREAM_ZIP_PATH_RELATIVE}\" -ErrorAction Stop | Select-Object -First 1 -ExpandProperty FullName", returnStdout: true).trim() + // Use PowerShell to find the latest zip file based on filename timestamp + // This logic is similar to the 'Archive Latest Zip' stage from the combined pipeline + def powershellOutput = powershell(script: """ + \$zipPattern = "AzaionSuite*-*-*.zip" # Pattern for zip files + Write-Host "Searching for latest zip file matching '\$zipPattern' in '\$PWD'..." - if (upstreamZipFullPath) { - echo "Found upstream file: ${upstreamZipFullPath}" - // Extract just the filename from the full path - copiedZipFilename = upstreamZipFullPath.substring(upstreamZipFullPath.lastIndexOf('\\') + 1) - echo "Derived filename: ${copiedZipFilename}" - // DEBUG: Show the derived filename explicitly - echo "DEBUG: Derived copiedZipFilename = '${copiedZipFilename}'" + # Find all zip files matching the pattern + # Use -ErrorAction Stop to fail if Get-ChildItem fails + \$zipFiles = Get-ChildItem -Path . -Filter \$zipPattern -ErrorAction Stop - // --- Removed Workaround: Remove trailing .zip if it's .zip.zip --- - copiedZipFilePath = "${env:WORKSPACE}\\\\${env:TMP_UPLOAD_DIR}\\\\${copiedZipFilename}" // Path where it will be copied in THIS workspace - expectedZipFilenameOnDrive = copiedZipFilename // The name on Google Drive is the same as the original filename + if (\$zipFiles.Count -eq 0) { + Write-Host "No zip files matching pattern '\$zipPattern' found in '\$PWD'." + # Exit PowerShell script with a non-zero code to fail the step + exit 1 + } + Write-Host "Found \$(\$zipFiles.Count) zip file(s)." + + # --- Sorting of ZIP Files by Filename Timestamp (in PowerShell) --- + Write-Host "Sorting ZIP files by filename timestamp (YYYYMMDD-HHMMSS)..." + + # Regex to extract the timestamp from the filename + \$timestampRegex = '.*-(\\d{8}-\\d{6})\\.zip' + + # Sort the files by extracting the timestamp and converting to DateTime for accurate sorting + # Sort-Object -Descending ensures newest are first + \$sortedZipFiles = \$zipFiles | Sort-Object -Descending { + \$name = \$_.Name + \$match = [regex]::Match(\$name, \$timestampRegex) + if (\$match.Success -and \$match.Groups.Count -gt 1) { + \$timestampStr = \$match.Groups[1].Value + # Attempt to parse the timestamp string into a DateTime object + try { + [DateTime]::ParseExact(\$timestampStr, "yyyyMMdd-HHmmss", \$null) + } catch { + Write-Host "Warning: Could not parse timestamp from filename '\$name': \$(\$_.Exception.Message)" + # Handle parsing errors - treat as the oldest possible date (e.g., 1/1/0001) + # This ensures unparseable dates are placed at the end (oldest) + [DateTime]::MinValue + } + } else { + Write-Host "Warning: Filename '\$name' does not match timestamp regex." + # Handle non-matching filenames - treat as the oldest possible date + [DateTime]::MinValue + # Exit the script here if you want to fail the stage on unparseable filenames + # exit 1 + } + } + # --- End Sorting --- + + # Get the name of the latest zip file (the first one after sorting descending) + \$latestZipFile = \$sortedZipFiles | Select-Object -First 1 + + Write-Host "Identified latest zip file: '\$latestZipFile.Name'" + + # Output the latest zip filename and set it as an environment variable for Jenkins + # This uses the Jenkins 'set context' feature + Write-Host "::SET-ENV::LATEST_ZIP_FILENAME=\$(\$latestZipFile.Name)" + + exit 0 # Exit PowerShell script successfully + + """ , returnStdout: true + ) // End powershell call + + // Parse the PowerShell output to find the latest zip filename and set the Groovy environment variable + def matcher = powershellOutput =~ /::SET-ENV::LATEST_ZIP_FILENAME=(.+)/ + def latestZipFilename = null + if (matcher.find()) { + latestZipFilename = matcher.group(1).trim() + env.LATEST_ZIP_FILENAME = latestZipFilename // Set the environment variable + echo "Groovy set LATEST_ZIP_FILENAME to: ${env.LATEST_ZIP_FILENAME}" } else { - // Updated error message to reflect looking for .zip only - error("No *.zip file found in the upstream workspace '${env.UPSTREAM_WORKSPACE}\\\\${env.UPSTREAM_ZIP_PATH_RELATIVE}'. Cannot proceed.") - return // Exit script block safely + error "Could not find the latest zip filename in the PowerShell output using marker." } - } catch (e) { - echo "Error finding upstream file: ${e.message}" - error("Failed to find the zip file in the upstream workspace.") - return // Exit script block safely - } - // --- End Find upstream zip file name --- - echo "Target copy path in this workspace: ${copiedZipFilePath}" - echo "Expected zip filename on Google Drive: ${expectedZipFilenameOnDrive}" + // Ensure the latest zip filename environment variable is set before attempting upload + if (env.LATEST_ZIP_FILENAME && env.LATEST_ZIP_FILENAME != '') { + echo "Identified latest zip file for upload: ${env.LATEST_ZIP_FILENAME}" + try { + // --- Upload the latest ZIP archive directly from the current directory --- + echo "Starting upload of '${env.LATEST_ZIP_FILENAME}' directly from '${pwd()}' to ${GDRIVE_REMOTE}..." + // Use standard Windows PowerShell to execute rclone (now in PATH) + // Ensure config path and remote path are quoted, and use backslashes for Windows paths + // The source path for rclone is the filename relative to the current directory (TARGET_ARTIFACTS_DIR) + powershell """ + rclone --config "${env:WORKSPACE}\\\\${env:RCLONE_CONFIG}" copy \"${env:LATEST_ZIP_FILENAME}\" \"${env:GDRIVE_REMOTE}\" + """ + echo "Finished uploading ${env.LATEST_ZIP_FILENAME}." - // --- Get list of existing zip files on Google Drive --- - def existingZipFiles = [] - try { - echo "Checking for existing zip files on Google Drive: ${GDRIVE_REMOTE}..." - // Use standard Windows PowerShell to execute rclone (now in PATH) - // Ensure config path and remote path are quoted, and use backslashes for Windows paths - def rcloneListCommand = """ - rclone --config "${env:WORKSPACE}\\\\${RCLONE_CONFIG}" lsjson "${GDRIVE_REMOTE}" - """ - def rcloneListOutput = powershell(script: rcloneListCommand, returnStdout: true).trim() ?: '[]' - - if (!rcloneListOutput.startsWith('[') || !rcloneListOutput.endsWith(']')) { - echo "Warning: rclone lsjson did not return a valid JSON array for existing files check. Output: ${rcloneListOutput}" - // Continue, but assume no existing files to be safe - existingZipFiles = [] - } else { - def allFilesJson = readJSON text: rcloneListOutput - // Filter for zip files and ensure Name exists - // Removed workaround application here - existingZipFiles = allFilesJson.findAll { it.Name?.endsWith(".zip") }.collect { it.Name } - // DEBUG: Print the exact list of existing zip files found (without workaround) - echo "DEBUG: Exact list of existing zip files on Google Drive: ${existingZipFiles}" - } - } catch (e) { - echo "An error occurred while checking existing files on Google Drive: ${e}" - // Continue, but assume no existing files to be safe - existingZipFiles = [] - } - // --- End getting existing files list --- - - // DEBUG: Print the exact expected zip filename being checked - echo "DEBUG: Checking for existence of expected zip file: ${expectedZipFilenameOnDrive}" - - // --- Manual Check if the zip file already exists on Google Drive --- - def fileExistsOnDrive = false - for (existingFile in existingZipFiles) { - // Compare the original filename to the list from Google Drive (without workaround) - if (existingFile == expectedZipFilenameOnDrive) { - fileExistsOnDrive = true - break // Found a match, no need to check further - } - } - // --- End Manual Check --- - - if (!fileExistsOnDrive) { // Use the result of the manual check - // If we reach here, the zip file does NOT exist on Google Drive, so proceed with copying and uploading - - echo "Zip file ${expectedZipFilenameOnDrive} does not exist on Google Drive. Proceeding with copying and uploading." - - try { - // --- Copy the zip file from the upstream workspace --- - // Use the original upstreamZipFullPath for the source path - echo "Copying zip file from '${upstreamZipFullPath}' to '${copiedZipFilePath}'..." - // DEBUG: Show source and destination paths for Copy-Item - echo "DEBUG: Copy-Item Source: '${upstreamZipFullPath}'" - echo "DEBUG: Copy-Item Destination: '${copiedZipFilePath}'" - // Use standard Windows PowerShell Copy-Item - // Ensure paths are quoted for safety and use backslashes - powershell "Copy-Item -Path \"${upstreamZipFullPath}\" -Destination \"${copiedZipFilePath}\" -Force" - echo "Successfully copied zip file." - - // --- Upload the copied ZIP archive to Google Drive --- - // Use the original filename for the upload source path - echo "Starting upload of '${copiedZipFilename}' to ${GDRIVE_REMOTE}..." - // DEBUG: Show source path for rclone copy - echo "DEBUG: rclone copy Source: '${copiedZipFilePath}'" - // Use standard Windows PowerShell to execute rclone (now in PATH) - powershell """ - rclone --config "${env:WORKSPACE}\\\\${RCLONE_CONFIG}" copy \"${copiedZipFilePath}\" \"${GDRIVE_REMOTE}\" - """ - echo "Finished uploading ${copiedZipFilename}." - - } catch (e) { - echo "ERROR processing build (copy/upload): ${e}" - // Consider adding a flag here to mark that at least one build failed processing - // This could be checked in a later post block to decide if the overall build should be marked as unstable - error("Failed to copy or upload build: ${e.message}") // Fail the stage on error - } finally { - // Clean up the copied zip file after upload attempt - // Use standard Windows PowerShell Remove-Item - echo "Cleaning up copied zip file: ${copiedZipFilePath}" - powershell "Remove-Item -Force \"${copiedZipFilePath}\" -ErrorAction SilentlyContinue" - } - } else { - // If the file DOES exist on Google Drive, print the skipping message - echo "Skipping upload: ${expectedZipFilenameOnDrive} already exists on Google Drive." - // No file was copied in this case, so no cleanup needed in finally - } + } catch (e) { + echo "ERROR uploading build: ${e}" + error("Failed to upload latest zip file: ${e.message}") // Fail the stage on error + } + // No cleanup needed in finally block here as the file is not copied to a temp location first + } else { + error "LATEST_ZIP_FILENAME environment variable was not set or was empty. Cannot upload." + } + } // End dir block } // end script } // end steps } // end stage @@ -195,7 +166,7 @@ pipeline { script { // Wrap script logic in a script block echo "Starting Google Drive retention process (using PowerShell)..." // Ensure rclone is installed and in PATH on the Windows agent, - // and the Jenkins agent user has read access to '${env:WORKSPACE}\\\\${RCLONE_CONFIG}'. + // and the Jenkins agent user has read access to '${env:WORKSPACE}\\\\${env.RCLONE_CONFIG}'. // PowerShell script block for retention logic powershell """ @@ -242,6 +213,8 @@ pipeline { Write-Host "Warning: Filename '\$name' does not match timestamp regex." # Handle non-matching filenames - treat as the oldest possible date [DateTime]::MinValue + # Exit the script here if you want to fail the stage on unparseable filenames + # exit 1 } } # --- End Sorting --- diff --git a/build/jenkins/zip b/build/jenkins/zip index 1f8f2e8..0e47f00 100644 --- a/build/jenkins/zip +++ b/build/jenkins/zip @@ -30,7 +30,7 @@ pipeline { // Define the name of the created zip file as an environment variable // This makes it easier to reference in later stages - CREATED_ZIP_FILENAME = '' // This will be set dynamically + CREATED_ZIP_FILENAME = '' // This will be set dynamically by capturing PowerShell output } stages { @@ -49,12 +49,13 @@ pipeline { // These are now defined as literals within the PowerShell script string // def exePattern = 'AzaionSuite*.exe' // def binPattern = 'AzaionSuite*.bin' - // Define defaultVersion here, used if version extraction fails + // Define defaultVersion here, used if no exe is found // def defaultVersion = '1.0.0' // Use a powershell step to perform file finding, filename extraction, timestamp generation, and zipping - powershell ''' + // Capture the output of the powershell script + def zipFilenameOutput = powershell returnStdout: true, script: ''' $ErrorActionPreference = "Stop" # Stop the script on any error $sevenZipExe = "$env:SEVEN_ZIP_PATH\\7z.exe" @@ -89,7 +90,7 @@ pipeline { # --- Zipping Logic --- - # Get current date and time in YYYYMMDD-HHmmss format + # Get current date and time inYYYYMMDD-HHmmss format $timestamp = (Get-Date -Format "yyyyMMdd-HHmmss") # Construct the zip filename using the base filename and timestamp @@ -124,13 +125,19 @@ pipeline { Write-Host "Zip archive created successfully by 7-Zip: $zipFilename" - # Output the zip filename and set it as an environment variable for Jenkins - # This uses the Jenkins 'set context' feature - Write-Host "::SET-ZIP-FILENAME::$zipFilename" - Write-Host "::SET-ENV::CREATED_ZIP_FILENAME=$zipFilename" + # Output the zip filename to standard output for the Groovy script to capture + # Write-Host "::SET-ZIP-FILENAME::$zipFilename" # Removed, using Write-Output instead + # Write-Host "::SET-ENV::CREATED_ZIP_FILENAME=$zipFilename" # Removed, using Write-Output instead + Write-Output $zipFilename exit 0 ''' // End powershell script + + // Capture the output and set the environment variable + // The PowerShell script outputs the zip filename as the last line + env.CREATED_ZIP_FILENAME = zipFilenameOutput.trim() + echo "Set CREATED_ZIP_FILENAME environment variable to: ${env.CREATED_ZIP_FILENAME}" + } // End dir block } } @@ -145,14 +152,14 @@ pipeline { // The zip filename was set as an environment variable in the previous stage def createdZipFilename = env.CREATED_ZIP_FILENAME - if (createdZipFilename) { + if (createdZipFilename && !createdZipFilename.trim().isEmpty()) { echo "Identified created zip file for archiving: ${createdZipFilename}" // Archive the created zip file using Jenkins built-in step // The zip file is created in the MAIN_BUILD_ARTIFACTS_DIR by the Batch script archiveArtifacts artifacts: "${createdZipFilename}", fingerprint: true echo "Archive step completed." } else { - error "CREATED_ZIP_FILENAME environment variable was not set. Cannot archive." + error "CREATED_ZIP_FILENAME environment variable was not set or was empty. Cannot archive." } } // End dir block } From ea71ec2adde3e2577a2f137e747ea515602d87cc Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 13:50:56 +0300 Subject: [PATCH 11/85] zip update --- build/jenkins/zip | 137 ++++++++++++++++++++++++++-------------------- 1 file changed, 78 insertions(+), 59 deletions(-) diff --git a/build/jenkins/zip b/build/jenkins/zip index 0e47f00..97d2c40 100644 --- a/build/jenkins/zip +++ b/build/jenkins/zip @@ -53,7 +53,7 @@ pipeline { // def defaultVersion = '1.0.0' - // Use a powershell step to perform file finding, filename extraction, timestamp generation, and zipping + // Use a powershell step to check for existing zip, or create a new one, then output the filename // Capture the output of the powershell script def zipFilenameOutput = powershell returnStdout: true, script: ''' $ErrorActionPreference = "Stop" # Stop the script on any error @@ -62,72 +62,91 @@ pipeline { $defaultVersion = "1.0.0" # Default version if no exe is found $exePattern = "AzaionSuite*.exe" $binPattern = "AzaionSuite*.bin" + $zipPattern = "AzaionSuite*.zip" # Pattern for existing zip files - Write-Host "Searching for files matching $exePattern and $binPattern in the current directory for zipping..." + Write-Host "Operating in directory: $(Get-Location)" - # Find all files matching the patterns - $foundFiles = Get-ChildItem -Recurse -Path . -Include $exePattern, $binPattern | Select-Object -ExpandProperty FullName + # --- Check for existing zip files --- + Write-Host "Checking for existing zip files matching '$zipPattern'..." + $existingZips = Get-ChildItem -Path . -Include $zipPattern | Sort-Object LastWriteTime -Descending - if ($foundFiles.Count -eq 0) { - Write-Error "No files matching patterns $exePattern or $binPattern found in $(Get-Location)." - exit 1 - } + $zipFilename = "" + $zipFound = $false - Write-Host "Found $($foundFiles.Count) file(s) to archive." - - # --- Determine Base Filename for Zip (from .exe if present) --- - $zipBaseFilename = "AzaionSuite.$defaultVersion" # Default base filename - $exeFile = Get-ChildItem -Recurse -Path . -Filter $exePattern | Select-Object -First 1 - - if ($exeFile) { - Write-Host "Executable file found: '$($exeFile.FullName)'" - # Extract filename without extension - $zipBaseFilename = $exeFile.BaseName - Write-Host "Using executable base filename for archive name: '$zipBaseFilename'" + if ($existingZips.Count -gt 0) { + # Found existing zip files, use the newest one + $newestZip = $existingZips | Select-Object -First 1 + $zipFilename = $newestZip.Name + $zipFound = $true + Write-Host "Found existing zip file: '$zipFilename'. Skipping creation." } else { - Write-Warning "No executable found matching $exePattern. Using default base filename: '$zipBaseFilename'" + # No existing zip files, proceed with creation + Write-Host "No existing zip files found. Proceeding with creation." + + Write-Host "Searching for files matching $exePattern and $binPattern in the current directory for zipping..." + + # Find all files matching the patterns + $foundFiles = Get-ChildItem -Recurse -Path . -Include $exePattern, $binPattern | Select-Object -ExpandProperty FullName + + if ($foundFiles.Count -eq 0) { + Write-Error "No files matching patterns $exePattern or $binPattern found in $(Get-Location)." + exit 1 + } + + Write-Host "Found $($foundFiles.Count) file(s) to archive." + + # --- Determine Base Filename for Zip (from .exe if present) --- + $zipBaseFilename = "AzaionSuite.$defaultVersion" # Default base filename + $exeFile = Get-ChildItem -Recurse -Path . -Filter $exePattern | Select-Object -First 1 + + if ($exeFile) { + Write-Host "Executable file found: '$($exeFile.FullName)'" + # Extract filename without extension + $zipBaseFilename = $exeFile.BaseName + Write-Host "Using executable base filename for archive name: '$zipBaseFilename'" + } else { + Write-Warning "No executable found matching $exePattern. Using default base filename: '$zipBaseFilename'" + } + + # --- Zipping Logic --- + + # Get current date and time inYYYYMMDD-HHmmss format + $timestamp = (Get-Date -Format "yyyyMMdd-HHmmss") + + # Construct the zip filename using the base filename and timestamp + $zipFilename = "$zipBaseFilename-$timestamp.zip" + + Write-Host "Creating zip archive: $zipFilename using 7-Zip." + + # Build the 7z command arguments + # Start with command, type, and quoted zip filename + $sevenZipArgs = @("a", "-tzip", "$zipFilename") + + # Add the list of found files, ensuring each path is quoted + # Using backticks to escape quotes within the PowerShell string + $foundFilesQuoted = $foundFiles | ForEach-Object { "`"$_`"" } + $sevenZipArgs += $foundFilesQuoted + + # Construct the full command string for logging + $commandString = "$sevenZipExe $($sevenZipArgs -join ' ')" + Write-Host "Executing command: $commandString" + + # Execute the 7z command + # Using Start-Process with -Wait to ensure the script waits for 7z to finish + # and capturing the exit code + $process = Start-Process -FilePath $sevenZipExe -ArgumentList $sevenZipArgs -Wait -PassThru + $exitCode = $process.ExitCode + + # Check the last exit code from the external command + if ($exitCode -ne 0) { + Write-Error "Error creating zip archive with 7-Zip. 7z exit code: $exitCode" + exit $exitCode + } + + Write-Host "Zip archive created successfully by 7-Zip: $zipFilename" } - # --- Zipping Logic --- - - # Get current date and time inYYYYMMDD-HHmmss format - $timestamp = (Get-Date -Format "yyyyMMdd-HHmmss") - - # Construct the zip filename using the base filename and timestamp - $zipFilename = "$zipBaseFilename-$timestamp.zip" - - Write-Host "Creating zip archive: $zipFilename using 7-Zip." - - # Build the 7z command arguments - # Start with command, type, and quoted zip filename - $sevenZipArgs = @("a", "-tzip", "$zipFilename") - - # Add the list of found files, ensuring each path is quoted - # Using backticks to escape quotes within the PowerShell string - $foundFilesQuoted = $foundFiles | ForEach-Object { "`"$_`"" } - $sevenZipArgs += $foundFilesQuoted - - # Construct the full command string for logging - $commandString = "$sevenZipExe $($sevenZipArgs -join ' ')" - Write-Host "Executing command: $commandString" - - # Execute the 7z command - # Using Start-Process with -Wait to ensure the script waits for 7z to finish - # and capturing the exit code - $process = Start-Process -FilePath $sevenZipExe -ArgumentList $sevenZipArgs -Wait -PassThru - $exitCode = $process.ExitCode - - # Check the last exit code from the external command - if ($exitCode -ne 0) { - Write-Error "Error creating zip archive with 7-Zip. 7z exit code: $exitCode" - exit $exitCode - } - - Write-Host "Zip archive created successfully by 7-Zip: $zipFilename" - # Output the zip filename to standard output for the Groovy script to capture - # Write-Host "::SET-ZIP-FILENAME::$zipFilename" # Removed, using Write-Output instead - # Write-Host "::SET-ENV::CREATED_ZIP_FILENAME=$zipFilename" # Removed, using Write-Output instead Write-Output $zipFilename exit 0 From 7de0fe363bc39714612d021b1e370995a927d45a Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 13:52:20 +0300 Subject: [PATCH 12/85] zip update --- build/jenkins/zip | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/build/jenkins/zip b/build/jenkins/zip index 97d2c40..ca62f04 100644 --- a/build/jenkins/zip +++ b/build/jenkins/zip @@ -66,10 +66,25 @@ pipeline { Write-Host "Operating in directory: $(Get-Location)" + # --- Debugging: List all items in the directory --- + Write-Host "DEBUG: Listing all items in the current directory:" + Get-ChildItem -Path . | ForEach-Object { Write-Host "DEBUG: Item: $($_.FullName)" } + Write-Host "DEBUG: End of item listing." + # --- Check for existing zip files --- Write-Host "Checking for existing zip files matching '$zipPattern'..." $existingZips = Get-ChildItem -Path . -Include $zipPattern | Sort-Object LastWriteTime -Descending + # --- Debugging: Show found zip files --- + Write-Host "DEBUG: Files found by Get-ChildItem -Path . -Include '$zipPattern':" + if ($existingZips.Count -gt 0) { + $existingZips | ForEach-Object { Write-Host "DEBUG: Found zip: $($_.Name)" } + } else { + Write-Host "DEBUG: No zip files found by Get-ChildItem with pattern '$zipPattern'." + } + Write-Host "DEBUG: End of found zip listing." + + $zipFilename = "" $zipFound = $false From d5057dd86c4f9aac732b14d736974a3c61653fd0 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 13:53:29 +0300 Subject: [PATCH 13/85] zip update --- build/jenkins/zip | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/build/jenkins/zip b/build/jenkins/zip index ca62f04..413c82c 100644 --- a/build/jenkins/zip +++ b/build/jenkins/zip @@ -72,15 +72,16 @@ pipeline { Write-Host "DEBUG: End of item listing." # --- Check for existing zip files --- - Write-Host "Checking for existing zip files matching '$zipPattern'..." - $existingZips = Get-ChildItem -Path . -Include $zipPattern | Sort-Object LastWriteTime -Descending + Write-Host "Checking for existing zip files matching '$zipPattern' using -Filter..." + # Corrected: Using -Filter instead of -Include with -Path . + $existingZips = Get-ChildItem -Path . -Filter $zipPattern | Sort-Object LastWriteTime -Descending # --- Debugging: Show found zip files --- - Write-Host "DEBUG: Files found by Get-ChildItem -Path . -Include '$zipPattern':" + Write-Host "DEBUG: Files found by Get-ChildItem -Path . -Filter '$zipPattern':" if ($existingZips.Count -gt 0) { $existingZips | ForEach-Object { Write-Host "DEBUG: Found zip: $($_.Name)" } } else { - Write-Host "DEBUG: No zip files found by Get-ChildItem with pattern '$zipPattern'." + Write-Host "DEBUG: No zip files found by Get-ChildItem with pattern '$zipPattern' using -Filter." } Write-Host "DEBUG: End of found zip listing." From fcda29fd497cf13fbad8904babd9c1d4aa0b2e6c Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 13:54:32 +0300 Subject: [PATCH 14/85] zip update --- build/jenkins/zip | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/build/jenkins/zip b/build/jenkins/zip index 413c82c..1799eb2 100644 --- a/build/jenkins/zip +++ b/build/jenkins/zip @@ -54,7 +54,7 @@ pipeline { // Use a powershell step to check for existing zip, or create a new one, then output the filename - // Capture the output of the powershell script + // Capture the output of the powershell script, redirecting stderr to stdout def zipFilenameOutput = powershell returnStdout: true, script: ''' $ErrorActionPreference = "Stop" # Stop the script on any error @@ -166,12 +166,19 @@ pipeline { Write-Output $zipFilename exit 0 - ''' // End powershell script + ''' 2>&1 // End powershell script and redirect stderr to stdout // Capture the output and set the environment variable // The PowerShell script outputs the zip filename as the last line - env.CREATED_ZIP_FILENAME = zipFilenameOutput.trim() - echo "Set CREATED_ZIP_FILENAME environment variable to: ${env.CREATED_ZIP_FILENAME}" + // Use readLines() to handle multi-line output and get the last line + def outputLines = zipFilenameOutput.readLines() + if (!outputLines.isEmpty()) { + env.CREATED_ZIP_FILENAME = outputLines.last().trim() + echo "Set CREATED_ZIP_FILENAME environment variable to: ${env.CREATED_ZIP_FILENAME}" + } else { + error "PowerShell script did not produce any output to capture the zip filename." + } + } // End dir block } @@ -194,6 +201,7 @@ pipeline { archiveArtifacts artifacts: "${createdZipFilename}", fingerprint: true echo "Archive step completed." } else { + // This error should now be less likely with improved output capturing error "CREATED_ZIP_FILENAME environment variable was not set or was empty. Cannot archive." } } // End dir block From 53ecfb3cad85fec4d496d1ff4875d0c5c9b5f797 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 13:55:15 +0300 Subject: [PATCH 15/85] zip update --- build/jenkins/zip | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/build/jenkins/zip b/build/jenkins/zip index 1799eb2..32c7543 100644 --- a/build/jenkins/zip +++ b/build/jenkins/zip @@ -1,3 +1,5 @@ +&1)"> +```groovy // This pipeline job is triggered by the main AzaionSuite build pipeline. // It operates directly within the main build job's artifact directory, // zips the artifacts using PowerShell and 7-Zip, and then triggers the Google Drive upload pipeline. @@ -54,7 +56,7 @@ pipeline { // Use a powershell step to check for existing zip, or create a new one, then output the filename - // Capture the output of the powershell script, redirecting stderr to stdout + // Capture the output of the powershell script def zipFilenameOutput = powershell returnStdout: true, script: ''' $ErrorActionPreference = "Stop" # Stop the script on any error @@ -163,20 +165,22 @@ pipeline { } # Output the zip filename to standard output for the Groovy script to capture + # Ensure this is the very last thing written to the standard output stream Write-Output $zipFilename exit 0 - ''' 2>&1 // End powershell script and redirect stderr to stdout + ''' // End powershell script // Capture the output and set the environment variable // The PowerShell script outputs the zip filename as the last line // Use readLines() to handle multi-line output and get the last line - def outputLines = zipFilenameOutput.readLines() + def outputLines = zipFilenameOutput.readLines().findAll { it.trim() != '' } // Filter out empty lines if (!outputLines.isEmpty()) { env.CREATED_ZIP_FILENAME = outputLines.last().trim() echo "Set CREATED_ZIP_FILENAME environment variable to: ${env.CREATED_ZIP_FILENAME}" } else { - error "PowerShell script did not produce any output to capture the zip filename." + // This error should now be more informative if no output is captured + error "PowerShell script did not produce any non-empty output lines to capture the zip filename." } @@ -228,3 +232,4 @@ pipeline { } // End stage block } // End of stages block } // End of pipeline block +``` \ No newline at end of file From 5b143d38ced4a17aebce165ee5990e1934a097ef Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 13:55:45 +0300 Subject: [PATCH 16/85] zip update --- build/jenkins/zip | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/build/jenkins/zip b/build/jenkins/zip index 32c7543..acca572 100644 --- a/build/jenkins/zip +++ b/build/jenkins/zip @@ -231,5 +231,4 @@ pipeline { } // End steps block } // End stage block } // End of stages block -} // End of pipeline block -``` \ No newline at end of file +} // End of pipeline block \ No newline at end of file From 05b830b7fb94bc1d9df79954c2aeb8df5256b459 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 13:56:31 +0300 Subject: [PATCH 17/85] zip update --- build/jenkins/zip | 5 ----- 1 file changed, 5 deletions(-) diff --git a/build/jenkins/zip b/build/jenkins/zip index acca572..a3682b3 100644 --- a/build/jenkins/zip +++ b/build/jenkins/zip @@ -1,8 +1,3 @@ -&1)"> -```groovy -// This pipeline job is triggered by the main AzaionSuite build pipeline. -// It operates directly within the main build job's artifact directory, -// zips the artifacts using PowerShell and 7-Zip, and then triggers the Google Drive upload pipeline. pipeline { // Agent should be your Windows VM agent // This job MUST run on the SAME agent as the main build job From b165aa3ede38939335c751a9656327af53091d5d Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 13:58:40 +0300 Subject: [PATCH 18/85] zip update --- build/jenkins/zip | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/build/jenkins/zip b/build/jenkins/zip index a3682b3..3b67a36 100644 --- a/build/jenkins/zip +++ b/build/jenkins/zip @@ -1,3 +1,6 @@ +// This pipeline job is triggered by the main AzaionSuite build pipeline. +// It operates directly within the main build job's artifact directory, +// zips the artifacts using PowerShell and 7-Zip, and then triggers the Google Drive upload pipeline. pipeline { // Agent should be your Windows VM agent // This job MUST run on the SAME agent as the main build job @@ -42,14 +45,6 @@ pipeline { dir("${env.MAIN_BUILD_ARTIFACTS_DIR}") { echo "Operating in directory: ${pwd()}" - // Define the expected artifact patterns relative to the current directory (MAIN_BUILD_ARTIFACTS_DIR) - // These are now defined as literals within the PowerShell script string - // def exePattern = 'AzaionSuite*.exe' - // def binPattern = 'AzaionSuite*.bin' - // Define defaultVersion here, used if no exe is found - // def defaultVersion = '1.0.0' - - // Use a powershell step to check for existing zip, or create a new one, then output the filename // Capture the output of the powershell script def zipFilenameOutput = powershell returnStdout: true, script: ''' @@ -168,15 +163,9 @@ pipeline { // Capture the output and set the environment variable // The PowerShell script outputs the zip filename as the last line - // Use readLines() to handle multi-line output and get the last line - def outputLines = zipFilenameOutput.readLines().findAll { it.trim() != '' } // Filter out empty lines - if (!outputLines.isEmpty()) { - env.CREATED_ZIP_FILENAME = outputLines.last().trim() - echo "Set CREATED_ZIP_FILENAME environment variable to: ${env.CREATED_ZIP_FILENAME}" - } else { - // This error should now be more informative if no output is captured - error "PowerShell script did not produce any non-empty output lines to capture the zip filename." - } + // Trim any leading/trailing whitespace or newlines from the captured output + env.CREATED_ZIP_FILENAME = zipFilenameOutput.trim() + echo "Set CREATED_ZIP_FILENAME environment variable to: ${env.CREATED_ZIP_FILENAME}" } // End dir block @@ -226,4 +215,4 @@ pipeline { } // End steps block } // End stage block } // End of stages block -} // End of pipeline block \ No newline at end of file +} // End of pipeline block From 23f9ff16a4371543c0fd37d5479a0890b7ebc6df Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 13:59:44 +0300 Subject: [PATCH 19/85] zip update --- build/jenkins/zip | 63 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 50 insertions(+), 13 deletions(-) diff --git a/build/jenkins/zip b/build/jenkins/zip index 3b67a36..f59fe6e 100644 --- a/build/jenkins/zip +++ b/build/jenkins/zip @@ -30,7 +30,7 @@ pipeline { // Define the name of the created zip file as an environment variable // This makes it easier to reference in later stages - CREATED_ZIP_FILENAME = '' // This will be set dynamically by capturing PowerShell output + CREATED_ZIP_FILENAME = '' // This will be set dynamically by reading a temp file } stages { @@ -39,15 +39,17 @@ pipeline { stage('Archive Build Artifacts (PowerShell/7-Zip)') { steps { - script { // Need script block for dir and powershell step + script { // Need script block for dir, powershell, and file operations echo "Starting 'Archive Build Artifacts (PowerShell/7-Zip)' stage." // Change directory to the main build job's artifacts folder dir("${env.MAIN_BUILD_ARTIFACTS_DIR}") { echo "Operating in directory: ${pwd()}" - // Use a powershell step to check for existing zip, or create a new one, then output the filename - // Capture the output of the powershell script - def zipFilenameOutput = powershell returnStdout: true, script: ''' + // Define the name for the temporary file to store the zip filename + def tempFilenameFile = "zip_filename.txt" + + // Use a powershell step to check for existing zip, or create a new one, then write the filename to a temp file + powershell ''' $ErrorActionPreference = "Stop" # Stop the script on any error $sevenZipExe = "$env:SEVEN_ZIP_PATH\\7z.exe" @@ -55,6 +57,7 @@ pipeline { $exePattern = "AzaionSuite*.exe" $binPattern = "AzaionSuite*.bin" $zipPattern = "AzaionSuite*.zip" # Pattern for existing zip files + $tempFilenameFile = "''' + tempFilenameFile + '''" # Pass temp filename to PowerShell Write-Host "Operating in directory: $(Get-Location)" @@ -154,18 +157,52 @@ pipeline { Write-Host "Zip archive created successfully by 7-Zip: $zipFilename" } - # Output the zip filename to standard output for the Groovy script to capture - # Ensure this is the very last thing written to the standard output stream - Write-Output $zipFilename + # Write the determined zip filename to a temporary file + Write-Host "Writing zip filename '$zipFilename' to temporary file '$tempFilenameFile'..." + $zipFilename | Out-File -Path $tempFilenameFile -Encoding UTF8 -Force exit 0 ''' // End powershell script - // Capture the output and set the environment variable - // The PowerShell script outputs the zip filename as the last line - // Trim any leading/trailing whitespace or newlines from the captured output - env.CREATED_ZIP_FILENAME = zipFilenameOutput.trim() - echo "Set CREATED_ZIP_FILENAME environment variable to: ${env.CREATED_ZIP_FILENAME}" + // Read the zip filename from the temporary file + def createdZipFilename = "" + def tempFilenameFile = "zip_filename.txt" // Must match the name used in PowerShell + + try { + echo "Attempting to read zip filename from temporary file: ${tempFilenameFile}" + createdZipFilename = readFile(tempFilenameFile).trim() + echo "Successfully read zip filename: ${createdZipFilename}" + } catch (FileNotFoundException e) { + // This might happen if the PowerShell script failed before writing the file + echo "Warning: Temporary filename file '${tempFilenameFile}' not found. Zip creation might have failed." + } finally { + // Clean up the temporary file + echo "Cleaning up temporary filename file: ${tempFilenameFile}" + deleteDir() // Use deleteDir() to remove files/dirs in the current dir block + // Or more specifically: fileOperations([genSandboxConfig: true, operations: [[excludes: null, includes: tempFilenameFile, pattern: null, type: 'DELETE']]]) + // Let's use deleteDir() within the dir block for simplicity here. Note: deleteDir() removes everything in the current dir block. + // A more targeted approach might be needed if other files must persist. + // For now, let's assume it's safe to clean the entire dir block. + // Wait, deleteDir() is too aggressive. Let's use the fileOperations step. + } + + // Re-implementing cleanup using fileOperations + try { + echo "Cleaning up temporary filename file: ${tempFilenameFile} using fileOperations" + fileOperations([genSandboxConfig: true, operations: [[excludes: null, includes: tempFilenameFile, pattern: null, type: 'DELETE']]]) + echo "Temporary filename file cleaned up." + } catch (Exception e) { + echo "Warning: Failed to clean up temporary filename file '${tempFilenameFile}': ${e.getMessage()}" + } + + + // Set the environment variable for subsequent stages + if (createdZipFilename && !createdZipFilename.trim().isEmpty()) { + env.CREATED_ZIP_FILENAME = createdZipFilename + echo "Set CREATED_ZIP_FILENAME environment variable to: ${env.CREATED_ZIP_FILENAME}" + } else { + error "Captured zip filename was empty or could not be read from the temporary file. Cannot archive." + } } // End dir block From c1a755c477b62b3dacffca117d40b6d00a56b065 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 14:00:34 +0300 Subject: [PATCH 20/85] zip update --- build/jenkins/zip | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/build/jenkins/zip b/build/jenkins/zip index f59fe6e..dfd8179 100644 --- a/build/jenkins/zip +++ b/build/jenkins/zip @@ -166,7 +166,7 @@ pipeline { // Read the zip filename from the temporary file def createdZipFilename = "" - def tempFilenameFile = "zip_filename.txt" // Must match the name used in PowerShell + // Removed the duplicate declaration of tempFilenameFile here. try { echo "Attempting to read zip filename from temporary file: ${tempFilenameFile}" @@ -177,22 +177,13 @@ pipeline { echo "Warning: Temporary filename file '${tempFilenameFile}' not found. Zip creation might have failed." } finally { // Clean up the temporary file - echo "Cleaning up temporary filename file: ${tempFilenameFile}" - deleteDir() // Use deleteDir() to remove files/dirs in the current dir block - // Or more specifically: fileOperations([genSandboxConfig: true, operations: [[excludes: null, includes: tempFilenameFile, pattern: null, type: 'DELETE']]]) - // Let's use deleteDir() within the dir block for simplicity here. Note: deleteDir() removes everything in the current dir block. - // A more targeted approach might be needed if other files must persist. - // For now, let's assume it's safe to clean the entire dir block. - // Wait, deleteDir() is too aggressive. Let's use the fileOperations step. - } - - // Re-implementing cleanup using fileOperations - try { - echo "Cleaning up temporary filename file: ${tempFilenameFile} using fileOperations" - fileOperations([genSandboxConfig: true, operations: [[excludes: null, includes: tempFilenameFile, pattern: null, type: 'DELETE']]]) - echo "Temporary filename file cleaned up." - } catch (Exception e) { - echo "Warning: Failed to clean up temporary filename file '${tempFilenameFile}': ${e.getMessage()}" + try { + echo "Cleaning up temporary filename file: ${tempFilenameFile} using fileOperations" + fileOperations([genSandboxConfig: true, operations: [[excludes: null, includes: tempFilenameFile, pattern: null, type: 'DELETE']]]) + echo "Temporary filename file cleaned up." + } catch (Exception e) { + echo "Warning: Failed to clean up temporary filename file '${tempFilenameFile}': ${e.getMessage()}" + } } From 6be07693ccc10655f533c09494e1a23a0b85d5c9 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 14:02:24 +0300 Subject: [PATCH 21/85] zip update --- build/jenkins/zip | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/jenkins/zip b/build/jenkins/zip index dfd8179..3eac561 100644 --- a/build/jenkins/zip +++ b/build/jenkins/zip @@ -159,14 +159,14 @@ pipeline { # Write the determined zip filename to a temporary file Write-Host "Writing zip filename '$zipFilename' to temporary file '$tempFilenameFile'..." - $zipFilename | Out-File -Path $tempFilenameFile -Encoding UTF8 -Force + $zipFilename | Out-File -FilePath $tempFilenameFile -Encoding UTF8 -Force # Corrected: Using -FilePath exit 0 ''' // End powershell script // Read the zip filename from the temporary file def createdZipFilename = "" - // Removed the duplicate declaration of tempFilenameFile here. + // The tempFilenameFile variable is already defined above try { echo "Attempting to read zip filename from temporary file: ${tempFilenameFile}" From 6c49b63e8ee6fcf6aa357649151d4791879633e4 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 14:04:15 +0300 Subject: [PATCH 22/85] zip update --- build/jenkins/zip | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/build/jenkins/zip b/build/jenkins/zip index 3eac561..10cacf9 100644 --- a/build/jenkins/zip +++ b/build/jenkins/zip @@ -80,6 +80,7 @@ pipeline { } Write-Host "DEBUG: End of found zip listing." + Write-Host "DEBUG: Existing zip files found count: $($existingZips.Count)" $zipFilename = "" $zipFound = $false @@ -89,10 +90,10 @@ pipeline { $newestZip = $existingZips | Select-Object -First 1 $zipFilename = $newestZip.Name $zipFound = $true - Write-Host "Found existing zip file: '$zipFilename'. Skipping creation." + Write-Host "DEBUG: Using newest existing zip file: '$zipFilename'. Skipping creation process." } else { # No existing zip files, proceed with creation - Write-Host "No existing zip files found. Proceeding with creation." + Write-Host "DEBUG: No existing zip files found. Proceeding with file finding and zipping process." Write-Host "Searching for files matching $exePattern and $binPattern in the current directory for zipping..." @@ -158,8 +159,8 @@ pipeline { } # Write the determined zip filename to a temporary file - Write-Host "Writing zip filename '$zipFilename' to temporary file '$tempFilenameFile'..." - $zipFilename | Out-File -FilePath $tempFilenameFile -Encoding UTF8 -Force # Corrected: Using -FilePath + Write-Host "Writing determined zip filename '$zipFilename' to temporary file '$tempFilenameFile'..." + $zipFilename | Out-File -FilePath $tempFilenameFile -Encoding UTF8 -Force exit 0 ''' // End powershell script @@ -176,10 +177,10 @@ pipeline { // This might happen if the PowerShell script failed before writing the file echo "Warning: Temporary filename file '${tempFilenameFile}' not found. Zip creation might have failed." } finally { - // Clean up the temporary file + // Clean up the temporary file using a powershell step try { - echo "Cleaning up temporary filename file: ${tempFilenameFile} using fileOperations" - fileOperations([genSandboxConfig: true, operations: [[excludes: null, includes: tempFilenameFile, pattern: null, type: 'DELETE']]]) + echo "Cleaning up temporary filename file: ${tempFilenameFile} using powershell" + powershell "Remove-Item -Path '${tempFilenameFile}' -Force" echo "Temporary filename file cleaned up." } catch (Exception e) { echo "Warning: Failed to clean up temporary filename file '${tempFilenameFile}': ${e.getMessage()}" From 154b5cdcf65e2a7c4659428bc041c99c9ac56544 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 14:08:46 +0300 Subject: [PATCH 23/85] zip update --- build/jenkins/zip | 110 +++++++++++++++++----------------------------- 1 file changed, 41 insertions(+), 69 deletions(-) diff --git a/build/jenkins/zip b/build/jenkins/zip index 10cacf9..48661c2 100644 --- a/build/jenkins/zip +++ b/build/jenkins/zip @@ -30,7 +30,7 @@ pipeline { // Define the name of the created zip file as an environment variable // This makes it easier to reference in later stages - CREATED_ZIP_FILENAME = '' // This will be set dynamically by reading a temp file + CREATED_ZIP_FILENAME = '' // This will be set dynamically by capturing PowerShell output } stages { @@ -39,17 +39,15 @@ pipeline { stage('Archive Build Artifacts (PowerShell/7-Zip)') { steps { - script { // Need script block for dir, powershell, and file operations + script { // Need script block for dir and powershell step echo "Starting 'Archive Build Artifacts (PowerShell/7-Zip)' stage." // Change directory to the main build job's artifacts folder dir("${env.MAIN_BUILD_ARTIFACTS_DIR}") { echo "Operating in directory: ${pwd()}" - // Define the name for the temporary file to store the zip filename - def tempFilenameFile = "zip_filename.txt" - - // Use a powershell step to check for existing zip, or create a new one, then write the filename to a temp file - powershell ''' + // Use a powershell step to check for existing zip, or create a new one, then output the filename + // Capture the output of the powershell script + def zipFilenameOutput = powershell returnStdout: true, script: ''' $ErrorActionPreference = "Stop" # Stop the script on any error $sevenZipExe = "$env:SEVEN_ZIP_PATH\\7z.exe" @@ -57,7 +55,6 @@ pipeline { $exePattern = "AzaionSuite*.exe" $binPattern = "AzaionSuite*.bin" $zipPattern = "AzaionSuite*.zip" # Pattern for existing zip files - $tempFilenameFile = "''' + tempFilenameFile + '''" # Pass temp filename to PowerShell Write-Host "Operating in directory: $(Get-Location)" @@ -90,112 +87,87 @@ pipeline { $newestZip = $existingZips | Select-Object -First 1 $zipFilename = $newestZip.Name $zipFound = $true - Write-Host "DEBUG: Using newest existing zip file: '$zipFilename'. Skipping creation process." + Write-Host "Using newest existing zip file: '$zipFilename'. Skipping creation process." + # Skip the rest of the script that creates a new zip } else { # No existing zip files, proceed with creation - Write-Host "DEBUG: No existing zip files found. Proceeding with file finding and zipping process." + Write-Host "No existing zip files found. Proceeding with file finding and zipping process." Write-Host "Searching for files matching $exePattern and $binPattern in the current directory for zipping..." # Find all files matching the patterns - $foundFiles = Get-ChildItem -Recurse -Path . -Include $exePattern, $binPattern | Select-Object -ExpandProperty FullName + $foundFiles = Get-ChildItem -Recurse -Path . -Include \$exePattern, \$binPattern | Select-Object -ExpandProperty FullName - if ($foundFiles.Count -eq 0) { - Write-Error "No files matching patterns $exePattern or $binPattern found in $(Get-Location)." + if (\$foundFiles.Count -eq 0) { + Write-Error "No files matching patterns \$exePattern or \$binPattern found in \$(Get-Location)." exit 1 } - Write-Host "Found $($foundFiles.Count) file(s) to archive." + Write-Host "Found \$(\$foundFiles.Count) file(s) to archive." # --- Determine Base Filename for Zip (from .exe if present) --- - $zipBaseFilename = "AzaionSuite.$defaultVersion" # Default base filename - $exeFile = Get-ChildItem -Recurse -Path . -Filter $exePattern | Select-Object -First 1 + \$zipBaseFilename = "AzaionSuite.\$defaultVersion" # Default base filename + \$exeFile = Get-ChildItem -Recurse -Path . -Filter \$exePattern | Select-Object -First 1 - if ($exeFile) { - Write-Host "Executable file found: '$($exeFile.FullName)'" + if (\$exeFile) { + Write-Host "Executable file found: '\$(\$exeFile.FullName)'" # Extract filename without extension - $zipBaseFilename = $exeFile.BaseName - Write-Host "Using executable base filename for archive name: '$zipBaseFilename'" + \$zipBaseFilename = \$exeFile.BaseName + Write-Host "Using executable base filename for archive name: '\$zipBaseFilename'" } else { - Write-Warning "No executable found matching $exePattern. Using default base filename: '$zipBaseFilename'" + Write-Warning "No executable found matching \$exePattern. Using default base filename: '\$zipBaseFilename'" } # --- Zipping Logic --- # Get current date and time inYYYYMMDD-HHmmss format - $timestamp = (Get-Date -Format "yyyyMMdd-HHmmss") + \$timestamp = (Get-Date -Format "yyyyMMdd-HHmmss") # Construct the zip filename using the base filename and timestamp - $zipFilename = "$zipBaseFilename-$timestamp.zip" + \$zipFilename = "\$zipBaseFilename-\$timestamp.zip" - Write-Host "Creating zip archive: $zipFilename using 7-Zip." + Write-Host "Creating zip archive: \$zipFilename using 7-Zip." # Build the 7z command arguments # Start with command, type, and quoted zip filename - $sevenZipArgs = @("a", "-tzip", "$zipFilename") + \$sevenZipArgs = @("a", "-tzip", "\$zipFilename") # Add the list of found files, ensuring each path is quoted # Using backticks to escape quotes within the PowerShell string - $foundFilesQuoted = $foundFiles | ForEach-Object { "`"$_`"" } - $sevenZipArgs += $foundFilesQuoted + \$foundFilesQuoted = \$foundFiles | ForEach-Object { "\`"$_`"" } + \$sevenZipArgs += \$foundFilesQuoted # Construct the full command string for logging - $commandString = "$sevenZipExe $($sevenZipArgs -join ' ')" - Write-Host "Executing command: $commandString" + \$commandString = "\$sevenZipExe \$(\$sevenZipArgs -join ' ')" + Write-Host "Executing command: \$commandString" # Execute the 7z command # Using Start-Process with -Wait to ensure the script waits for 7z to finish # and capturing the exit code - $process = Start-Process -FilePath $sevenZipExe -ArgumentList $sevenZipArgs -Wait -PassThru - $exitCode = $process.ExitCode + \$process = Start-Process -FilePath \$sevenZipExe -ArgumentList \$sevenZipArgs -Wait -PassThru + \$exitCode = \$process.ExitCode # Check the last exit code from the external command - if ($exitCode -ne 0) { - Write-Error "Error creating zip archive with 7-Zip. 7z exit code: $exitCode" - exit $exitCode + if (\$exitCode -ne 0) { + Write-Error "Error creating zip archive with 7-Zip. 7z exit code: \$exitCode" + exit \$exitCode } - Write-Host "Zip archive created successfully by 7-Zip: $zipFilename" + Write-Host "Zip archive created successfully by 7-Zip: \$zipFilename" } - # Write the determined zip filename to a temporary file - Write-Host "Writing determined zip filename '$zipFilename' to temporary file '$tempFilenameFile'..." - $zipFilename | Out-File -FilePath $tempFilenameFile -Encoding UTF8 -Force + # Output the determined zip filename to standard output for the Groovy script to capture + # Ensure this is the very last thing written to the standard output stream + # This output will be captured by returnStdout: true + Write-Output \$zipFilename exit 0 ''' // End powershell script - // Read the zip filename from the temporary file - def createdZipFilename = "" - // The tempFilenameFile variable is already defined above - - try { - echo "Attempting to read zip filename from temporary file: ${tempFilenameFile}" - createdZipFilename = readFile(tempFilenameFile).trim() - echo "Successfully read zip filename: ${createdZipFilename}" - } catch (FileNotFoundException e) { - // This might happen if the PowerShell script failed before writing the file - echo "Warning: Temporary filename file '${tempFilenameFile}' not found. Zip creation might have failed." - } finally { - // Clean up the temporary file using a powershell step - try { - echo "Cleaning up temporary filename file: ${tempFilenameFile} using powershell" - powershell "Remove-Item -Path '${tempFilenameFile}' -Force" - echo "Temporary filename file cleaned up." - } catch (Exception e) { - echo "Warning: Failed to clean up temporary filename file '${tempFilenameFile}': ${e.getMessage()}" - } - } - - - // Set the environment variable for subsequent stages - if (createdZipFilename && !createdZipFilename.trim().isEmpty()) { - env.CREATED_ZIP_FILENAME = createdZipFilename - echo "Set CREATED_ZIP_FILENAME environment variable to: ${env.CREATED_ZIP_FILENAME}" - } else { - error "Captured zip filename was empty or could not be read from the temporary file. Cannot archive." - } - + // Capture the output and set the environment variable + // The PowerShell script is designed to output ONLY the zip filename to standard output + env.CREATED_ZIP_FILENAME = zipFilenameOutput.trim() + echo "Set CREATED_ZIP_FILENAME environment variable to: ${env.CREATED_ZIP_FILENAME}" } // End dir block } From 366aab294e13a2464243c1577c116117f8c0bdeb Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 14:11:15 +0300 Subject: [PATCH 24/85] zip update --- build/jenkins/zip | 241 +++++++++++++++++++++------------------------- 1 file changed, 108 insertions(+), 133 deletions(-) diff --git a/build/jenkins/zip b/build/jenkins/zip index 48661c2..b3c27a5 100644 --- a/build/jenkins/zip +++ b/build/jenkins/zip @@ -9,7 +9,6 @@ pipeline { 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 { @@ -17,203 +16,179 @@ pipeline { 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 + PATH = "${SEVEN_ZIP_PATH};${env.PATH}" // Define the name of your existing Google Drive upload pipeline job - // ** IMPORTANT: Replace 'YourGoogleDriveUploadPipelineName' with the actual name ** - GOOGLE_DRIVE_UPLOAD_JOB_NAME = 'GDrive Upload' // <<== UPDATE THIS + GOOGLE_DRIVE_UPLOAD_JOB_NAME = 'GDrive Upload' // Define the source directory for artifacts from the main build job's workspace - // This is the directory this pipeline will change into to operate. - // ** IMPORTANT: Replace 'C:/Jenkins/workspace/AzaionSuite/suite' with the actual path ** - MAIN_BUILD_ARTIFACTS_DIR = 'C:/Jenkins/workspace/AzaionSuite/suite' // <<== UPDATE THIS + MAIN_BUILD_ARTIFACTS_DIR = 'C:/Jenkins/workspace/AzaionSuite/suite' // Define the name of the created zip file as an environment variable - // This makes it easier to reference in later stages - CREATED_ZIP_FILENAME = '' // This will be set dynamically by capturing PowerShell output + CREATED_ZIP_FILENAME = '' } stages { - // Removed the 'Copy Build Artifacts' stage. - // This pipeline will now operate directly in the MAIN_BUILD_ARTIFACTS_DIR. - stage('Archive Build Artifacts (PowerShell/7-Zip)') { steps { - script { // Need script block for dir and powershell step + script { echo "Starting 'Archive Build Artifacts (PowerShell/7-Zip)' stage." - // Change directory to the main build job's artifacts folder dir("${env.MAIN_BUILD_ARTIFACTS_DIR}") { echo "Operating in directory: ${pwd()}" - // Use a powershell step to check for existing zip, or create a new one, then output the filename - // Capture the output of the powershell script + // Use a powershell step with improved error handling and robustness def zipFilenameOutput = powershell returnStdout: true, script: ''' $ErrorActionPreference = "Stop" # Stop the script on any error + # Define key variables $sevenZipExe = "$env:SEVEN_ZIP_PATH\\7z.exe" - $defaultVersion = "1.0.0" # Default version if no exe is found + $defaultVersion = "1.0.0" $exePattern = "AzaionSuite*.exe" $binPattern = "AzaionSuite*.bin" - $zipPattern = "AzaionSuite*.zip" # Pattern for existing zip files + $zipPattern = "AzaionSuite*.zip" Write-Host "Operating in directory: $(Get-Location)" - # --- Debugging: List all items in the directory --- - Write-Host "DEBUG: Listing all items in the current directory:" - Get-ChildItem -Path . | ForEach-Object { Write-Host "DEBUG: Item: $($_.FullName)" } - Write-Host "DEBUG: End of item listing." - - # --- Check for existing zip files --- - Write-Host "Checking for existing zip files matching '$zipPattern' using -Filter..." - # Corrected: Using -Filter instead of -Include with -Path . - $existingZips = Get-ChildItem -Path . -Filter $zipPattern | Sort-Object LastWriteTime -Descending - - # --- Debugging: Show found zip files --- - Write-Host "DEBUG: Files found by Get-ChildItem -Path . -Filter '$zipPattern':" - if ($existingZips.Count -gt 0) { - $existingZips | ForEach-Object { Write-Host "DEBUG: Found zip: $($_.Name)" } - } else { - Write-Host "DEBUG: No zip files found by Get-ChildItem with pattern '$zipPattern' using -Filter." + # Check if 7-Zip exists + if (-not (Test-Path $sevenZipExe)) { + Write-Error "7-Zip executable not found at $sevenZipExe" + exit 1 } - Write-Host "DEBUG: End of found zip listing." - Write-Host "DEBUG: Existing zip files found count: $($existingZips.Count)" + # Check for existing zip files + $existingZips = Get-ChildItem -Path . -Filter $zipPattern | + Sort-Object LastWriteTime -Descending $zipFilename = "" - $zipFound = $false if ($existingZips.Count -gt 0) { # Found existing zip files, use the newest one $newestZip = $existingZips | Select-Object -First 1 $zipFilename = $newestZip.Name - $zipFound = $true - Write-Host "Using newest existing zip file: '$zipFilename'. Skipping creation process." - # Skip the rest of the script that creates a new zip + Write-Host "Using newest existing zip file: '$zipFilename'." } else { # No existing zip files, proceed with creation - Write-Host "No existing zip files found. Proceeding with file finding and zipping process." - - Write-Host "Searching for files matching $exePattern and $binPattern in the current directory for zipping..." + Write-Host "No existing zip files found. Creating new zip file." # Find all files matching the patterns - $foundFiles = Get-ChildItem -Recurse -Path . -Include \$exePattern, \$binPattern | Select-Object -ExpandProperty FullName + $foundFiles = Get-ChildItem -Recurse -Path . -Include $exePattern, $binPattern | + Select-Object -ExpandProperty FullName - if (\$foundFiles.Count -eq 0) { - Write-Error "No files matching patterns \$exePattern or \$binPattern found in \$(Get-Location)." + if ($foundFiles.Count -eq 0) { + Write-Error "No files matching patterns $exePattern or $binPattern found in $(Get-Location)." exit 1 } - Write-Host "Found \$(\$foundFiles.Count) file(s) to archive." + Write-Host "Found $($foundFiles.Count) file(s) to archive." - # --- Determine Base Filename for Zip (from .exe if present) --- - \$zipBaseFilename = "AzaionSuite.\$defaultVersion" # Default base filename - \$exeFile = Get-ChildItem -Recurse -Path . -Filter \$exePattern | Select-Object -First 1 + # Determine Base Filename for Zip (from .exe if present) + $zipBaseFilename = "AzaionSuite.$defaultVersion" # Default + $exeFile = Get-ChildItem -Recurse -Path . -Filter $exePattern | + Select-Object -First 1 - if (\$exeFile) { - Write-Host "Executable file found: '\$(\$exeFile.FullName)'" - # Extract filename without extension - \$zipBaseFilename = \$exeFile.BaseName - Write-Host "Using executable base filename for archive name: '\$zipBaseFilename'" + if ($exeFile) { + $zipBaseFilename = $exeFile.BaseName + Write-Host "Using executable base filename: '$zipBaseFilename'" } else { - Write-Warning "No executable found matching \$exePattern. Using default base filename: '\$zipBaseFilename'" + Write-Host "No executable found. Using default: '$zipBaseFilename'" } - # --- Zipping Logic --- + # Get timestamp for filename + $timestamp = (Get-Date -Format "yyyyMMdd-HHmmss") + $zipFilename = "$zipBaseFilename-$timestamp.zip" - # Get current date and time inYYYYMMDD-HHmmss format - \$timestamp = (Get-Date -Format "yyyyMMdd-HHmmss") + Write-Host "Creating zip archive: $zipFilename" - # Construct the zip filename using the base filename and timestamp - \$zipFilename = "\$zipBaseFilename-\$timestamp.zip" + try { + # Build the 7z command arguments + $sevenZipArgs = @("a", "-tzip", "$zipFilename") + $foundFilesQuoted = $foundFiles | ForEach-Object { "`"$_`"" } + $sevenZipArgs += $foundFilesQuoted - Write-Host "Creating zip archive: \$zipFilename using 7-Zip." + # Execute the 7z command + $process = Start-Process -FilePath $sevenZipExe -ArgumentList $sevenZipArgs -Wait -NoNewWindow -PassThru + $exitCode = $process.ExitCode - # Build the 7z command arguments - # Start with command, type, and quoted zip filename - \$sevenZipArgs = @("a", "-tzip", "\$zipFilename") + if ($exitCode -ne 0) { + Write-Error "Error creating zip archive. 7z exit code: $exitCode" + exit $exitCode + } - # Add the list of found files, ensuring each path is quoted - # Using backticks to escape quotes within the PowerShell string - \$foundFilesQuoted = \$foundFiles | ForEach-Object { "\`"$_`"" } - \$sevenZipArgs += \$foundFilesQuoted - - # Construct the full command string for logging - \$commandString = "\$sevenZipExe \$(\$sevenZipArgs -join ' ')" - Write-Host "Executing command: \$commandString" - - # Execute the 7z command - # Using Start-Process with -Wait to ensure the script waits for 7z to finish - # and capturing the exit code - \$process = Start-Process -FilePath \$sevenZipExe -ArgumentList \$sevenZipArgs -Wait -PassThru - \$exitCode = \$process.ExitCode - - # Check the last exit code from the external command - if (\$exitCode -ne 0) { - Write-Error "Error creating zip archive with 7-Zip. 7z exit code: \$exitCode" - exit \$exitCode + Write-Host "Zip archive created successfully: $zipFilename" + } + catch { + Write-Error "Exception occurred during zip creation: $_" + exit 1 } - - Write-Host "Zip archive created successfully by 7-Zip: \$zipFilename" } - # Output the determined zip filename to standard output for the Groovy script to capture - # Ensure this is the very last thing written to the standard output stream - # This output will be captured by returnStdout: true - Write-Output \$zipFilename + # Verify the zip file exists before returning + if (-not (Test-Path $zipFilename)) { + Write-Error "Expected zip file $zipFilename does not exist" + exit 1 + } + # Output the final zip filename + Write-Output $zipFilename exit 0 - ''' // End powershell script + ''' - // Capture the output and set the environment variable - // The PowerShell script is designed to output ONLY the zip filename to standard output + // Trim the output and set the environment variable env.CREATED_ZIP_FILENAME = zipFilenameOutput.trim() - echo "Set CREATED_ZIP_FILENAME environment variable to: ${env.CREATED_ZIP_FILENAME}" - - } // End dir block + echo "Zip filename: ${env.CREATED_ZIP_FILENAME}" + } } } } + stage('Archive Created Zip') { - steps { - script { // Need script block for dir and accessing environment variables set by PowerShell - echo "Starting 'Archive Created Zip' stage." - // Change directory back to the main build job's artifacts folder to archive the zip - dir("${env.MAIN_BUILD_ARTIFACTS_DIR}") { - echo "Operating in directory: ${pwd()}" - // The zip filename was set as an environment variable in the previous stage - def createdZipFilename = env.CREATED_ZIP_FILENAME + steps { + script { + echo "Starting 'Archive Created Zip' stage." + dir("${env.MAIN_BUILD_ARTIFACTS_DIR}") { + echo "Operating in directory: ${pwd()}" - if (createdZipFilename && !createdZipFilename.trim().isEmpty()) { - echo "Identified created zip file for archiving: ${createdZipFilename}" - // Archive the created zip file using Jenkins built-in step - // The zip file is created in the MAIN_BUILD_ARTIFACTS_DIR by the Batch script - archiveArtifacts artifacts: "${createdZipFilename}", fingerprint: true - echo "Archive step completed." - } else { - // This error should now be less likely with improved output capturing - error "CREATED_ZIP_FILENAME environment variable was not set or was empty. Cannot archive." - } - } // End dir block - } - } - } + // Verify zip filename was set properly + if (!env.CREATED_ZIP_FILENAME?.trim()) { + error "CREATED_ZIP_FILENAME environment variable was not set properly." + } + // Verify the file exists before attempting to archive + def fileExists = fileExists env.CREATED_ZIP_FILENAME + if (!fileExists) { + error "File ${env.CREATED_ZIP_FILENAME} does not exist at ${pwd()}." + } + + echo "Archiving zip file: ${env.CREATED_ZIP_FILENAME}" + archiveArtifacts artifacts: "${env.CREATED_ZIP_FILENAME}", fingerprint: true + echo "Archive step completed." + } + } + } + } stage('Trigger Google Drive Upload') { steps { - script { // This stage still requires a script block for the build step + script { echo "Triggering Google Drive Upload pipeline: ${env.GOOGLE_DRIVE_UPLOAD_JOB_NAME}" - // build job is a Jenkins Pipeline step, cannot be replaced by Batch directly. - // 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 and archiving it). - // The 'build' step executes from the current directory, which is inside the dir block. - dir("${env.MAIN_BUILD_ARTIFACTS_DIR}") { - echo "Operating in directory: ${pwd()}" - build job: env.GOOGLE_DRIVE_UPLOAD_JOB_NAME - } // End dir block - } // End script block - } // End steps block - } // End stage block - } // End of stages block -} // End of pipeline block + try { + build job: env.GOOGLE_DRIVE_UPLOAD_JOB_NAME + echo "Google Drive Upload pipeline triggered successfully." + } catch (Exception e) { + echo "Failed to trigger Google Drive Upload pipeline: ${e.message}" + error "Failed to trigger Google Drive Upload pipeline. See console log for details." + } + } + } + } + } + + post { + success { + echo "Pipeline completed successfully. Created and archived zip: ${env.CREATED_ZIP_FILENAME}" + } + failure { + echo "Pipeline failed. See logs for details." + } + } +} \ No newline at end of file From 604e3d132ef51be93398c6ec51e1b38c7b9d67bc Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 14:13:16 +0300 Subject: [PATCH 25/85] zip update --- build/jenkins/zip | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/build/jenkins/zip b/build/jenkins/zip index b3c27a5..2488631 100644 --- a/build/jenkins/zip +++ b/build/jenkins/zip @@ -128,14 +128,28 @@ pipeline { exit 1 } - # Output the final zip filename - Write-Output $zipFilename + # This is the critical fix - we need to make sure this is the last thing output + # And ensure it's on its own line with no other text + Write-Host "ZIPFILENAME=$zipFilename" exit 0 ''' - // Trim the output and set the environment variable - env.CREATED_ZIP_FILENAME = zipFilenameOutput.trim() - echo "Zip filename: ${env.CREATED_ZIP_FILENAME}" + // Extract the zip filename from the PowerShell output by looking for "ZIPFILENAME=" prefix + def outputLines = zipFilenameOutput.split('\n') + def zipFilename = null + for (line in outputLines) { + if (line.trim().startsWith("ZIPFILENAME=")) { + zipFilename = line.trim() - "ZIPFILENAME=" + break + } + } + + if (zipFilename) { + env.CREATED_ZIP_FILENAME = zipFilename.trim() + echo "Found zip filename: ${env.CREATED_ZIP_FILENAME}" + } else { + error "Failed to extract zip filename from PowerShell output. Check PowerShell script." + } } } } From 98d99ec7be4d2a1dbaae2cf5e6df0e5f60145d7f Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 14:14:28 +0300 Subject: [PATCH 26/85] zip update --- build/jenkins/zip | 47 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/build/jenkins/zip b/build/jenkins/zip index 2488631..4667025 100644 --- a/build/jenkins/zip +++ b/build/jenkins/zip @@ -134,21 +134,54 @@ pipeline { exit 0 ''' - // Extract the zip filename from the PowerShell output by looking for "ZIPFILENAME=" prefix - def outputLines = zipFilenameOutput.split('\n') + // Debug: Print raw PowerShell output to see what we're getting + echo "Raw PowerShell output: ${zipFilenameOutput}" + + // The output may have Windows line endings, split by any common line ending + def outputLines = zipFilenameOutput.split('(?:\\r\\n|\\n|\\r)') + echo "Found ${outputLines.size()} lines in output" + def zipFilename = null - for (line in outputLines) { - if (line.trim().startsWith("ZIPFILENAME=")) { - zipFilename = line.trim() - "ZIPFILENAME=" + // Debug: Print each line of output + for (int i = 0; i < outputLines.size(); i++) { + echo "Line ${i}: ${outputLines[i]}" + if (outputLines[i].trim().contains("ZIPFILENAME=")) { + zipFilename = outputLines[i].trim().substring(outputLines[i].trim().indexOf("ZIPFILENAME=") + 11) + echo "Found zip filename in line ${i}: ${zipFilename}" break } } if (zipFilename) { env.CREATED_ZIP_FILENAME = zipFilename.trim() - echo "Found zip filename: ${env.CREATED_ZIP_FILENAME}" + echo "Setting CREATED_ZIP_FILENAME to: ${env.CREATED_ZIP_FILENAME}" } else { - error "Failed to extract zip filename from PowerShell output. Check PowerShell script." + // If we can't find the ZIPFILENAME marker, try a fallback approach + // Look for the line containing "Using newest existing zip file:" or "Zip archive created successfully:" + for (int i = 0; i < outputLines.size(); i++) { + def line = outputLines[i].trim() + if (line.contains("Using newest existing zip file: '") && line.contains(".zip'")) { + def start = line.indexOf("'") + 1 + def end = line.lastIndexOf("'") + if (start > 0 && end > start) { + zipFilename = line.substring(start, end) + echo "Extracted zip filename from 'Using newest' line: ${zipFilename}" + break + } + } else if (line.contains("Zip archive created successfully: ") && line.contains(".zip")) { + def start = line.indexOf("Zip archive created successfully: ") + 30 + zipFilename = line.substring(start).trim() + echo "Extracted zip filename from 'created successfully' line: ${zipFilename}" + break + } + } + + if (zipFilename) { + env.CREATED_ZIP_FILENAME = zipFilename.trim() + echo "Setting CREATED_ZIP_FILENAME using fallback to: ${env.CREATED_ZIP_FILENAME}" + } else { + error "Failed to extract zip filename from PowerShell output after multiple attempts. Check PowerShell script." + } } } } From 08f93c775b31b2133b61ce45e6612711456ac2d1 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 14:16:49 +0300 Subject: [PATCH 27/85] zip update --- build/jenkins/zip | 63 +++++++++-------------------------------------- 1 file changed, 12 insertions(+), 51 deletions(-) diff --git a/build/jenkins/zip b/build/jenkins/zip index 4667025..acdad9d 100644 --- a/build/jenkins/zip +++ b/build/jenkins/zip @@ -37,7 +37,8 @@ pipeline { echo "Operating in directory: ${pwd()}" // Use a powershell step with improved error handling and robustness - def zipFilenameOutput = powershell returnStdout: true, script: ''' + // First, create a PowerShell script to find the zip file using standard output + powershell ''' $ErrorActionPreference = "Stop" # Stop the script on any error # Define key variables @@ -128,61 +129,21 @@ pipeline { exit 1 } - # This is the critical fix - we need to make sure this is the last thing output - # And ensure it's on its own line with no other text - Write-Host "ZIPFILENAME=$zipFilename" + # CRITICAL: Write the filename to a temporary file that we can read in Jenkins + $zipFilename | Out-File -FilePath "zipfilename.txt" -Encoding utf8 -NoNewline + Write-Host "Wrote zip filename to zipfilename.txt: $zipFilename" exit 0 ''' - // Debug: Print raw PowerShell output to see what we're getting - echo "Raw PowerShell output: ${zipFilenameOutput}" + // Now read the file directly using readFile step + def zipFilename = readFile(file: 'zipfilename.txt').trim() + echo "Read zip filename from file: ${zipFilename}" - // The output may have Windows line endings, split by any common line ending - def outputLines = zipFilenameOutput.split('(?:\\r\\n|\\n|\\r)') - echo "Found ${outputLines.size()} lines in output" + // Set the environment variable + env.CREATED_ZIP_FILENAME = zipFilename + echo "Set CREATED_ZIP_FILENAME to: ${env.CREATED_ZIP_FILENAME}" - def zipFilename = null - // Debug: Print each line of output - for (int i = 0; i < outputLines.size(); i++) { - echo "Line ${i}: ${outputLines[i]}" - if (outputLines[i].trim().contains("ZIPFILENAME=")) { - zipFilename = outputLines[i].trim().substring(outputLines[i].trim().indexOf("ZIPFILENAME=") + 11) - echo "Found zip filename in line ${i}: ${zipFilename}" - break - } - } - - if (zipFilename) { - env.CREATED_ZIP_FILENAME = zipFilename.trim() - echo "Setting CREATED_ZIP_FILENAME to: ${env.CREATED_ZIP_FILENAME}" - } else { - // If we can't find the ZIPFILENAME marker, try a fallback approach - // Look for the line containing "Using newest existing zip file:" or "Zip archive created successfully:" - for (int i = 0; i < outputLines.size(); i++) { - def line = outputLines[i].trim() - if (line.contains("Using newest existing zip file: '") && line.contains(".zip'")) { - def start = line.indexOf("'") + 1 - def end = line.lastIndexOf("'") - if (start > 0 && end > start) { - zipFilename = line.substring(start, end) - echo "Extracted zip filename from 'Using newest' line: ${zipFilename}" - break - } - } else if (line.contains("Zip archive created successfully: ") && line.contains(".zip")) { - def start = line.indexOf("Zip archive created successfully: ") + 30 - zipFilename = line.substring(start).trim() - echo "Extracted zip filename from 'created successfully' line: ${zipFilename}" - break - } - } - - if (zipFilename) { - env.CREATED_ZIP_FILENAME = zipFilename.trim() - echo "Setting CREATED_ZIP_FILENAME using fallback to: ${env.CREATED_ZIP_FILENAME}" - } else { - error "Failed to extract zip filename from PowerShell output after multiple attempts. Check PowerShell script." - } - } + // Nothing needed here since we now write the filename to a file and read it directly } } } From 71e8f088a06f3f9e2dc171f805029294cb2803cc Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 14:19:02 +0300 Subject: [PATCH 28/85] zip update --- build/jenkins/zip | 107 +++++++++++++--------------------------------- 1 file changed, 30 insertions(+), 77 deletions(-) diff --git a/build/jenkins/zip b/build/jenkins/zip index acdad9d..8d8a938 100644 --- a/build/jenkins/zip +++ b/build/jenkins/zip @@ -1,31 +1,15 @@ -// This pipeline job is triggered by the main AzaionSuite build pipeline. -// It operates directly within the main build job's artifact directory, -// zips the artifacts using PowerShell and 7-Zip, and then triggers the Google Drive upload pipeline. pipeline { - // Agent should be your Windows VM agent - // This job MUST run on the SAME agent as the main build job agent { label 'Win10-BuildMachine' } tools { - // Git tool might be needed if this Jenkinsfile is in SCM git 'Default' } 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 + SEVEN_ZIP_PATH = "C:/Program Files/7-Zip" PATH = "${SEVEN_ZIP_PATH};${env.PATH}" - - // Define the name of your existing Google Drive upload pipeline job GOOGLE_DRIVE_UPLOAD_JOB_NAME = 'GDrive Upload' - - // Define the source directory for artifacts from the main build job's workspace MAIN_BUILD_ARTIFACTS_DIR = 'C:/Jenkins/workspace/AzaionSuite/suite' - - // Define the name of the created zip file as an environment variable - CREATED_ZIP_FILENAME = '' } stages { @@ -36,12 +20,8 @@ pipeline { dir("${env.MAIN_BUILD_ARTIFACTS_DIR}") { echo "Operating in directory: ${pwd()}" - // Use a powershell step with improved error handling and robustness - // First, create a PowerShell script to find the zip file using standard output powershell ''' - $ErrorActionPreference = "Stop" # Stop the script on any error - - # Define key variables + $ErrorActionPreference = "Stop" $sevenZipExe = "$env:SEVEN_ZIP_PATH\\7z.exe" $defaultVersion = "1.0.0" $exePattern = "AzaionSuite*.exe" @@ -50,100 +30,73 @@ pipeline { Write-Host "Operating in directory: $(Get-Location)" - # Check if 7-Zip exists if (-not (Test-Path $sevenZipExe)) { Write-Error "7-Zip executable not found at $sevenZipExe" exit 1 } - # Check for existing zip files - $existingZips = Get-ChildItem -Path . -Filter $zipPattern | + $existingZips = Get-ChildItem -Path . -Filter $zipPattern | Sort-Object LastWriteTime -Descending - $zipFilename = "" if ($existingZips.Count -gt 0) { - # Found existing zip files, use the newest one $newestZip = $existingZips | Select-Object -First 1 $zipFilename = $newestZip.Name Write-Host "Using newest existing zip file: '$zipFilename'." } else { - # No existing zip files, proceed with creation Write-Host "No existing zip files found. Creating new zip file." - # Find all files matching the patterns $foundFiles = Get-ChildItem -Recurse -Path . -Include $exePattern, $binPattern | Select-Object -ExpandProperty FullName if ($foundFiles.Count -eq 0) { - Write-Error "No files matching patterns $exePattern or $binPattern found in $(Get-Location)." + Write-Error "No files found to zip." exit 1 } - Write-Host "Found $($foundFiles.Count) file(s) to archive." - - # Determine Base Filename for Zip (from .exe if present) - $zipBaseFilename = "AzaionSuite.$defaultVersion" # Default - $exeFile = Get-ChildItem -Recurse -Path . -Filter $exePattern | - Select-Object -First 1 - + $zipBaseFilename = "AzaionSuite.$defaultVersion" + $exeFile = Get-ChildItem -Recurse -Path . -Filter $exePattern | Select-Object -First 1 if ($exeFile) { $zipBaseFilename = $exeFile.BaseName - Write-Host "Using executable base filename: '$zipBaseFilename'" - } else { - Write-Host "No executable found. Using default: '$zipBaseFilename'" } - # Get timestamp for filename $timestamp = (Get-Date -Format "yyyyMMdd-HHmmss") $zipFilename = "$zipBaseFilename-$timestamp.zip" - Write-Host "Creating zip archive: $zipFilename" try { - # Build the 7z command arguments $sevenZipArgs = @("a", "-tzip", "$zipFilename") $foundFilesQuoted = $foundFiles | ForEach-Object { "`"$_`"" } $sevenZipArgs += $foundFilesQuoted - - # Execute the 7z command $process = Start-Process -FilePath $sevenZipExe -ArgumentList $sevenZipArgs -Wait -NoNewWindow -PassThru - $exitCode = $process.ExitCode - - if ($exitCode -ne 0) { - Write-Error "Error creating zip archive. 7z exit code: $exitCode" - exit $exitCode + if ($process.ExitCode -ne 0) { + Write-Error "7-Zip failed with code $($process.ExitCode)" + exit $process.ExitCode } - - Write-Host "Zip archive created successfully: $zipFilename" } catch { - Write-Error "Exception occurred during zip creation: $_" + Write-Error "Zip creation failed: $_" exit 1 } } - # Verify the zip file exists before returning if (-not (Test-Path $zipFilename)) { Write-Error "Expected zip file $zipFilename does not exist" exit 1 } - # CRITICAL: Write the filename to a temporary file that we can read in Jenkins - $zipFilename | Out-File -FilePath "zipfilename.txt" -Encoding utf8 -NoNewline - Write-Host "Wrote zip filename to zipfilename.txt: $zipFilename" + # Write zip filename WITHOUT BOM (ASCII encoding) + Set-Content -Path "zipfilename.txt" -Value $zipFilename -Encoding ASCII + Write-Host "Zip filename written to zipfilename.txt: $zipFilename" exit 0 ''' - // Now read the file directly using readFile step - def zipFilename = readFile(file: 'zipfilename.txt').trim() + // Read and clean the filename + def zipFilename = readFile('zipfilename.txt').trim() echo "Read zip filename from file: ${zipFilename}" - // Set the environment variable - env.CREATED_ZIP_FILENAME = zipFilename - echo "Set CREATED_ZIP_FILENAME to: ${env.CREATED_ZIP_FILENAME}" - - // Nothing needed here since we now write the filename to a file and read it directly + // Save to file for next stage + writeFile file: 'created_zip.txt', text: zipFilename } } } @@ -154,22 +107,19 @@ pipeline { script { echo "Starting 'Archive Created Zip' stage." dir("${env.MAIN_BUILD_ARTIFACTS_DIR}") { + def zipFilename = readFile('created_zip.txt').trim() echo "Operating in directory: ${pwd()}" - // Verify zip filename was set properly - if (!env.CREATED_ZIP_FILENAME?.trim()) { - error "CREATED_ZIP_FILENAME environment variable was not set properly." + if (!zipFilename) { + error "Zip filename not found or is empty." } - // Verify the file exists before attempting to archive - def fileExists = fileExists env.CREATED_ZIP_FILENAME - if (!fileExists) { - error "File ${env.CREATED_ZIP_FILENAME} does not exist at ${pwd()}." + if (!fileExists(zipFilename)) { + error "File ${zipFilename} does not exist." } - echo "Archiving zip file: ${env.CREATED_ZIP_FILENAME}" - archiveArtifacts artifacts: "${env.CREATED_ZIP_FILENAME}", fingerprint: true - echo "Archive step completed." + echo "Archiving zip file: ${zipFilename}" + archiveArtifacts artifacts: "${zipFilename}", fingerprint: true } } } @@ -184,7 +134,7 @@ pipeline { echo "Google Drive Upload pipeline triggered successfully." } catch (Exception e) { echo "Failed to trigger Google Drive Upload pipeline: ${e.message}" - error "Failed to trigger Google Drive Upload pipeline. See console log for details." + error "Trigger failed. See logs." } } } @@ -193,10 +143,13 @@ pipeline { post { success { - echo "Pipeline completed successfully. Created and archived zip: ${env.CREATED_ZIP_FILENAME}" + script { + def zipFilename = readFile("${env.MAIN_BUILD_ARTIFACTS_DIR}/created_zip.txt").trim() + echo "Pipeline completed successfully. Created and archived zip: ${zipFilename}" + } } failure { echo "Pipeline failed. See logs for details." } } -} \ No newline at end of file +} From 24324b5ffd9980c16956ce3827d7d6bdb94a2d68 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 14:21:29 +0300 Subject: [PATCH 29/85] zip update --- build/jenkins/zip | 113 ++++++++++++++++++---------------------------- 1 file changed, 44 insertions(+), 69 deletions(-) diff --git a/build/jenkins/zip b/build/jenkins/zip index 8d8a938..4abfc08 100644 --- a/build/jenkins/zip +++ b/build/jenkins/zip @@ -13,13 +13,11 @@ pipeline { } stages { - stage('Archive Build Artifacts (PowerShell/7-Zip)') { + stage('Detect or Create Zip') { steps { script { - echo "Starting 'Archive Build Artifacts (PowerShell/7-Zip)' stage." + echo "Starting 'Detect or Create Zip' stage." dir("${env.MAIN_BUILD_ARTIFACTS_DIR}") { - echo "Operating in directory: ${pwd()}" - powershell ''' $ErrorActionPreference = "Stop" $sevenZipExe = "$env:SEVEN_ZIP_PATH\\7z.exe" @@ -28,97 +26,80 @@ pipeline { $binPattern = "AzaionSuite*.bin" $zipPattern = "AzaionSuite*.zip" - Write-Host "Operating in directory: $(Get-Location)" - if (-not (Test-Path $sevenZipExe)) { - Write-Error "7-Zip executable not found at $sevenZipExe" + Write-Error "7-Zip not found at $sevenZipExe" exit 1 } - $existingZips = Get-ChildItem -Path . -Filter $zipPattern | - Sort-Object LastWriteTime -Descending + $existingZips = Get-ChildItem -Path . -Filter $zipPattern | Sort-Object LastWriteTime -Descending $zipFilename = "" if ($existingZips.Count -gt 0) { - $newestZip = $existingZips | Select-Object -First 1 - $zipFilename = $newestZip.Name - Write-Host "Using newest existing zip file: '$zipFilename'." + $zipFilename = $existingZips[0].Name + Write-Host "Using existing zip file: $zipFilename" + $wasCreated = $false } else { - Write-Host "No existing zip files found. Creating new zip file." + $exeFile = Get-ChildItem -Recurse -Filter $exePattern | Select-Object -First 1 + if (-not $exeFile) { + Write-Error "No EXE file found to create zip" + exit 1 + } - $foundFiles = Get-ChildItem -Recurse -Path . -Include $exePattern, $binPattern | - Select-Object -ExpandProperty FullName + $zipBaseFilename = $exeFile.BaseName + $timestamp = (Get-Date -Format "yyyyMMdd-HHmmss") + $zipFilename = "$zipBaseFilename-$timestamp.zip" - if ($foundFiles.Count -eq 0) { + $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 } - $zipBaseFilename = "AzaionSuite.$defaultVersion" - $exeFile = Get-ChildItem -Recurse -Path . -Filter $exePattern | Select-Object -First 1 - if ($exeFile) { - $zipBaseFilename = $exeFile.BaseName + $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 } - $timestamp = (Get-Date -Format "yyyyMMdd-HHmmss") - $zipFilename = "$zipBaseFilename-$timestamp.zip" - Write-Host "Creating zip archive: $zipFilename" - - try { - $sevenZipArgs = @("a", "-tzip", "$zipFilename") - $foundFilesQuoted = $foundFiles | ForEach-Object { "`"$_`"" } - $sevenZipArgs += $foundFilesQuoted - $process = Start-Process -FilePath $sevenZipExe -ArgumentList $sevenZipArgs -Wait -NoNewWindow -PassThru - if ($process.ExitCode -ne 0) { - Write-Error "7-Zip failed with code $($process.ExitCode)" - exit $process.ExitCode - } - } - catch { - Write-Error "Zip creation failed: $_" - exit 1 - } + $wasCreated = $true + Write-Host "Created new zip file: $zipFilename" } - if (-not (Test-Path $zipFilename)) { - Write-Error "Expected zip file $zipFilename does not exist" - exit 1 - } - - # Write zip filename WITHOUT BOM (ASCII encoding) + # Save outputs without BOM Set-Content -Path "zipfilename.txt" -Value $zipFilename -Encoding ASCII - Write-Host "Zip filename written to zipfilename.txt: $zipFilename" - exit 0 + Set-Content -Path "zip_created.txt" -Value $wasCreated -Encoding ASCII ''' - // Read and clean the filename def zipFilename = readFile('zipfilename.txt').trim() - echo "Read zip filename from file: ${zipFilename}" + def zipCreated = readFile('zip_created.txt').trim().toBoolean() - // Save to file for next stage + echo "Zip filename: ${zipFilename}" + echo "Was zip created this run? ${zipCreated}" + + // Save results for next stages writeFile file: 'created_zip.txt', text: zipFilename + writeFile file: 'zip_was_created.txt', text: zipCreated.toString() } } } } - stage('Archive Created Zip') { + stage('Archive Zip File (if new)') { + when { + expression { + def zipCreated = readFile("${env.MAIN_BUILD_ARTIFACTS_DIR}/zip_was_created.txt").trim().toBoolean() + return zipCreated + } + } steps { script { - echo "Starting 'Archive Created Zip' stage." + echo "Archiving newly created zip file..." dir("${env.MAIN_BUILD_ARTIFACTS_DIR}") { def zipFilename = readFile('created_zip.txt').trim() - echo "Operating in directory: ${pwd()}" - - if (!zipFilename) { - error "Zip filename not found or is empty." - } - if (!fileExists(zipFilename)) { - error "File ${zipFilename} does not exist." + error "Zip file '${zipFilename}' not found!" } - - echo "Archiving zip file: ${zipFilename}" archiveArtifacts artifacts: "${zipFilename}", fingerprint: true } } @@ -129,13 +110,7 @@ pipeline { steps { script { echo "Triggering Google Drive Upload pipeline: ${env.GOOGLE_DRIVE_UPLOAD_JOB_NAME}" - try { - build job: env.GOOGLE_DRIVE_UPLOAD_JOB_NAME - echo "Google Drive Upload pipeline triggered successfully." - } catch (Exception e) { - echo "Failed to trigger Google Drive Upload pipeline: ${e.message}" - error "Trigger failed. See logs." - } + build job: env.GOOGLE_DRIVE_UPLOAD_JOB_NAME } } } @@ -145,11 +120,11 @@ pipeline { success { script { def zipFilename = readFile("${env.MAIN_BUILD_ARTIFACTS_DIR}/created_zip.txt").trim() - echo "Pipeline completed successfully. Created and archived zip: ${zipFilename}" + echo "Pipeline completed successfully. Final zip: ${zipFilename}" } } failure { - echo "Pipeline failed. See logs for details." + echo "Pipeline failed." } } } From 0c0cc1bb839da7d1db16c195b7725b03c6e1a3ac Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 14:25:28 +0300 Subject: [PATCH 30/85] gdrive update --- build/jenkins/GDriveUpload | 314 +++++++------------------------------ 1 file changed, 53 insertions(+), 261 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index 8ad4a11..b72410c 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -1,283 +1,75 @@ -// Jenkins Pipeline script to find the latest zip file directly in the artifacts directory -// and upload it to Google Drive with retention. -// Retention is based on the timestamp embedded in the filename and performed entirely in PowerShell. -// Designed to run on a Windows agent, specifically on the machine where the main build creates artifacts. -// Assumes rclone is installed and its directory is added to the system's PATH on the Windows agent. - pipeline { - // Agent should be the SAME Windows VM agent where the main build job runs - // and creates the artifacts in the MAIN_BUILD_ARTIFACTS_DIR. - agent { label 'Win10-BuildMachine' } // Replace with your Windows agent label if different - - environment { - // Google Drive settings - GDRIVE_REMOTE = 'AzaionGoogleDrive:AzaionSuiteBuilds' // Your rclone remote name and path - // Use a relative path within the workspace for the temporary directory on Windows - // This temporary directory is still useful for rclone's internal operations and cleanup - TMP_UPLOAD_DIR = 'temp_upload' - // Path to rclone.conf on the Windows agent. - // Adjust this path if your rclone.conf is located elsewhere on the Windows VM. - // Using a relative path from the workspace root is often best practice. - RCLONE_CONFIG = 'rclone.conf' // Assuming rclone.conf is in the workspace root - - // Number of latest files to keep on Google Drive - FILES_TO_KEEP = 3 - - // Define the FULL path to the directory containing the zip files. - // This job will operate directly within this directory. - // ** IMPORTANT: Replace 'C:/Jenkins/workspace/AzaionSuite/suite' with the actual path ** - TARGET_ARTIFACTS_DIR = 'C:/Jenkins/workspace/AzaionSuite/suite' // <<== UPDATE THIS - - // Define the name of the latest zip file found as an environment variable - // This makes it easier to reference in later stages - LATEST_ZIP_FILENAME = '' // This will be set dynamically in the 'Find Latest Zip and Upload' stage - } + agent { label 'windows' } stages { stage('Initialize Workspace') { steps { - echo "Initializing workspace on Windows agent..." - // Use standard Windows PowerShell for directory creation and cleanup - // Ensure paths are quoted for safety and use backslashes for Windows paths - powershell """ - # Create temporary upload directory within THIS job's workspace - New-Item -ItemType Directory -Force -Path "${env:WORKSPACE}\\\\${env:TMP_UPLOAD_DIR}" - - # Clean up previous temporary files in the upload directory - Remove-Item -Recurse -Force "${env:WORKSPACE}\\\\${env:TMP_UPLOAD_DIR}\\\\*" -ErrorAction SilentlyContinue - """ + echo 'Initializing workspace on Windows agent...' + powershell ''' + $uploadDir = "temp_upload" + if (-Not (Test-Path $uploadDir)) { + New-Item -ItemType Directory -Path $uploadDir | Out-Null + } + ''' } } - stage('Find Latest Zip and Upload') { // Renamed stage + stage('Find Latest Zip and Upload') { steps { - script { // Wrap steps in a script block + script { echo "Starting 'Find Latest Zip and Upload' stage." - - // Change directory to the target artifacts folder where the zip files are located - dir("${env.TARGET_ARTIFACTS_DIR}") { - echo "Operating in directory: ${pwd()}" - - // Use PowerShell to find the latest zip file based on filename timestamp - // This logic is similar to the 'Archive Latest Zip' stage from the combined pipeline - def powershellOutput = powershell(script: """ - \$zipPattern = "AzaionSuite*-*-*.zip" # Pattern for zip files - Write-Host "Searching for latest zip file matching '\$zipPattern' in '\$PWD'..." - - # Find all zip files matching the pattern - # Use -ErrorAction Stop to fail if Get-ChildItem fails - \$zipFiles = Get-ChildItem -Path . -Filter \$zipPattern -ErrorAction Stop - - if (\$zipFiles.Count -eq 0) { - Write-Host "No zip files matching pattern '\$zipPattern' found in '\$PWD'." - # Exit PowerShell script with a non-zero code to fail the step + dir("C:/Jenkins/workspace/AzaionSuite/suite") { + def output = powershell(returnStdout: true, script: ''' + $pattern = "AzaionSuite*-*-*.zip" + $zipFiles = Get-ChildItem -Filter $pattern | Sort-Object Name -Descending + if ($zipFiles.Count -eq 0) { + Write-Error "No ZIP files matching pattern '$pattern' were found." exit 1 } + $latestZip = $zipFiles[0].Name + Write-Output "::SET-ENV::LATEST_ZIP_FILENAME=$latestZip" + ''').trim() - Write-Host "Found \$(\$zipFiles.Count) zip file(s)." - - # --- Sorting of ZIP Files by Filename Timestamp (in PowerShell) --- - Write-Host "Sorting ZIP files by filename timestamp (YYYYMMDD-HHMMSS)..." - - # Regex to extract the timestamp from the filename - \$timestampRegex = '.*-(\\d{8}-\\d{6})\\.zip' - - # Sort the files by extracting the timestamp and converting to DateTime for accurate sorting - # Sort-Object -Descending ensures newest are first - \$sortedZipFiles = \$zipFiles | Sort-Object -Descending { - \$name = \$_.Name - \$match = [regex]::Match(\$name, \$timestampRegex) - if (\$match.Success -and \$match.Groups.Count -gt 1) { - \$timestampStr = \$match.Groups[1].Value - # Attempt to parse the timestamp string into a DateTime object - try { - [DateTime]::ParseExact(\$timestampStr, "yyyyMMdd-HHmmss", \$null) - } catch { - Write-Host "Warning: Could not parse timestamp from filename '\$name': \$(\$_.Exception.Message)" - # Handle parsing errors - treat as the oldest possible date (e.g., 1/1/0001) - # This ensures unparseable dates are placed at the end (oldest) - [DateTime]::MinValue - } - } else { - Write-Host "Warning: Filename '\$name' does not match timestamp regex." - # Handle non-matching filenames - treat as the oldest possible date - [DateTime]::MinValue - # Exit the script here if you want to fail the stage on unparseable filenames - # exit 1 - } - } - # --- End Sorting --- - - # Get the name of the latest zip file (the first one after sorting descending) - \$latestZipFile = \$sortedZipFiles | Select-Object -First 1 - - Write-Host "Identified latest zip file: '\$latestZipFile.Name'" - - # Output the latest zip filename and set it as an environment variable for Jenkins - # This uses the Jenkins 'set context' feature - Write-Host "::SET-ENV::LATEST_ZIP_FILENAME=\$(\$latestZipFile.Name)" - - exit 0 # Exit PowerShell script successfully - - """ , returnStdout: true - ) // End powershell call - - // Parse the PowerShell output to find the latest zip filename and set the Groovy environment variable - def matcher = powershellOutput =~ /::SET-ENV::LATEST_ZIP_FILENAME=(.+)/ - def latestZipFilename = null - if (matcher.find()) { - latestZipFilename = matcher.group(1).trim() - env.LATEST_ZIP_FILENAME = latestZipFilename // Set the environment variable - echo "Groovy set LATEST_ZIP_FILENAME to: ${env.LATEST_ZIP_FILENAME}" - } else { - error "Could not find the latest zip filename in the PowerShell output using marker." + def match = output =~ /::SET-ENV::LATEST_ZIP_FILENAME=(.+)/ + if (!match) { + error("Could not find the latest zip filename in the PowerShell output using marker.") } + def zipFileName = match[0][1] + echo "Latest zip file selected: ${zipFileName}" - // Ensure the latest zip filename environment variable is set before attempting upload - if (env.LATEST_ZIP_FILENAME && env.LATEST_ZIP_FILENAME != '') { - echo "Identified latest zip file for upload: ${env.LATEST_ZIP_FILENAME}" - - try { - // --- Upload the latest ZIP archive directly from the current directory --- - echo "Starting upload of '${env.LATEST_ZIP_FILENAME}' directly from '${pwd()}' to ${GDRIVE_REMOTE}..." - // Use standard Windows PowerShell to execute rclone (now in PATH) - // Ensure config path and remote path are quoted, and use backslashes for Windows paths - // The source path for rclone is the filename relative to the current directory (TARGET_ARTIFACTS_DIR) - powershell """ - rclone --config "${env:WORKSPACE}\\\\${env:RCLONE_CONFIG}" copy \"${env:LATEST_ZIP_FILENAME}\" \"${env:GDRIVE_REMOTE}\" - """ - echo "Finished uploading ${env.LATEST_ZIP_FILENAME}." - - } catch (e) { - echo "ERROR uploading build: ${e}" - error("Failed to upload latest zip file: ${e.message}") // Fail the stage on error - } - // No cleanup needed in finally block here as the file is not copied to a temp location first - } else { - error "LATEST_ZIP_FILENAME environment variable was not set or was empty. Cannot upload." - } - } // End dir block - } // end script - } // end steps - } // end stage + // Pass the variable into the environment for the next steps if needed + env.LATEST_ZIP_FILENAME = zipFileName + } + } + } + } stage('Retention on Google Drive') { - steps { - script { // Wrap script logic in a script block - echo "Starting Google Drive retention process (using PowerShell)..." - // Ensure rclone is installed and in PATH on the Windows agent, - // and the Jenkins agent user has read access to '${env:WORKSPACE}\\\\${env.RCLONE_CONFIG}'. - - // PowerShell script block for retention logic - powershell """ - \$rcloneRemote = "${env:GDRIVE_REMOTE}" - \$rcloneConfig = "${env:WORKSPACE}\\\\${env:RCLONE_CONFIG}" - \$filesToKeep = ${env.FILES_TO_KEEP} - - # Get list of files from Google Drive as JSON - \$rcloneListOutput = rclone --config "\$rcloneConfig" lsjson "\$rcloneRemote" | Out-String - - # Parse JSON output - # ConvertFrom-Json will throw an error if the input is not valid JSON, - # which will cause the PowerShell step and the stage to fail. - \$allFilesJson = \$rcloneListOutput | ConvertFrom-Json - - # Filter for zip files - \$zipFiles = \$allFilesJson | Where-Object { \$_.Name -ne \$null -and \$_.Name.EndsWith(".zip") } - - Write-Host "Found \$(\$zipFiles.Count) total ZIP files on Google Drive." - - # --- Sorting of ZIP Files by Filename Timestamp (in PowerShell) --- - Write-Host "Sorting ZIP files on Google Drive by filename timestamp (YYYYMMDD-HHMMSS)..." - - # Regex to extract the timestamp from the filename - \$timestampRegex = '.*-(\\d{8}-\\d{6})\\.zip' - - # Sort the files by extracting the timestamp and converting to DateTime for accurate sorting - # Sort-Object -Descending ensures newest are first - \$sortedZipFiles = \$zipFiles | Sort-Object -Descending { - \$name = \$_.Name - \$match = [regex]::Match(\$name, \$timestampRegex) - if (\$match.Success -and \$match.Groups.Count -gt 1) { - \$timestampStr = \$match.Groups[1].Value - # Attempt to parse the timestamp string into a DateTime object - try { - [DateTime]::ParseExact(\$timestampStr, "yyyyMMdd-HHmmss", \$null) - } catch { - Write-Host "Warning: Could not parse timestamp from filename '\$name': \$(\$_.Exception.Message)" - # Handle parsing errors - treat as the oldest possible date (e.g., 1/1/0001) - # This ensures unparseable dates are placed at the end (oldest) - [DateTime]::MinValue - } - } else { - Write-Host "Warning: Filename '\$name' does not match timestamp regex." - # Handle non-matching filenames - treat as the oldest possible date - [DateTime]::MinValue - # Exit the script here if you want to fail the stage on unparseable filenames - # exit 1 - } - } - # --- End Sorting --- - - # DEBUG: Print the sorted list by filename timestamp with each file on a new line - Write-Host "DEBUG: ZIP files on Google Drive sorted by filename timestamp (newest first):" - \$sortedZipFiles | ForEach-Object { Write-Host \$_.Name } - - - # Keep the latest N files, identify the rest for deletion - if (\$sortedZipFiles.Count -gt \$filesToKeep) { - # Select the files to delete (from index FILES_TO_KEEP to the end) - \$filesToDelete = \$sortedZipFiles | Select-Object -Skip \$filesToKeep - - Write-Host "Applying retention: Keeping \$filesToKeep newest files, deleting \$(\$filesToDelete.Count) older files." - # DEBUG: Print the list of files identified for deletion - Write-Host "DEBUG: Files identified for deletion:" - \$filesToDelete | ForEach-Object { Write-Host \$_.Name } - - - # Loop through files to delete and execute rclone delete - foreach (\$oldZipInfo in \$filesToDelete) { - \$oldZipName = \$oldZipInfo.Name - Write-Host "Deleting old ZIP from Google Drive: \$oldZipName" - # Ensure filenames are quoted for safety, especially if they contain spaces - # Use errorHanding: 'ignore' if you want to continue even if a delete fails - rclone --config "\$rcloneConfig" delete "\$rcloneRemote/\$oldZipName" --drive-use-trash=false - } - } else { - Write-Host "Retention check: Found \$(\$sortedZipFiles.Count) ZIP files, which is not more than \$filesToKeep. No files deleted." - } - """ // End PowerShell script block - } // end script - } // end steps - } // end stage - - } // End of main 'stages' block + steps { + echo "Uploading ${env.LATEST_ZIP_FILENAME} to Google Drive..." + // Example command (replace with actual upload command) + powershell """ + \$filePath = "C:/Jenkins/workspace/AzaionSuite/suite/${env.LATEST_ZIP_FILENAME}" + Write-Output "Would upload: \$filePath" + # Add your actual GDrive upload logic here + """ + } + } + } post { always { - script { // Wrap steps in a script block - echo "Executing post-build cleanup..." - // Use standard Windows PowerShell Remove-Item for cleanup - // Quote TMP_UPLOAD_DIR path for safety and use backslashes for Windows paths - powershell """ - echo 'Cleaning up temporary upload directory: ${env:WORKSPACE}\\\\${env:TMP_UPLOAD_DIR}' - Remove-Item -Recurse -Force "${env:WORKSPACE}\\\\${env:TMP_UPLOAD_DIR}" -ErrorAction SilentlyContinue - """ - // Removed cleanup for copied artifacts directory as files are cleaned up individually now. - } // end script + echo 'Executing post-build cleanup...' + powershell ''' + $uploadDir = "temp_upload" + if (Test-Path $uploadDir) { + Remove-Item -Recurse -Force $uploadDir + } + ''' } - success { - script { // Wrap steps in a script block - echo "Pipeline finished successfully." - // Add any success-specific notifications or actions here - } // end script - } - failure { - script { // Wrap steps in a script block - echo "Pipeline failed. Check logs for details." - // Add any failure-specific notifications or actions here - } // end script - } - } // End of 'post' block -} // End of 'pipeline' block + failure { + echo 'Pipeline failed. Check logs for details.' + } + } +} From f0f6e05b0d3c88bd499041cc3621c472b8935ab9 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 14:34:33 +0300 Subject: [PATCH 31/85] gdrive update --- build/jenkins/GDriveUpload | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index b72410c..9c3fe2d 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -1,5 +1,13 @@ pipeline { - agent { label 'windows' } + agent { label 'Win10-BuildMachine' } + + tools { + git 'Default' + } + + environment { + GOOGLE_DRIVE_UPLOAD_JOB_NAME = 'YourGoogleDriveUploadPipelineName' // <<== Update this + } stages { stage('Initialize Workspace') { @@ -44,14 +52,15 @@ pipeline { } } - stage('Retention on Google Drive') { + stage('Upload to Google Drive using rclone') { steps { echo "Uploading ${env.LATEST_ZIP_FILENAME} to Google Drive..." - // Example command (replace with actual upload command) powershell """ \$filePath = "C:/Jenkins/workspace/AzaionSuite/suite/${env.LATEST_ZIP_FILENAME}" - Write-Output "Would upload: \$filePath" - # Add your actual GDrive upload logic here + Write-Output "Preparing to upload: \$filePath" + + # Use rclone to upload the file to Google Drive + rclone copy "\$filePath" remote:YourFolderNameOnGDrive --progress --drive-chunk-size 64M """ } } From 44bef40d9be951c688deeddfe32b56949556e6e2 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 14:39:47 +0300 Subject: [PATCH 32/85] gdrive update --- build/jenkins/GDriveUpload | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index 9c3fe2d..72e06cf 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -6,7 +6,9 @@ pipeline { } environment { - GOOGLE_DRIVE_UPLOAD_JOB_NAME = 'YourGoogleDriveUploadPipelineName' // <<== Update this + GOOGLE_DRIVE_UPLOAD_JOB_NAME = 'AzaionBuilds' // <<== Update this + RCLONE_CONFIG = 'C:/Program Files/rclone/rclone.conf' // <<== Ensure this points to the correct location of your rclone.conf + } stages { From 8574e10b52b87031177058bd67710ed148a8c599 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 14:41:37 +0300 Subject: [PATCH 33/85] gdrive update --- build/jenkins/GDriveUpload | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index 72e06cf..de93c41 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -7,8 +7,7 @@ pipeline { environment { GOOGLE_DRIVE_UPLOAD_JOB_NAME = 'AzaionBuilds' // <<== Update this - RCLONE_CONFIG = 'C:/Program Files/rclone/rclone.conf' // <<== Ensure this points to the correct location of your rclone.conf - + RCLONE_CONFIG = 'C:/Program Files/rclone/rclone.conf' // Ensure this points to the correct location } stages { @@ -61,6 +60,9 @@ pipeline { \$filePath = "C:/Jenkins/workspace/AzaionSuite/suite/${env.LATEST_ZIP_FILENAME}" Write-Output "Preparing to upload: \$filePath" + # Ensure rclone uses the correct config file path + \$env:RCLONE_CONFIG = 'C:/Program Files/rclone/rclone.conf' # Explicitly set environment variable for this step + # Use rclone to upload the file to Google Drive rclone copy "\$filePath" remote:YourFolderNameOnGDrive --progress --drive-chunk-size 64M """ From 41c2ed37c1e3c29c5c903be26ae1010ac3be35a6 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 14:43:16 +0300 Subject: [PATCH 34/85] gdrive update --- build/jenkins/GDriveUpload | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index de93c41..1d9bcae 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -60,8 +60,11 @@ pipeline { \$filePath = "C:/Jenkins/workspace/AzaionSuite/suite/${env.LATEST_ZIP_FILENAME}" Write-Output "Preparing to upload: \$filePath" - # Ensure rclone uses the correct config file path - \$env:RCLONE_CONFIG = 'C:/Program Files/rclone/rclone.conf' # Explicitly set environment variable for this step + # Display the contents of the rclone configuration file to ensure it's being read correctly + Get-Content 'C:/Program Files/rclone/rclone.conf' + + # Explicitly set the rclone config path + \$env:RCLONE_CONFIG = 'C:/Program Files/rclone/rclone.conf' # Use rclone to upload the file to Google Drive rclone copy "\$filePath" remote:YourFolderNameOnGDrive --progress --drive-chunk-size 64M From 514c275f3a158e2d9659f742a87688d507468c8e Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 14:44:44 +0300 Subject: [PATCH 35/85] gdrive update --- build/jenkins/GDriveUpload | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index 1d9bcae..b27a105 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -6,7 +6,7 @@ pipeline { } environment { - GOOGLE_DRIVE_UPLOAD_JOB_NAME = 'AzaionBuilds' // <<== Update this + GOOGLE_DRIVE_UPLOAD_JOB_NAME = 'AzaionSuiteBuilds' // <<== Update this RCLONE_CONFIG = 'C:/Program Files/rclone/rclone.conf' // Ensure this points to the correct location } @@ -67,7 +67,7 @@ pipeline { \$env:RCLONE_CONFIG = 'C:/Program Files/rclone/rclone.conf' # Use rclone to upload the file to Google Drive - rclone copy "\$filePath" remote:YourFolderNameOnGDrive --progress --drive-chunk-size 64M + rclone copy "\$filePath" AzaionGoogleDrive:YourFolderNameOnGDrive --progress --drive-chunk-size 64M """ } } From 5d0e49b6fd52bcd4325c8ba455104a0ea3706748 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 14:54:08 +0300 Subject: [PATCH 36/85] gdrive update --- build/jenkins/GDriveUpload | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index b27a105..8cd44f6 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -5,8 +5,11 @@ pipeline { git 'Default' } + parameters { + string(name: 'GOOGLE_DRIVE_FOLDER', defaultValue: 'AzaionSuiteBuilds', description: 'The folder on Google Drive where the build will be uploaded.') + } + environment { - GOOGLE_DRIVE_UPLOAD_JOB_NAME = 'AzaionSuiteBuilds' // <<== Update this RCLONE_CONFIG = 'C:/Program Files/rclone/rclone.conf' // Ensure this points to the correct location } @@ -67,7 +70,7 @@ pipeline { \$env:RCLONE_CONFIG = 'C:/Program Files/rclone/rclone.conf' # Use rclone to upload the file to Google Drive - rclone copy "\$filePath" AzaionGoogleDrive:YourFolderNameOnGDrive --progress --drive-chunk-size 64M + rclone copy "\$filePath" AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --progress --drive-chunk-size 64M """ } } From efde78ad931f6727dadb0c929fbc843f055e5443 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 14:58:19 +0300 Subject: [PATCH 37/85] gdrive update --- build/jenkins/GDriveUpload | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index 8cd44f6..dff3731 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -74,6 +74,27 @@ pipeline { """ } } + + stage('Cleanup Older Files on Google Drive') { + steps { + echo "Cleaning up older files on Google Drive..." + powershell """ + # Get the list of files in the Google Drive folder + \$files = rclone lsf --files-only --dirs-only --max-depth 1 AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --format "tp" | Sort-Object -Descending + + # Keep only the 3 latest files + \$filesToDelete = \$files | Select-Object -Skip 3 + + # If there are files to delete, remove them + if (\$filesToDelete.Count -gt 0) { + Write-Output "Deleting files: \$filesToDelete" + rclone delete AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --files-from <(echo \$filesToDelete) --drive-chunk-size 64M + } else { + Write-Output "No files to delete." + } + """ + } + } } post { From 78caeac943fc7b87e30a31f93d5a33deecb47e86 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 14:59:16 +0300 Subject: [PATCH 38/85] gdrive update --- build/jenkins/GDriveUpload | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index dff3731..cbc5e48 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -88,7 +88,16 @@ pipeline { # If there are files to delete, remove them if (\$filesToDelete.Count -gt 0) { Write-Output "Deleting files: \$filesToDelete" - rclone delete AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --files-from <(echo \$filesToDelete) --drive-chunk-size 64M + + # Create a temporary file to store the list of files to delete + \$tempFile = [System.IO.Path]::GetTempFileName() + \$filesToDelete | Out-File -FilePath \$tempFile -Encoding utf8 + + # Use rclone to delete the files + rclone delete AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --files-from \$tempFile --drive-chunk-size 64M + + # Clean up the temporary file + Remove-Item -Path \$tempFile } else { Write-Output "No files to delete." } From f42646bc72f52222b0efaf1a94501d4636b350b9 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 15:00:58 +0300 Subject: [PATCH 39/85] gdrive update --- build/jenkins/GDriveUpload | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index cbc5e48..1d2a1a3 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -79,11 +79,20 @@ pipeline { steps { echo "Cleaning up older files on Google Drive..." powershell """ - # Get the list of files in the Google Drive folder - \$files = rclone lsf --files-only --dirs-only --max-depth 1 AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --format "tp" | Sort-Object -Descending + # List all files in the Google Drive folder + Write-Output "Listing all files in the folder ${params.GOOGLE_DRIVE_FOLDER} on Google Drive..." + \$files = rclone lsf --files-only --dirs-only --max-depth 1 AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --format "tp" + Write-Output "Files found on Google Drive:" + Write-Output \$files + + # Sort the files by date in descending order + \$filesSorted = \$files | Sort-Object -Descending # Keep only the 3 latest files - \$filesToDelete = \$files | Select-Object -Skip 3 + \$filesToDelete = \$filesSorted | Select-Object -Skip 3 + + # Display the files to delete + Write-Output "Files to delete: \$filesToDelete" # If there are files to delete, remove them if (\$filesToDelete.Count -gt 0) { From 7343e9d630f69ecd2c92e3829fa08f412931e743 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 15:02:27 +0300 Subject: [PATCH 40/85] gdrive update --- build/jenkins/GDriveUpload | 41 +++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index 1d2a1a3..449261c 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -81,34 +81,39 @@ pipeline { powershell """ # List all files in the Google Drive folder Write-Output "Listing all files in the folder ${params.GOOGLE_DRIVE_FOLDER} on Google Drive..." - \$files = rclone lsf --files-only --dirs-only --max-depth 1 AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --format "tp" + \$files = rclone lsf --files-only AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --format "tp" --max-depth 1 Write-Output "Files found on Google Drive:" Write-Output \$files - # Sort the files by date in descending order - \$filesSorted = \$files | Sort-Object -Descending + # If files were found + if (\$files.Count -gt 0) { + # Sort the files by date in descending order + \$filesSorted = \$files | Sort-Object -Descending - # Keep only the 3 latest files - \$filesToDelete = \$filesSorted | Select-Object -Skip 3 + # Keep only the 3 latest files + \$filesToDelete = \$filesSorted | Select-Object -Skip 3 - # Display the files to delete - Write-Output "Files to delete: \$filesToDelete" + Write-Output "Files to delete (older than 3 latest):" + Write-Output \$filesToDelete - # If there are files to delete, remove them - if (\$filesToDelete.Count -gt 0) { - Write-Output "Deleting files: \$filesToDelete" + # If there are files to delete, remove them + if (\$filesToDelete.Count -gt 0) { + Write-Output "Deleting files: \$filesToDelete" - # Create a temporary file to store the list of files to delete - \$tempFile = [System.IO.Path]::GetTempFileName() - \$filesToDelete | Out-File -FilePath \$tempFile -Encoding utf8 + # Create a temporary file to store the list of files to delete + \$tempFile = [System.IO.Path]::GetTempFileName() + \$filesToDelete | Out-File -FilePath \$tempFile -Encoding utf8 - # Use rclone to delete the files - rclone delete AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --files-from \$tempFile --drive-chunk-size 64M + # Use rclone to delete the files + rclone delete AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --files-from \$tempFile --drive-chunk-size 64M - # Clean up the temporary file - Remove-Item -Path \$tempFile + # Clean up the temporary file + Remove-Item -Path \$tempFile + } else { + Write-Output "No files to delete." + } } else { - Write-Output "No files to delete." + Write-Output "No files found on Google Drive to clean up." } """ } From 7985c298a6b4db0247924e1dd9cef324b4bd6568 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 15:04:04 +0300 Subject: [PATCH 41/85] gdrive update --- build/jenkins/GDriveUpload | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index 449261c..d5af3c7 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -100,9 +100,12 @@ pipeline { if (\$filesToDelete.Count -gt 0) { Write-Output "Deleting files: \$filesToDelete" + # Extract file names (without timestamps) + \$fileNamesToDelete = \$filesToDelete -replace '^\S+ ', '' + # Create a temporary file to store the list of files to delete \$tempFile = [System.IO.Path]::GetTempFileName() - \$filesToDelete | Out-File -FilePath \$tempFile -Encoding utf8 + \$fileNamesToDelete | Out-File -FilePath \$tempFile -Encoding utf8 # Use rclone to delete the files rclone delete AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --files-from \$tempFile --drive-chunk-size 64M From c83ed5367281e7091e3d9645db2d1a55a3fc9d8b Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 15:06:53 +0300 Subject: [PATCH 42/85] gdrive update1 --- build/jenkins/GDriveUpload | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index d5af3c7..0e316b4 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -78,47 +78,47 @@ pipeline { stage('Cleanup Older Files on Google Drive') { steps { echo "Cleaning up older files on Google Drive..." - powershell """ + powershell ''' # List all files in the Google Drive folder Write-Output "Listing all files in the folder ${params.GOOGLE_DRIVE_FOLDER} on Google Drive..." - \$files = rclone lsf --files-only AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --format "tp" --max-depth 1 + $files = rclone lsf --files-only AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --format "tp" --max-depth 1 Write-Output "Files found on Google Drive:" - Write-Output \$files + Write-Output $files # If files were found - if (\$files.Count -gt 0) { + if ($files.Count -gt 0) { # Sort the files by date in descending order - \$filesSorted = \$files | Sort-Object -Descending + $filesSorted = $files | Sort-Object -Descending # Keep only the 3 latest files - \$filesToDelete = \$filesSorted | Select-Object -Skip 3 + $filesToDelete = $filesSorted | Select-Object -Skip 3 Write-Output "Files to delete (older than 3 latest):" - Write-Output \$filesToDelete + Write-Output $filesToDelete # If there are files to delete, remove them - if (\$filesToDelete.Count -gt 0) { - Write-Output "Deleting files: \$filesToDelete" + if ($filesToDelete.Count -gt 0) { + Write-Output "Deleting files: $filesToDelete" # Extract file names (without timestamps) - \$fileNamesToDelete = \$filesToDelete -replace '^\S+ ', '' + $fileNamesToDelete = $filesToDelete -replace '^\S+ ', '' # Create a temporary file to store the list of files to delete - \$tempFile = [System.IO.Path]::GetTempFileName() - \$fileNamesToDelete | Out-File -FilePath \$tempFile -Encoding utf8 + $tempFile = [System.IO.Path]::GetTempFileName() + $fileNamesToDelete | Out-File -FilePath $tempFile -Encoding utf8 # Use rclone to delete the files - rclone delete AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --files-from \$tempFile --drive-chunk-size 64M + rclone delete AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --files-from $tempFile --drive-chunk-size 64M # Clean up the temporary file - Remove-Item -Path \$tempFile + Remove-Item -Path $tempFile } else { Write-Output "No files to delete." } } else { Write-Output "No files found on Google Drive to clean up." } - """ + ''' } } } From ccc598d746fd06f684b15d588a5a13698ffbfe1c Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 15:09:01 +0300 Subject: [PATCH 43/85] gdrive update1 --- build/jenkins/GDriveUpload | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index 0e316b4..99c65cd 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -77,8 +77,9 @@ pipeline { stage('Cleanup Older Files on Google Drive') { steps { - echo "Cleaning up older files on Google Drive..." - powershell ''' + script { + // Writing PowerShell cleanup script to a temporary file + def cleanupScript = ''' # List all files in the Google Drive folder Write-Output "Listing all files in the folder ${params.GOOGLE_DRIVE_FOLDER} on Google Drive..." $files = rclone lsf --files-only AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --format "tp" --max-depth 1 @@ -118,7 +119,18 @@ pipeline { } else { Write-Output "No files found on Google Drive to clean up." } - ''' + ''' + + // Write the PowerShell cleanup script to a temporary file + def tempScriptFile = "cleanup_script.ps1" + writeFile file: tempScriptFile, text: cleanupScript + + // Run the PowerShell script + powershell script: tempScriptFile + + // Clean up the temporary PowerShell script file + deleteFile tempScriptFile + } } } } From a1f46799c79527dcf44bf6ac15a8e0426e3e3005 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 15:11:06 +0300 Subject: [PATCH 44/85] gdrive update1 --- build/jenkins/GDriveUpload | 45 +++++++++++++------------------------- 1 file changed, 15 insertions(+), 30 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index 99c65cd..449261c 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -77,60 +77,45 @@ pipeline { stage('Cleanup Older Files on Google Drive') { steps { - script { - // Writing PowerShell cleanup script to a temporary file - def cleanupScript = ''' + echo "Cleaning up older files on Google Drive..." + powershell """ # List all files in the Google Drive folder Write-Output "Listing all files in the folder ${params.GOOGLE_DRIVE_FOLDER} on Google Drive..." - $files = rclone lsf --files-only AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --format "tp" --max-depth 1 + \$files = rclone lsf --files-only AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --format "tp" --max-depth 1 Write-Output "Files found on Google Drive:" - Write-Output $files + Write-Output \$files # If files were found - if ($files.Count -gt 0) { + if (\$files.Count -gt 0) { # Sort the files by date in descending order - $filesSorted = $files | Sort-Object -Descending + \$filesSorted = \$files | Sort-Object -Descending # Keep only the 3 latest files - $filesToDelete = $filesSorted | Select-Object -Skip 3 + \$filesToDelete = \$filesSorted | Select-Object -Skip 3 Write-Output "Files to delete (older than 3 latest):" - Write-Output $filesToDelete + Write-Output \$filesToDelete # If there are files to delete, remove them - if ($filesToDelete.Count -gt 0) { - Write-Output "Deleting files: $filesToDelete" - - # Extract file names (without timestamps) - $fileNamesToDelete = $filesToDelete -replace '^\S+ ', '' + if (\$filesToDelete.Count -gt 0) { + Write-Output "Deleting files: \$filesToDelete" # Create a temporary file to store the list of files to delete - $tempFile = [System.IO.Path]::GetTempFileName() - $fileNamesToDelete | Out-File -FilePath $tempFile -Encoding utf8 + \$tempFile = [System.IO.Path]::GetTempFileName() + \$filesToDelete | Out-File -FilePath \$tempFile -Encoding utf8 # Use rclone to delete the files - rclone delete AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --files-from $tempFile --drive-chunk-size 64M + rclone delete AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --files-from \$tempFile --drive-chunk-size 64M # Clean up the temporary file - Remove-Item -Path $tempFile + Remove-Item -Path \$tempFile } else { Write-Output "No files to delete." } } else { Write-Output "No files found on Google Drive to clean up." } - ''' - - // Write the PowerShell cleanup script to a temporary file - def tempScriptFile = "cleanup_script.ps1" - writeFile file: tempScriptFile, text: cleanupScript - - // Run the PowerShell script - powershell script: tempScriptFile - - // Clean up the temporary PowerShell script file - deleteFile tempScriptFile - } + """ } } } From d547a4007eb672fa95ef9f330a05695761107068 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 15:14:12 +0300 Subject: [PATCH 45/85] gdrive update1 --- build/jenkins/GDriveUpload | 161 ++++++++----------------------------- 1 file changed, 34 insertions(+), 127 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index 449261c..44c6288 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -1,138 +1,45 @@ -pipeline { - agent { label 'Win10-BuildMachine' } +stage('Cleanup Older Files on Google Drive') { + steps { + echo "Cleaning up older files on Google Drive..." + powershell """ + # List all files in the Google Drive folder + Write-Output "Listing all files in the folder ${params.GOOGLE_DRIVE_FOLDER} on Google Drive..." + \$files = rclone lsf --files-only AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --format "tp" --max-depth 1 + Write-Output "Files found on Google Drive:" + Write-Output \$files - tools { - git 'Default' - } + # If files were found + if (\$files.Count -gt 0) { + # Sort the files by date in descending order + \$filesSorted = \$files | Sort-Object -Descending - parameters { - string(name: 'GOOGLE_DRIVE_FOLDER', defaultValue: 'AzaionSuiteBuilds', description: 'The folder on Google Drive where the build will be uploaded.') - } + # Keep only the 3 latest files + \$filesToDelete = \$filesSorted | Select-Object -Skip 3 - environment { - RCLONE_CONFIG = 'C:/Program Files/rclone/rclone.conf' // Ensure this points to the correct location - } + Write-Output "Files to delete (older than 3 latest):" + Write-Output \$filesToDelete - stages { - stage('Initialize Workspace') { - steps { - echo 'Initializing workspace on Windows agent...' - powershell ''' - $uploadDir = "temp_upload" - if (-Not (Test-Path $uploadDir)) { - New-Item -ItemType Directory -Path $uploadDir | Out-Null - } - ''' - } - } + # If there are files to delete, remove them + if (\$filesToDelete.Count -gt 0) { + Write-Output "Deleting files: \$filesToDelete" - stage('Find Latest Zip and Upload') { - steps { - script { - echo "Starting 'Find Latest Zip and Upload' stage." - dir("C:/Jenkins/workspace/AzaionSuite/suite") { - def output = powershell(returnStdout: true, script: ''' - $pattern = "AzaionSuite*-*-*.zip" - $zipFiles = Get-ChildItem -Filter $pattern | Sort-Object Name -Descending - if ($zipFiles.Count -eq 0) { - Write-Error "No ZIP files matching pattern '$pattern' were found." - exit 1 - } - $latestZip = $zipFiles[0].Name - Write-Output "::SET-ENV::LATEST_ZIP_FILENAME=$latestZip" - ''').trim() + # Create a temporary file to store the list of files to delete + \$tempFile = [System.IO.Path]::GetTempFileName() + \$filesToDelete | Out-File -FilePath \$tempFile -Encoding utf8 + Write-Output "Temporary file created: \$tempFile" - def match = output =~ /::SET-ENV::LATEST_ZIP_FILENAME=(.+)/ - if (!match) { - error("Could not find the latest zip filename in the PowerShell output using marker.") - } - def zipFileName = match[0][1] - echo "Latest zip file selected: ${zipFileName}" + # Use rclone to delete the files + Write-Output "Executing rclone delete..." + rclone delete AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --files-from \$tempFile --drive-chunk-size 64M --progress - // Pass the variable into the environment for the next steps if needed - env.LATEST_ZIP_FILENAME = zipFileName - } + # Clean up the temporary file + Remove-Item -Path \$tempFile + } else { + Write-Output "No files to delete." } + } else { + Write-Output "No files found on Google Drive to clean up." } - } - - stage('Upload to Google Drive using rclone') { - steps { - echo "Uploading ${env.LATEST_ZIP_FILENAME} to Google Drive..." - powershell """ - \$filePath = "C:/Jenkins/workspace/AzaionSuite/suite/${env.LATEST_ZIP_FILENAME}" - Write-Output "Preparing to upload: \$filePath" - - # Display the contents of the rclone configuration file to ensure it's being read correctly - Get-Content 'C:/Program Files/rclone/rclone.conf' - - # Explicitly set the rclone config path - \$env:RCLONE_CONFIG = 'C:/Program Files/rclone/rclone.conf' - - # Use rclone to upload the file to Google Drive - rclone copy "\$filePath" AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --progress --drive-chunk-size 64M - """ - } - } - - stage('Cleanup Older Files on Google Drive') { - steps { - echo "Cleaning up older files on Google Drive..." - powershell """ - # List all files in the Google Drive folder - Write-Output "Listing all files in the folder ${params.GOOGLE_DRIVE_FOLDER} on Google Drive..." - \$files = rclone lsf --files-only AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --format "tp" --max-depth 1 - Write-Output "Files found on Google Drive:" - Write-Output \$files - - # If files were found - if (\$files.Count -gt 0) { - # Sort the files by date in descending order - \$filesSorted = \$files | Sort-Object -Descending - - # Keep only the 3 latest files - \$filesToDelete = \$filesSorted | Select-Object -Skip 3 - - Write-Output "Files to delete (older than 3 latest):" - Write-Output \$filesToDelete - - # If there are files to delete, remove them - if (\$filesToDelete.Count -gt 0) { - Write-Output "Deleting files: \$filesToDelete" - - # Create a temporary file to store the list of files to delete - \$tempFile = [System.IO.Path]::GetTempFileName() - \$filesToDelete | Out-File -FilePath \$tempFile -Encoding utf8 - - # Use rclone to delete the files - rclone delete AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --files-from \$tempFile --drive-chunk-size 64M - - # Clean up the temporary file - Remove-Item -Path \$tempFile - } else { - Write-Output "No files to delete." - } - } else { - Write-Output "No files found on Google Drive to clean up." - } - """ - } - } - } - - post { - always { - echo 'Executing post-build cleanup...' - powershell ''' - $uploadDir = "temp_upload" - if (Test-Path $uploadDir) { - Remove-Item -Recurse -Force $uploadDir - } - ''' - } - - failure { - echo 'Pipeline failed. Check logs for details.' - } + """ } } From 0602b0c6f2c39910e36c540e5a84418d9f762803 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 15:15:23 +0300 Subject: [PATCH 46/85] Revert "gdrive update1" This reverts commit a1f46799 --- build/jenkins/GDriveUpload | 184 +++++++++++++++++++++++++++++-------- 1 file changed, 146 insertions(+), 38 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index 44c6288..99c65cd 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -1,45 +1,153 @@ -stage('Cleanup Older Files on Google Drive') { - steps { - echo "Cleaning up older files on Google Drive..." - powershell """ - # List all files in the Google Drive folder - Write-Output "Listing all files in the folder ${params.GOOGLE_DRIVE_FOLDER} on Google Drive..." - \$files = rclone lsf --files-only AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --format "tp" --max-depth 1 - Write-Output "Files found on Google Drive:" - Write-Output \$files +pipeline { + agent { label 'Win10-BuildMachine' } - # If files were found - if (\$files.Count -gt 0) { - # Sort the files by date in descending order - \$filesSorted = \$files | Sort-Object -Descending + tools { + git 'Default' + } - # Keep only the 3 latest files - \$filesToDelete = \$filesSorted | Select-Object -Skip 3 + parameters { + string(name: 'GOOGLE_DRIVE_FOLDER', defaultValue: 'AzaionSuiteBuilds', description: 'The folder on Google Drive where the build will be uploaded.') + } - Write-Output "Files to delete (older than 3 latest):" - Write-Output \$filesToDelete + environment { + RCLONE_CONFIG = 'C:/Program Files/rclone/rclone.conf' // Ensure this points to the correct location + } - # If there are files to delete, remove them - if (\$filesToDelete.Count -gt 0) { - Write-Output "Deleting files: \$filesToDelete" - - # Create a temporary file to store the list of files to delete - \$tempFile = [System.IO.Path]::GetTempFileName() - \$filesToDelete | Out-File -FilePath \$tempFile -Encoding utf8 - Write-Output "Temporary file created: \$tempFile" - - # Use rclone to delete the files - Write-Output "Executing rclone delete..." - rclone delete AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --files-from \$tempFile --drive-chunk-size 64M --progress - - # Clean up the temporary file - Remove-Item -Path \$tempFile - } else { - Write-Output "No files to delete." - } - } else { - Write-Output "No files found on Google Drive to clean up." + stages { + stage('Initialize Workspace') { + steps { + echo 'Initializing workspace on Windows agent...' + powershell ''' + $uploadDir = "temp_upload" + if (-Not (Test-Path $uploadDir)) { + New-Item -ItemType Directory -Path $uploadDir | Out-Null + } + ''' } - """ + } + + stage('Find Latest Zip and Upload') { + steps { + script { + echo "Starting 'Find Latest Zip and Upload' stage." + dir("C:/Jenkins/workspace/AzaionSuite/suite") { + def output = powershell(returnStdout: true, script: ''' + $pattern = "AzaionSuite*-*-*.zip" + $zipFiles = Get-ChildItem -Filter $pattern | Sort-Object Name -Descending + if ($zipFiles.Count -eq 0) { + Write-Error "No ZIP files matching pattern '$pattern' were found." + exit 1 + } + $latestZip = $zipFiles[0].Name + Write-Output "::SET-ENV::LATEST_ZIP_FILENAME=$latestZip" + ''').trim() + + def match = output =~ /::SET-ENV::LATEST_ZIP_FILENAME=(.+)/ + if (!match) { + error("Could not find the latest zip filename in the PowerShell output using marker.") + } + def zipFileName = match[0][1] + echo "Latest zip file selected: ${zipFileName}" + + // Pass the variable into the environment for the next steps if needed + env.LATEST_ZIP_FILENAME = zipFileName + } + } + } + } + + stage('Upload to Google Drive using rclone') { + steps { + echo "Uploading ${env.LATEST_ZIP_FILENAME} to Google Drive..." + powershell """ + \$filePath = "C:/Jenkins/workspace/AzaionSuite/suite/${env.LATEST_ZIP_FILENAME}" + Write-Output "Preparing to upload: \$filePath" + + # Display the contents of the rclone configuration file to ensure it's being read correctly + Get-Content 'C:/Program Files/rclone/rclone.conf' + + # Explicitly set the rclone config path + \$env:RCLONE_CONFIG = 'C:/Program Files/rclone/rclone.conf' + + # Use rclone to upload the file to Google Drive + rclone copy "\$filePath" AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --progress --drive-chunk-size 64M + """ + } + } + + stage('Cleanup Older Files on Google Drive') { + steps { + script { + // Writing PowerShell cleanup script to a temporary file + def cleanupScript = ''' + # List all files in the Google Drive folder + Write-Output "Listing all files in the folder ${params.GOOGLE_DRIVE_FOLDER} on Google Drive..." + $files = rclone lsf --files-only AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --format "tp" --max-depth 1 + Write-Output "Files found on Google Drive:" + Write-Output $files + + # If files were found + if ($files.Count -gt 0) { + # Sort the files by date in descending order + $filesSorted = $files | Sort-Object -Descending + + # Keep only the 3 latest files + $filesToDelete = $filesSorted | Select-Object -Skip 3 + + Write-Output "Files to delete (older than 3 latest):" + Write-Output $filesToDelete + + # If there are files to delete, remove them + if ($filesToDelete.Count -gt 0) { + Write-Output "Deleting files: $filesToDelete" + + # Extract file names (without timestamps) + $fileNamesToDelete = $filesToDelete -replace '^\S+ ', '' + + # Create a temporary file to store the list of files to delete + $tempFile = [System.IO.Path]::GetTempFileName() + $fileNamesToDelete | Out-File -FilePath $tempFile -Encoding utf8 + + # Use rclone to delete the files + rclone delete AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --files-from $tempFile --drive-chunk-size 64M + + # Clean up the temporary file + Remove-Item -Path $tempFile + } else { + Write-Output "No files to delete." + } + } else { + Write-Output "No files found on Google Drive to clean up." + } + ''' + + // Write the PowerShell cleanup script to a temporary file + def tempScriptFile = "cleanup_script.ps1" + writeFile file: tempScriptFile, text: cleanupScript + + // Run the PowerShell script + powershell script: tempScriptFile + + // Clean up the temporary PowerShell script file + deleteFile tempScriptFile + } + } + } + } + + post { + always { + echo 'Executing post-build cleanup...' + powershell ''' + $uploadDir = "temp_upload" + if (Test-Path $uploadDir) { + Remove-Item -Recurse -Force $uploadDir + } + ''' + } + + failure { + echo 'Pipeline failed. Check logs for details.' + } } } From bfe620d85eb3c9c38c12c7e2dab8a520a9fd34ae Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 15:15:58 +0300 Subject: [PATCH 47/85] gdrive update1 --- build/jenkins/GDriveUpload | 45 +++++++++++++------------------------- 1 file changed, 15 insertions(+), 30 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index 99c65cd..449261c 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -77,60 +77,45 @@ pipeline { stage('Cleanup Older Files on Google Drive') { steps { - script { - // Writing PowerShell cleanup script to a temporary file - def cleanupScript = ''' + echo "Cleaning up older files on Google Drive..." + powershell """ # List all files in the Google Drive folder Write-Output "Listing all files in the folder ${params.GOOGLE_DRIVE_FOLDER} on Google Drive..." - $files = rclone lsf --files-only AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --format "tp" --max-depth 1 + \$files = rclone lsf --files-only AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --format "tp" --max-depth 1 Write-Output "Files found on Google Drive:" - Write-Output $files + Write-Output \$files # If files were found - if ($files.Count -gt 0) { + if (\$files.Count -gt 0) { # Sort the files by date in descending order - $filesSorted = $files | Sort-Object -Descending + \$filesSorted = \$files | Sort-Object -Descending # Keep only the 3 latest files - $filesToDelete = $filesSorted | Select-Object -Skip 3 + \$filesToDelete = \$filesSorted | Select-Object -Skip 3 Write-Output "Files to delete (older than 3 latest):" - Write-Output $filesToDelete + Write-Output \$filesToDelete # If there are files to delete, remove them - if ($filesToDelete.Count -gt 0) { - Write-Output "Deleting files: $filesToDelete" - - # Extract file names (without timestamps) - $fileNamesToDelete = $filesToDelete -replace '^\S+ ', '' + if (\$filesToDelete.Count -gt 0) { + Write-Output "Deleting files: \$filesToDelete" # Create a temporary file to store the list of files to delete - $tempFile = [System.IO.Path]::GetTempFileName() - $fileNamesToDelete | Out-File -FilePath $tempFile -Encoding utf8 + \$tempFile = [System.IO.Path]::GetTempFileName() + \$filesToDelete | Out-File -FilePath \$tempFile -Encoding utf8 # Use rclone to delete the files - rclone delete AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --files-from $tempFile --drive-chunk-size 64M + rclone delete AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --files-from \$tempFile --drive-chunk-size 64M # Clean up the temporary file - Remove-Item -Path $tempFile + Remove-Item -Path \$tempFile } else { Write-Output "No files to delete." } } else { Write-Output "No files found on Google Drive to clean up." } - ''' - - // Write the PowerShell cleanup script to a temporary file - def tempScriptFile = "cleanup_script.ps1" - writeFile file: tempScriptFile, text: cleanupScript - - // Run the PowerShell script - powershell script: tempScriptFile - - // Clean up the temporary PowerShell script file - deleteFile tempScriptFile - } + """ } } } From 838cd1b8ecfecc9519cf894d29859076fa47364a Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 15:18:50 +0300 Subject: [PATCH 48/85] gdrive update1 --- build/jenkins/GDriveUpload | 60 +++++++++++++++----------------------- 1 file changed, 24 insertions(+), 36 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index 449261c..6b629c2 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -75,50 +75,38 @@ pipeline { } } - stage('Cleanup Older Files on Google Drive') { - steps { - echo "Cleaning up older files on Google Drive..." - powershell """ - # List all files in the Google Drive folder - Write-Output "Listing all files in the folder ${params.GOOGLE_DRIVE_FOLDER} on Google Drive..." - \$files = rclone lsf --files-only AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --format "tp" --max-depth 1 - Write-Output "Files found on Google Drive:" - Write-Output \$files + stage('Cleanup Older Files on Google Drive') { + steps { + echo "Cleaning up older files on Google Drive..." + powershell """ + # List all files in the Google Drive folder (only filenames) + Write-Output "Listing all files in the folder ${params.GOOGLE_DRIVE_FOLDER} on Google Drive..." + \$files = rclone lsf --files-only AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} + Write-Output "Files found on Google Drive:" + Write-Output \$files - # If files were found - if (\$files.Count -gt 0) { - # Sort the files by date in descending order - \$filesSorted = \$files | Sort-Object -Descending + # Convert to array and sort by name descending (adjust if you want date sorting) + \$filesArray = \$files -split "`n" | Where-Object { \$_ -ne "" } | Sort-Object -Descending - # Keep only the 3 latest files - \$filesToDelete = \$filesSorted | Select-Object -Skip 3 + # Keep only the 3 latest files + \$filesToDelete = \$filesArray | Select-Object -Skip 3 - Write-Output "Files to delete (older than 3 latest):" - Write-Output \$filesToDelete + Write-Output "Files to delete (older than 3 latest):" + Write-Output \$filesToDelete - # If there are files to delete, remove them - if (\$filesToDelete.Count -gt 0) { - Write-Output "Deleting files: \$filesToDelete" + if (\$filesToDelete.Count -gt 0) { + \$tempFile = [System.IO.Path]::GetTempFileName() + \$filesToDelete | Out-File -FilePath \$tempFile -Encoding utf8 - # Create a temporary file to store the list of files to delete - \$tempFile = [System.IO.Path]::GetTempFileName() - \$filesToDelete | Out-File -FilePath \$tempFile -Encoding utf8 + rclone delete AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --files-from \$tempFile --drive-chunk-size 64M - # Use rclone to delete the files - rclone delete AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --files-from \$tempFile --drive-chunk-size 64M - - # Clean up the temporary file - Remove-Item -Path \$tempFile - } else { - Write-Output "No files to delete." - } - } else { - Write-Output "No files found on Google Drive to clean up." - } - """ + Remove-Item -Path \$tempFile + } else { + Write-Output "No files to delete." } - } + """ } +} post { always { From eddd3f2052dca16e6954fd8cb3ab8d9829957069 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 15:19:34 +0300 Subject: [PATCH 49/85] gdrive update1 --- build/jenkins/GDriveUpload | 53 +++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 30 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index 6b629c2..5df6d13 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -10,7 +10,7 @@ pipeline { } environment { - RCLONE_CONFIG = 'C:/Program Files/rclone/rclone.conf' // Ensure this points to the correct location + RCLONE_CONFIG = 'C:/Program Files/rclone/rclone.conf' } stages { @@ -49,7 +49,6 @@ pipeline { def zipFileName = match[0][1] echo "Latest zip file selected: ${zipFileName}" - // Pass the variable into the environment for the next steps if needed env.LATEST_ZIP_FILENAME = zipFileName } } @@ -63,50 +62,44 @@ pipeline { \$filePath = "C:/Jenkins/workspace/AzaionSuite/suite/${env.LATEST_ZIP_FILENAME}" Write-Output "Preparing to upload: \$filePath" - # Display the contents of the rclone configuration file to ensure it's being read correctly Get-Content 'C:/Program Files/rclone/rclone.conf' - - # Explicitly set the rclone config path \$env:RCLONE_CONFIG = 'C:/Program Files/rclone/rclone.conf' - # Use rclone to upload the file to Google Drive rclone copy "\$filePath" AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --progress --drive-chunk-size 64M """ } } - stage('Cleanup Older Files on Google Drive') { - steps { - echo "Cleaning up older files on Google Drive..." - powershell """ - # List all files in the Google Drive folder (only filenames) - Write-Output "Listing all files in the folder ${params.GOOGLE_DRIVE_FOLDER} on Google Drive..." - \$files = rclone lsf --files-only AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} - Write-Output "Files found on Google Drive:" - Write-Output \$files + stage('Cleanup Older Files on Google Drive') { + steps { + echo "Cleaning up older files on Google Drive..." + powershell """ + Write-Output "Listing all files in the folder ${params.GOOGLE_DRIVE_FOLDER} on Google Drive..." + \$files = rclone lsf --files-only AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} + Write-Output "Files found on Google Drive:" + Write-Output \$files - # Convert to array and sort by name descending (adjust if you want date sorting) - \$filesArray = \$files -split "`n" | Where-Object { \$_ -ne "" } | Sort-Object -Descending + \$filesArray = \$files -split "`n" | Where-Object { \$_ -ne "" } | Sort-Object -Descending - # Keep only the 3 latest files - \$filesToDelete = \$filesArray | Select-Object -Skip 3 + \$filesToDelete = \$filesArray | Select-Object -Skip 3 - Write-Output "Files to delete (older than 3 latest):" - Write-Output \$filesToDelete + Write-Output "Files to delete (older than 3 latest):" + Write-Output \$filesToDelete - if (\$filesToDelete.Count -gt 0) { - \$tempFile = [System.IO.Path]::GetTempFileName() - \$filesToDelete | Out-File -FilePath \$tempFile -Encoding utf8 + if (\$filesToDelete.Count -gt 0) { + \$tempFile = [System.IO.Path]::GetTempFileName() + \$filesToDelete | Out-File -FilePath \$tempFile -Encoding utf8 - rclone delete AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --files-from \$tempFile --drive-chunk-size 64M + rclone delete AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --files-from \$tempFile --drive-chunk-size 64M - Remove-Item -Path \$tempFile - } else { - Write-Output "No files to delete." + Remove-Item -Path \$tempFile + } else { + Write-Output "No files to delete." + } + """ } - """ + } } -} post { always { From b776576b76612076dbd3be799ef4bcf788f2cfb2 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 15:25:36 +0300 Subject: [PATCH 50/85] gdrive update1 --- build/jenkins/GDriveUpload | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index 5df6d13..cc8c63b 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -89,8 +89,10 @@ pipeline { if (\$filesToDelete.Count -gt 0) { \$tempFile = [System.IO.Path]::GetTempFileName() \$filesToDelete | Out-File -FilePath \$tempFile -Encoding utf8 - - rclone delete AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --files-from \$tempFile --drive-chunk-size 64M + W + rite-Output "Contents of temporary delete list file (\$tempFile):" + Get-Content \$tempFile + rclone delete AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --files-from \$tempFile Remove-Item -Path \$tempFile } else { From 61ca5c28990cda8fb6bb46fab69d46b98eec83c4 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 15:26:35 +0300 Subject: [PATCH 51/85] gdrive update1 --- build/jenkins/GDriveUpload | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index cc8c63b..1a4dc80 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -89,8 +89,7 @@ pipeline { if (\$filesToDelete.Count -gt 0) { \$tempFile = [System.IO.Path]::GetTempFileName() \$filesToDelete | Out-File -FilePath \$tempFile -Encoding utf8 - W - rite-Output "Contents of temporary delete list file (\$tempFile):" + Write-Output "Contents of temporary delete list file (\$tempFile):" Get-Content \$tempFile rclone delete AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --files-from \$tempFile From 4703c73a24c3a38c64285d53080414d031564dde Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 15:29:00 +0300 Subject: [PATCH 52/85] gdrive update1 --- build/jenkins/GDriveUpload | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index 1a4dc80..b3699d2 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -10,7 +10,7 @@ pipeline { } environment { - RCLONE_CONFIG = 'C:/Program Files/rclone/rclone.conf' + RCLONE_CONFIG = 'C:/Program Files/rclone/rclone.conf' // Ensure this points to the correct location } stages { @@ -62,9 +62,12 @@ pipeline { \$filePath = "C:/Jenkins/workspace/AzaionSuite/suite/${env.LATEST_ZIP_FILENAME}" Write-Output "Preparing to upload: \$filePath" + # Display the contents of the rclone configuration file to ensure it's being read correctly Get-Content 'C:/Program Files/rclone/rclone.conf' + \$env:RCLONE_CONFIG = 'C:/Program Files/rclone/rclone.conf' + # Use rclone to upload the file to Google Drive rclone copy "\$filePath" AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --progress --drive-chunk-size 64M """ } @@ -74,28 +77,28 @@ pipeline { steps { echo "Cleaning up older files on Google Drive..." powershell """ - Write-Output "Listing all files in the folder ${params.GOOGLE_DRIVE_FOLDER} on Google Drive..." - \$files = rclone lsf --files-only AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} + \$driveFolder = '${params.GOOGLE_DRIVE_FOLDER}' + + # List all files in the Google Drive folder + Write-Output "Listing all files in the folder \$driveFolder on Google Drive..." + \$files = rclone lsf AzaionGoogleDrive:\$driveFolder --files-only --max-depth 1 Write-Output "Files found on Google Drive:" Write-Output \$files - \$filesArray = \$files -split "`n" | Where-Object { \$_ -ne "" } | Sort-Object -Descending + if (\$files.Count -gt 0) { + \$filesSorted = \$files | Sort-Object -Descending + \$filesToDelete = \$filesSorted | Select-Object -Skip 3 - \$filesToDelete = \$filesArray | Select-Object -Skip 3 + Write-Output "Files to delete (older than 3 latest):" + Write-Output \$filesToDelete - Write-Output "Files to delete (older than 3 latest):" - Write-Output \$filesToDelete - - if (\$filesToDelete.Count -gt 0) { - \$tempFile = [System.IO.Path]::GetTempFileName() - \$filesToDelete | Out-File -FilePath \$tempFile -Encoding utf8 - Write-Output "Contents of temporary delete list file (\$tempFile):" - Get-Content \$tempFile - rclone delete AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --files-from \$tempFile - - Remove-Item -Path \$tempFile + foreach (\$file in \$filesToDelete) { + \$trimmedFile = \$file.Trim() + Write-Output "Deleting file: \$trimmedFile" + rclone deletefile AzaionGoogleDrive:\$driveFolder/\$trimmedFile + } } else { - Write-Output "No files to delete." + Write-Output "No files found on Google Drive to clean up." } """ } From 7fc51e19eef389b27e374d979423f0cae06d9217 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 15:31:12 +0300 Subject: [PATCH 53/85] latest fixes for Gdrive upload --- build/jenkins/GDriveUpload | 58 ++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index b3699d2..8c6fa37 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -10,7 +10,7 @@ pipeline { } environment { - RCLONE_CONFIG = 'C:/Program Files/rclone/rclone.conf' // Ensure this points to the correct location + RCLONE_CONFIG = 'C:/Program Files/rclone/rclone.conf' } stages { @@ -57,18 +57,25 @@ pipeline { stage('Upload to Google Drive using rclone') { steps { - echo "Uploading ${env.LATEST_ZIP_FILENAME} to Google Drive..." + echo "Checking if ${env.LATEST_ZIP_FILENAME} already exists on Google Drive..." powershell """ - \$filePath = "C:/Jenkins/workspace/AzaionSuite/suite/${env.LATEST_ZIP_FILENAME}" - Write-Output "Preparing to upload: \$filePath" + \$fileName = "${env.LATEST_ZIP_FILENAME}" + \$folder = "${params.GOOGLE_DRIVE_FOLDER}" + \$rcloneRemote = "AzaionGoogleDrive:\$folder" - # Display the contents of the rclone configuration file to ensure it's being read correctly - Get-Content 'C:/Program Files/rclone/rclone.conf' + Write-Output "Checking for existing files in: \$rcloneRemote" + \$existingFiles = rclone lsf --files-only \$rcloneRemote + Write-Output "Existing files:" + Write-Output \$existingFiles - \$env:RCLONE_CONFIG = 'C:/Program Files/rclone/rclone.conf' - - # Use rclone to upload the file to Google Drive - rclone copy "\$filePath" AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} --progress --drive-chunk-size 64M + if (\$existingFiles -match "^\$fileName\$") { + Write-Output "File '\$fileName' already exists on Google Drive. Skipping upload." + } else { + Write-Output "Uploading '\$fileName' to Google Drive..." + \$filePath = "C:/Jenkins/workspace/AzaionSuite/suite/\$fileName" + \$env:RCLONE_CONFIG = 'C:/Program Files/rclone/rclone.conf' + rclone copy "\$filePath" \$rcloneRemote --progress --drive-chunk-size 64M + } """ } } @@ -77,25 +84,34 @@ pipeline { steps { echo "Cleaning up older files on Google Drive..." powershell """ - \$driveFolder = '${params.GOOGLE_DRIVE_FOLDER}' - - # List all files in the Google Drive folder - Write-Output "Listing all files in the folder \$driveFolder on Google Drive..." - \$files = rclone lsf AzaionGoogleDrive:\$driveFolder --files-only --max-depth 1 + Write-Output "Listing all files in the folder ${params.GOOGLE_DRIVE_FOLDER} on Google Drive..." + \$files = rclone lsf --files-only AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} Write-Output "Files found on Google Drive:" Write-Output \$files - if (\$files.Count -gt 0) { - \$filesSorted = \$files | Sort-Object -Descending + \$filesArray = \$files -split "`n" | Where-Object { \$_ -ne "" } + if (\$filesArray.Count -gt 3) { + \$filesSorted = \$filesArray | Sort-Object -Descending \$filesToDelete = \$filesSorted | Select-Object -Skip 3 Write-Output "Files to delete (older than 3 latest):" Write-Output \$filesToDelete - foreach (\$file in \$filesToDelete) { - \$trimmedFile = \$file.Trim() - Write-Output "Deleting file: \$trimmedFile" - rclone deletefile AzaionGoogleDrive:\$driveFolder/\$trimmedFile + if (\$filesToDelete.Count -gt 0) { + \$tempFile = [System.IO.Path]::GetTempFileName() + \$filesToDelete | Set-Content -Path \$tempFile -Encoding utf8 + + Write-Output "Contents of temporary delete list file (\$tempFile):" + Get-Content \$tempFile + + foreach (\$file in \$filesToDelete) { + Write-Output "Deleting \$file..." + rclone deletefile AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER}/\$file + } + + Remove-Item -Path \$tempFile + } else { + Write-Output "No files to delete." } } else { Write-Output "No files found on Google Drive to clean up." From bb7eec1d5d594c4f320ef6ea7e86257bc92e3700 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 15:33:23 +0300 Subject: [PATCH 54/85] latest fixes for Gdrive upload --- build/jenkins/GDriveUpload | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index 8c6fa37..402ada9 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -55,13 +55,14 @@ pipeline { } } - stage('Upload to Google Drive using rclone') { + stage('Upload or Delete Local If Already Exists') { steps { echo "Checking if ${env.LATEST_ZIP_FILENAME} already exists on Google Drive..." powershell """ \$fileName = "${env.LATEST_ZIP_FILENAME}" \$folder = "${params.GOOGLE_DRIVE_FOLDER}" \$rcloneRemote = "AzaionGoogleDrive:\$folder" + \$localFilePath = "C:/Jenkins/workspace/AzaionSuite/suite/\$fileName" Write-Output "Checking for existing files in: \$rcloneRemote" \$existingFiles = rclone lsf --files-only \$rcloneRemote @@ -69,12 +70,17 @@ pipeline { Write-Output \$existingFiles if (\$existingFiles -match "^\$fileName\$") { - Write-Output "File '\$fileName' already exists on Google Drive. Skipping upload." + Write-Output "File '\$fileName' already exists on Google Drive. Deleting local copy..." + if (Test-Path \$localFilePath) { + Remove-Item -Force \$localFilePath + Write-Output "Local file deleted: \$localFilePath" + } else { + Write-Output "Local file not found for deletion: \$localFilePath" + } } else { Write-Output "Uploading '\$fileName' to Google Drive..." - \$filePath = "C:/Jenkins/workspace/AzaionSuite/suite/\$fileName" - \$env:RCLONE_CONFIG = 'C:/Program Files/rclone/rclone.conf' - rclone copy "\$filePath" \$rcloneRemote --progress --drive-chunk-size 64M + rclone copy "\$localFilePath" \$rcloneRemote --progress --drive-chunk-size 64M + Write-Output "Upload complete." } """ } From 2766be732da6ecac04c70dc20297cb35f6de5166 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 15:39:03 +0300 Subject: [PATCH 55/85] latest fixes for Gdrive upload --- build/jenkins/GDriveUpload | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index 402ada9..3efea58 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -26,10 +26,10 @@ pipeline { } } - stage('Find Latest Zip and Upload') { + stage('Find Latest Zip') { steps { script { - echo "Starting 'Find Latest Zip and Upload' stage." + echo "Finding latest zip file..." dir("C:/Jenkins/workspace/AzaionSuite/suite") { def output = powershell(returnStdout: true, script: ''' $pattern = "AzaionSuite*-*-*.zip" @@ -48,16 +48,15 @@ pipeline { } def zipFileName = match[0][1] echo "Latest zip file selected: ${zipFileName}" - env.LATEST_ZIP_FILENAME = zipFileName } } } } - stage('Upload or Delete Local If Already Exists') { + stage('Upload If Not Exists & Always Remove Local') { steps { - echo "Checking if ${env.LATEST_ZIP_FILENAME} already exists on Google Drive..." + echo "Checking Google Drive for existing ZIP and uploading if needed..." powershell """ \$fileName = "${env.LATEST_ZIP_FILENAME}" \$folder = "${params.GOOGLE_DRIVE_FOLDER}" @@ -70,18 +69,19 @@ pipeline { Write-Output \$existingFiles if (\$existingFiles -match "^\$fileName\$") { - Write-Output "File '\$fileName' already exists on Google Drive. Deleting local copy..." - if (Test-Path \$localFilePath) { - Remove-Item -Force \$localFilePath - Write-Output "Local file deleted: \$localFilePath" - } else { - Write-Output "Local file not found for deletion: \$localFilePath" - } + Write-Output "File '\$fileName' already exists on Google Drive. Skipping upload." } else { Write-Output "Uploading '\$fileName' to Google Drive..." rclone copy "\$localFilePath" \$rcloneRemote --progress --drive-chunk-size 64M Write-Output "Upload complete." } + + if (Test-Path \$localFilePath) { + Remove-Item -Force \$localFilePath + Write-Output "Local file deleted: \$localFilePath" + } else { + Write-Output "Local file already deleted or not found." + } """ } } From 1acfab9b87d660ef7f4a82dc436d82deb0041f79 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 18:49:25 +0300 Subject: [PATCH 56/85] latest fixes for Gdrive upload --- build/jenkins/GDriveUpload | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index 3efea58..2bd008b 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -32,7 +32,7 @@ pipeline { echo "Finding latest zip file..." dir("C:/Jenkins/workspace/AzaionSuite/suite") { def output = powershell(returnStdout: true, script: ''' - $pattern = "AzaionSuite*-*-*.zip" + $pattern = "AzaionSuite.*-*-*.zip" $zipFiles = Get-ChildItem -Filter $pattern | Sort-Object Name -Descending if ($zipFiles.Count -eq 0) { Write-Error "No ZIP files matching pattern '$pattern' were found." From 961c750f1f7f5360823a55b3e886dc6f3f6633e9 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Sun, 4 May 2025 18:52:08 +0300 Subject: [PATCH 57/85] latest fixes for Gdrive upload --- build/jenkins/GDriveUpload | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index 2bd008b..50b1d23 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -32,29 +32,34 @@ pipeline { echo "Finding latest zip file..." dir("C:/Jenkins/workspace/AzaionSuite/suite") { def output = powershell(returnStdout: true, script: ''' - $pattern = "AzaionSuite.*-*-*.zip" + $pattern = "AzaionSuite*-*-*.zip" $zipFiles = Get-ChildItem -Filter $pattern | Sort-Object Name -Descending - if ($zipFiles.Count -eq 0) { - Write-Error "No ZIP files matching pattern '$pattern' were found." - exit 1 + if ($zipFiles.Count -gt 0) { + $latestZip = $zipFiles[0].Name + Write-Output "::SET-ENV::LATEST_ZIP_FILENAME=$latestZip" + } else { + Write-Output "::SET-ENV::LATEST_ZIP_FILENAME=" } - $latestZip = $zipFiles[0].Name - Write-Output "::SET-ENV::LATEST_ZIP_FILENAME=$latestZip" ''').trim() def match = output =~ /::SET-ENV::LATEST_ZIP_FILENAME=(.+)/ - if (!match) { - error("Could not find the latest zip filename in the PowerShell output using marker.") + if (!match || !match[0][1]?.trim()) { + echo "⚠️ No ZIP files matching the pattern were found. Skipping upload and cleanup stages." + env.LATEST_ZIP_FILENAME = '' + } else { + def zipFileName = match[0][1] + echo "✅ Latest zip file selected: ${zipFileName}" + env.LATEST_ZIP_FILENAME = zipFileName } - def zipFileName = match[0][1] - echo "Latest zip file selected: ${zipFileName}" - env.LATEST_ZIP_FILENAME = zipFileName } } } } stage('Upload If Not Exists & Always Remove Local') { + when { + expression { return env.LATEST_ZIP_FILENAME?.trim() } + } steps { echo "Checking Google Drive for existing ZIP and uploading if needed..." powershell """ @@ -87,6 +92,9 @@ pipeline { } stage('Cleanup Older Files on Google Drive') { + when { + expression { return env.LATEST_ZIP_FILENAME?.trim() } + } steps { echo "Cleaning up older files on Google Drive..." powershell """ From d5e7a289643227d27a26cdbfe42a80252dacd8f3 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Wed, 7 May 2025 18:22:51 +0300 Subject: [PATCH 58/85] updated zip pipeline to use parameters from Azaion pipeline. --- build/jenkins/zip | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/build/jenkins/zip b/build/jenkins/zip index 4abfc08..1e09545 100644 --- a/build/jenkins/zip +++ b/build/jenkins/zip @@ -1,6 +1,10 @@ pipeline { agent { label 'Win10-BuildMachine' } + parameters { + string(name: 'buildPath', defaultValue: 'C:/Jenkins/workspace/AzaionSuite/suite', description: 'Build directory to zip from') + } + tools { git 'Default' } @@ -9,7 +13,6 @@ pipeline { SEVEN_ZIP_PATH = "C:/Program Files/7-Zip" PATH = "${SEVEN_ZIP_PATH};${env.PATH}" GOOGLE_DRIVE_UPLOAD_JOB_NAME = 'GDrive Upload' - MAIN_BUILD_ARTIFACTS_DIR = 'C:/Jenkins/workspace/AzaionSuite/suite' } stages { @@ -17,11 +20,11 @@ pipeline { steps { script { echo "Starting 'Detect or Create Zip' stage." - dir("${env.MAIN_BUILD_ARTIFACTS_DIR}") { + echo "Using build path: ${params.buildPath}" + dir("${params.buildPath}") { powershell ''' $ErrorActionPreference = "Stop" $sevenZipExe = "$env:SEVEN_ZIP_PATH\\7z.exe" - $defaultVersion = "1.0.0" $exePattern = "AzaionSuite*.exe" $binPattern = "AzaionSuite*.bin" $zipPattern = "AzaionSuite*.zip" @@ -66,18 +69,16 @@ pipeline { Write-Host "Created new zip file: $zipFilename" } - # Save outputs without BOM Set-Content -Path "zipfilename.txt" -Value $zipFilename -Encoding ASCII - Set-Content -Path "zip_created.txt" -Value $wasCreated -Encoding ASCII + Set-Content -Path "zip_was_created.txt" -Value $wasCreated -Encoding ASCII ''' def zipFilename = readFile('zipfilename.txt').trim() - def zipCreated = readFile('zip_created.txt').trim().toBoolean() + def zipCreated = readFile('zip_was_created.txt').trim().toBoolean() echo "Zip filename: ${zipFilename}" echo "Was zip created this run? ${zipCreated}" - // Save results for next stages writeFile file: 'created_zip.txt', text: zipFilename writeFile file: 'zip_was_created.txt', text: zipCreated.toString() } @@ -88,14 +89,14 @@ pipeline { stage('Archive Zip File (if new)') { when { expression { - def zipCreated = readFile("${env.MAIN_BUILD_ARTIFACTS_DIR}/zip_was_created.txt").trim().toBoolean() + def zipCreated = readFile("${params.buildPath}/zip_was_created.txt").trim().toBoolean() return zipCreated } } steps { script { echo "Archiving newly created zip file..." - dir("${env.MAIN_BUILD_ARTIFACTS_DIR}") { + dir("${params.buildPath}") { def zipFilename = readFile('created_zip.txt').trim() if (!fileExists(zipFilename)) { error "Zip file '${zipFilename}' not found!" @@ -119,7 +120,7 @@ pipeline { post { success { script { - def zipFilename = readFile("${env.MAIN_BUILD_ARTIFACTS_DIR}/created_zip.txt").trim() + def zipFilename = readFile("${params.buildPath}/created_zip.txt").trim() echo "Pipeline completed successfully. Final zip: ${zipFilename}" } } From 5c87f536c102f7ed008932b4161698134644e915 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Wed, 7 May 2025 18:31:55 +0300 Subject: [PATCH 59/85] updated zip pipeline to use parameters from Azaion pipeline - fixed path --- build/jenkins/zip | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/jenkins/zip b/build/jenkins/zip index 1e09545..598683e 100644 --- a/build/jenkins/zip +++ b/build/jenkins/zip @@ -2,7 +2,7 @@ pipeline { agent { label 'Win10-BuildMachine' } parameters { - string(name: 'buildPath', defaultValue: 'C:/Jenkins/workspace/AzaionSuite/suite', description: 'Build directory to zip from') + string(name: 'buildPath', defaultValue: 'C:/Jenkins/workspace/Azaion/suite', description: 'Build directory to zip from') } tools { From c3e4b741c8a73faf733e100714bde74ae7aa4e90 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Wed, 7 May 2025 18:37:26 +0300 Subject: [PATCH 60/85] updated pipelines zip and gdrive upload --- build/jenkins/GDriveUpload | 7 ++++--- build/jenkins/zip | 16 +++++++++------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index 50b1d23..7f777dc 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -7,6 +7,7 @@ pipeline { parameters { string(name: 'GOOGLE_DRIVE_FOLDER', defaultValue: 'AzaionSuiteBuilds', description: 'The folder on Google Drive where the build will be uploaded.') + string(name: 'buildPath', defaultValue: 'C:/Jenkins/workspace/AzaionSuite/suite', description: 'Path to folder containing zip builds.') } environment { @@ -29,8 +30,8 @@ pipeline { stage('Find Latest Zip') { steps { script { - echo "Finding latest zip file..." - dir("C:/Jenkins/workspace/AzaionSuite/suite") { + echo "Finding latest zip file in: ${params.buildPath}" + dir("${params.buildPath}") { def output = powershell(returnStdout: true, script: ''' $pattern = "AzaionSuite*-*-*.zip" $zipFiles = Get-ChildItem -Filter $pattern | Sort-Object Name -Descending @@ -66,7 +67,7 @@ pipeline { \$fileName = "${env.LATEST_ZIP_FILENAME}" \$folder = "${params.GOOGLE_DRIVE_FOLDER}" \$rcloneRemote = "AzaionGoogleDrive:\$folder" - \$localFilePath = "C:/Jenkins/workspace/AzaionSuite/suite/\$fileName" + \$localFilePath = "${params.buildPath}/\$fileName" Write-Output "Checking for existing files in: \$rcloneRemote" \$existingFiles = rclone lsf --files-only \$rcloneRemote diff --git a/build/jenkins/zip b/build/jenkins/zip index 598683e..5f27f61 100644 --- a/build/jenkins/zip +++ b/build/jenkins/zip @@ -107,15 +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 - } - } + 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) + ] } } +} post { success { From 495268e56ac6f60c941421a4654b738ed206d202 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Wed, 7 May 2025 18:38:56 +0300 Subject: [PATCH 61/85] updated pipelines zip and gdrive upload --- build/jenkins/zip | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/jenkins/zip b/build/jenkins/zip index 5f27f61..59c4274 100644 --- a/build/jenkins/zip +++ b/build/jenkins/zip @@ -107,7 +107,7 @@ pipeline { } } - stage('Trigger Google Drive Upload') { + stage('Trigger Google Drive Upload') { steps { script { echo "Triggering Google Drive Upload pipeline: ${env.GOOGLE_DRIVE_UPLOAD_JOB_NAME}" From e6ec904657084e6194da97c9dd35c57487ae08c8 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Wed, 7 May 2025 18:41:44 +0300 Subject: [PATCH 62/85] updated pipelines zip and gdrive upload --- build/jenkins/GDriveUpload | 213 +++++++++++++++++-------------------- 1 file changed, 97 insertions(+), 116 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index 7f777dc..afa9968 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -1,154 +1,135 @@ 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' } - parameters { - string(name: 'GOOGLE_DRIVE_FOLDER', defaultValue: 'AzaionSuiteBuilds', description: 'The folder on Google Drive where the build will be uploaded.') - string(name: 'buildPath', defaultValue: 'C:/Jenkins/workspace/AzaionSuite/suite', description: 'Path to folder containing zip builds.') - } - environment { - RCLONE_CONFIG = 'C:/Program Files/rclone/rclone.conf' + SEVEN_ZIP_PATH = "C:/Program Files/7-Zip" + PATH = "${SEVEN_ZIP_PATH};${env.PATH}" + GOOGLE_DRIVE_UPLOAD_JOB_NAME = 'GDrive Upload' } stages { - stage('Initialize Workspace') { - steps { - echo 'Initializing workspace on Windows agent...' - powershell ''' - $uploadDir = "temp_upload" - if (-Not (Test-Path $uploadDir)) { - New-Item -ItemType Directory -Path $uploadDir | Out-Null - } - ''' - } - } - - stage('Find Latest Zip') { + stage('Detect or Create Zip') { steps { script { - echo "Finding latest zip file in: ${params.buildPath}" + echo "Starting 'Detect or Create Zip' stage." + echo "Using build path: ${params.buildPath}" dir("${params.buildPath}") { - def output = powershell(returnStdout: true, script: ''' - $pattern = "AzaionSuite*-*-*.zip" - $zipFiles = Get-ChildItem -Filter $pattern | Sort-Object Name -Descending - if ($zipFiles.Count -gt 0) { - $latestZip = $zipFiles[0].Name - Write-Output "::SET-ENV::LATEST_ZIP_FILENAME=$latestZip" - } else { - Write-Output "::SET-ENV::LATEST_ZIP_FILENAME=" - } - ''').trim() + powershell ''' + $ErrorActionPreference = "Stop" + $sevenZipExe = "$env:SEVEN_ZIP_PATH\\7z.exe" + $exePattern = "AzaionSuite*.exe" + $binPattern = "AzaionSuite*.bin" + $zipPattern = "AzaionSuite*.zip" - def match = output =~ /::SET-ENV::LATEST_ZIP_FILENAME=(.+)/ - if (!match || !match[0][1]?.trim()) { - echo "⚠️ No ZIP files matching the pattern were found. Skipping upload and cleanup stages." - env.LATEST_ZIP_FILENAME = '' - } else { - def zipFileName = match[0][1] - echo "✅ Latest zip file selected: ${zipFileName}" - env.LATEST_ZIP_FILENAME = zipFileName - } + 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('Upload If Not Exists & Always Remove Local') { + stage('Archive Zip File (if new)') { when { - expression { return env.LATEST_ZIP_FILENAME?.trim() } + expression { + def zipCreated = readFile("${params.buildPath}/zip_was_created.txt").trim().toBoolean() + return zipCreated + } } steps { - echo "Checking Google Drive for existing ZIP and uploading if needed..." - powershell """ - \$fileName = "${env.LATEST_ZIP_FILENAME}" - \$folder = "${params.GOOGLE_DRIVE_FOLDER}" - \$rcloneRemote = "AzaionGoogleDrive:\$folder" - \$localFilePath = "${params.buildPath}/\$fileName" - - Write-Output "Checking for existing files in: \$rcloneRemote" - \$existingFiles = rclone lsf --files-only \$rcloneRemote - Write-Output "Existing files:" - Write-Output \$existingFiles - - if (\$existingFiles -match "^\$fileName\$") { - Write-Output "File '\$fileName' already exists on Google Drive. Skipping upload." - } else { - Write-Output "Uploading '\$fileName' to Google Drive..." - rclone copy "\$localFilePath" \$rcloneRemote --progress --drive-chunk-size 64M - Write-Output "Upload complete." + 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 } - - if (Test-Path \$localFilePath) { - Remove-Item -Force \$localFilePath - Write-Output "Local file deleted: \$localFilePath" - } else { - Write-Output "Local file already deleted or not found." - } - """ + } } } - stage('Cleanup Older Files on Google Drive') { - when { - expression { return env.LATEST_ZIP_FILENAME?.trim() } - } + stage('Trigger Google Drive Upload') { steps { - echo "Cleaning up older files on Google Drive..." - powershell """ - Write-Output "Listing all files in the folder ${params.GOOGLE_DRIVE_FOLDER} on Google Drive..." - \$files = rclone lsf --files-only AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} - Write-Output "Files found on Google Drive:" - Write-Output \$files - - \$filesArray = \$files -split "`n" | Where-Object { \$_ -ne "" } - if (\$filesArray.Count -gt 3) { - \$filesSorted = \$filesArray | Sort-Object -Descending - \$filesToDelete = \$filesSorted | Select-Object -Skip 3 - - Write-Output "Files to delete (older than 3 latest):" - Write-Output \$filesToDelete - - if (\$filesToDelete.Count -gt 0) { - \$tempFile = [System.IO.Path]::GetTempFileName() - \$filesToDelete | Set-Content -Path \$tempFile -Encoding utf8 - - Write-Output "Contents of temporary delete list file (\$tempFile):" - Get-Content \$tempFile - - foreach (\$file in \$filesToDelete) { - Write-Output "Deleting \$file..." - rclone deletefile AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER}/\$file - } - - Remove-Item -Path \$tempFile - } else { - Write-Output "No files to delete." - } - } else { - Write-Output "No files found on Google Drive to clean up." - } - """ + 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) + ] + } } } } post { - always { - echo 'Executing post-build cleanup...' - powershell ''' - $uploadDir = "temp_upload" - if (Test-Path $uploadDir) { - Remove-Item -Recurse -Force $uploadDir - } - ''' + success { + script { + def zipFilename = readFile("${params.buildPath}/created_zip.txt").trim() + echo "Pipeline completed successfully. Final zip: ${zipFilename}" + } } - failure { - echo 'Pipeline failed. Check logs for details.' + echo "Pipeline failed." } } } From 80e1877c181e5b87bd8ab26c1bcc61e20b4cd66f Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Wed, 7 May 2025 18:49:17 +0300 Subject: [PATCH 63/85] 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 { From e6ab8bde47e007c5717f8269387c87885c6cbb85 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Wed, 7 May 2025 19:06:57 +0300 Subject: [PATCH 64/85] pipelines zip and gdrive upload updated --- build/jenkins/GDriveUpload | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index 7dc713c..9301298 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -27,7 +27,7 @@ pipeline { // Example (placeholder): powershell """ echo Uploading ${zipFilename} to Google Drive... - # rclone copy \"${zipFilename}\" remote:\"${env.GOOGLE_DRIVE_FOLDER}\" + rclone copy \"${zipFilename}\" remote:\"${env.GOOGLE_DRIVE_FOLDER}\" """ } } From 66632a97c16b2f646a0ad89e8e792d2c00434bd4 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Wed, 7 May 2025 19:10:55 +0300 Subject: [PATCH 65/85] pipelines zip and gdrive upload updated --- build/jenkins/GDriveUpload | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index 9301298..eb0b39d 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -17,17 +17,36 @@ pipeline { 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 in ${params.buildPath}" } - echo "Uploading '${zipFilename}' to Google Drive folder '${env.GOOGLE_DRIVE_FOLDER}'..." + // Check if file already exists on Google Drive + def alreadyExists = powershell(script: """ + \$result = rclone ls remote:\"${env.GOOGLE_DRIVE_FOLDER}\" | Select-String "${zipFilename}" + if (\$result) { return 1 } else { return 0 } + """, returnStatus: true) == 1 - // Add actual upload logic here (e.g., gsutil, rclone, or API) - // Example (placeholder): + if (alreadyExists) { + echo "Zip file '${zipFilename}' already exists on Google Drive. Skipping upload." + } else { + echo "Uploading '${zipFilename}' to Google Drive folder '${env.GOOGLE_DRIVE_FOLDER}'..." + powershell """ + rclone copy \"${zipFilename}\" remote:\"${env.GOOGLE_DRIVE_FOLDER}\" + """ + } + + // Retention logic – keep only latest 5 ZIPs + echo "Cleaning up old ZIP files in Google Drive..." powershell """ - echo Uploading ${zipFilename} to Google Drive... - rclone copy \"${zipFilename}\" remote:\"${env.GOOGLE_DRIVE_FOLDER}\" + \$files = rclone lsf --files-only --format "t" --max-age 365d remote:\"${env.GOOGLE_DRIVE_FOLDER}\" | Sort-Object | Where-Object { \$_ -like "*.zip" } + if (\$files.Count -gt 5) { + \$filesToDelete = \$files | Select-Object -First (\$files.Count - 5) + foreach (\$file in \$filesToDelete) { + rclone delete remote:\"${env.GOOGLE_DRIVE_FOLDER}/\$file\" + } + } """ } } From 7fff1d9af4c40553c99c8efb5b74ed44316a508a Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Wed, 7 May 2025 19:14:09 +0300 Subject: [PATCH 66/85] pipelines zip and gdrive upload updated --- build/jenkins/GDriveUpload | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index eb0b39d..b0958e3 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -22,9 +22,12 @@ pipeline { error "Zip file '${zipFilename}' not found in ${params.buildPath}" } - // Check if file already exists on Google Drive + // Replace 'your-working-remote' with your actual working rclone remote name + def remoteName = 'your-working-remote' + + // Check if file already exists def alreadyExists = powershell(script: """ - \$result = rclone ls remote:\"${env.GOOGLE_DRIVE_FOLDER}\" | Select-String "${zipFilename}" + \$result = rclone ls ${remoteName}:${env.GOOGLE_DRIVE_FOLDER} | Select-String "${zipFilename}" if (\$result) { return 1 } else { return 0 } """, returnStatus: true) == 1 @@ -33,18 +36,18 @@ pipeline { } else { echo "Uploading '${zipFilename}' to Google Drive folder '${env.GOOGLE_DRIVE_FOLDER}'..." powershell """ - rclone copy \"${zipFilename}\" remote:\"${env.GOOGLE_DRIVE_FOLDER}\" + rclone copy \"${zipFilename}\" ${remoteName}:${env.GOOGLE_DRIVE_FOLDER} """ } - // Retention logic – keep only latest 5 ZIPs + // Retention: keep only latest 5 echo "Cleaning up old ZIP files in Google Drive..." powershell """ - \$files = rclone lsf --files-only --format "t" --max-age 365d remote:\"${env.GOOGLE_DRIVE_FOLDER}\" | Sort-Object | Where-Object { \$_ -like "*.zip" } + \$files = rclone lsf --files-only ${remoteName}:${env.GOOGLE_DRIVE_FOLDER} | Sort-Object if (\$files.Count -gt 5) { \$filesToDelete = \$files | Select-Object -First (\$files.Count - 5) foreach (\$file in \$filesToDelete) { - rclone delete remote:\"${env.GOOGLE_DRIVE_FOLDER}/\$file\" + rclone delete ${remoteName}:${env.GOOGLE_DRIVE_FOLDER}/\$file } } """ From 64c99d88ecb4320244015d99f6199d69321e8241 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Wed, 7 May 2025 19:20:27 +0300 Subject: [PATCH 67/85] pipelines zip and gdrive upload updated --- build/jenkins/GDriveUpload | 168 ++++++++++++++++++++++++++++--------- 1 file changed, 127 insertions(+), 41 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index b0958e3..db9fcb3 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -1,68 +1,154 @@ pipeline { agent { label 'Win10-BuildMachine' } + tools { + git 'Default' + } + parameters { - string(name: 'buildPath', defaultValue: 'C:/Jenkins/workspace/Azaion/suite', description: 'Path where the zip file is located') + string(name: 'buildPath', defaultValue: 'C:/Jenkins/workspace/AzaionSuite/suite', description: 'Path to folder containing zip builds.') } environment { + RCLONE_CONFIG = 'C:/Program Files/rclone/rclone.conf' GOOGLE_DRIVE_FOLDER = 'AzaionSuiteBuilds' } stages { - stage('Upload to Google Drive') { + stage('Initialize Workspace') { + steps { + echo 'Initializing workspace on Windows agent...' + powershell ''' + $uploadDir = "temp_upload" + if (-Not (Test-Path $uploadDir)) { + New-Item -ItemType Directory -Path $uploadDir | Out-Null + } + ''' + } + } + + stage('Find Latest Zip') { steps { script { - echo "Looking for ZIP in: ${params.buildPath}" - echo "Target Google Drive folder: ${env.GOOGLE_DRIVE_FOLDER}" + echo "Finding latest zip file in: ${params.buildPath}" dir("${params.buildPath}") { - def zipFilename = readFile('created_zip.txt').trim() - - if (!fileExists(zipFilename)) { - error "Zip file '${zipFilename}' not found in ${params.buildPath}" - } - - // Replace 'your-working-remote' with your actual working rclone remote name - def remoteName = 'your-working-remote' - - // Check if file already exists - def alreadyExists = powershell(script: """ - \$result = rclone ls ${remoteName}:${env.GOOGLE_DRIVE_FOLDER} | Select-String "${zipFilename}" - if (\$result) { return 1 } else { return 0 } - """, returnStatus: true) == 1 - - if (alreadyExists) { - echo "Zip file '${zipFilename}' already exists on Google Drive. Skipping upload." - } else { - echo "Uploading '${zipFilename}' to Google Drive folder '${env.GOOGLE_DRIVE_FOLDER}'..." - powershell """ - rclone copy \"${zipFilename}\" ${remoteName}:${env.GOOGLE_DRIVE_FOLDER} - """ - } - - // Retention: keep only latest 5 - echo "Cleaning up old ZIP files in Google Drive..." - powershell """ - \$files = rclone lsf --files-only ${remoteName}:${env.GOOGLE_DRIVE_FOLDER} | Sort-Object - if (\$files.Count -gt 5) { - \$filesToDelete = \$files | Select-Object -First (\$files.Count - 5) - foreach (\$file in \$filesToDelete) { - rclone delete ${remoteName}:${env.GOOGLE_DRIVE_FOLDER}/\$file - } + def output = powershell(returnStdout: true, script: ''' + $pattern = "AzaionSuite*-*-*.zip" + $zipFiles = Get-ChildItem -Filter $pattern | Sort-Object Name -Descending + if ($zipFiles.Count -gt 0) { + $latestZip = $zipFiles[0].Name + Write-Output "::SET-ENV::LATEST_ZIP_FILENAME=$latestZip" + } else { + Write-Output "::SET-ENV::LATEST_ZIP_FILENAME=" } - """ + ''').trim() + + def match = output =~ /::SET-ENV::LATEST_ZIP_FILENAME=(.+)/ + if (!match || !match[0][1]?.trim()) { + echo "⚠️ No ZIP files matching the pattern were found. Skipping upload and cleanup stages." + env.LATEST_ZIP_FILENAME = '' + } else { + def zipFileName = match[0][1] + echo "✅ Latest zip file selected: ${zipFileName}" + env.LATEST_ZIP_FILENAME = zipFileName + } } } } } + + stage('Upload If Not Exists & Always Remove Local') { + when { + expression { return env.LATEST_ZIP_FILENAME?.trim() } + } + steps { + echo "Checking Google Drive for existing ZIP and uploading if needed..." + powershell """ + \$fileName = "${env.LATEST_ZIP_FILENAME}" + \$folder = "${env.GOOGLE_DRIVE_FOLDER}" + \$rcloneRemote = "AzaionGoogleDrive:\$folder" + \$localFilePath = "${params.buildPath}/\$fileName" + + Write-Output "Checking for existing files in: \$rcloneRemote" + \$existingFiles = rclone lsf --files-only \$rcloneRemote + Write-Output "Existing files:" + Write-Output \$existingFiles + + if (\$existingFiles -match "^\$fileName\$") { + Write-Output "File '\$fileName' already exists on Google Drive. Skipping upload." + } else { + Write-Output "Uploading '\$fileName' to Google Drive..." + rclone copy "\$localFilePath" \$rcloneRemote --progress --drive-chunk-size 64M + Write-Output "Upload complete." + } + + if (Test-Path \$localFilePath) { + Remove-Item -Force \$localFilePath + Write-Output "Local file deleted: \$localFilePath" + } else { + Write-Output "Local file already deleted or not found." + } + """ + } + } + + stage('Cleanup Older Files on Google Drive') { + when { + expression { return env.LATEST_ZIP_FILENAME?.trim() } + } + steps { + echo "Cleaning up older files on Google Drive..." + powershell """ + Write-Output "Listing all files in the folder ${env.GOOGLE_DRIVE_FOLDER} on Google Drive..." + \$files = rclone lsf --files-only AzaionGoogleDrive:${env.GOOGLE_DRIVE_FOLDER} + Write-Output "Files found on Google Drive:" + Write-Output \$files + + \$filesArray = \$files -split "`n" | Where-Object { \$_ -ne "" } + if (\$filesArray.Count -gt 3) { + \$filesSorted = \$filesArray | Sort-Object -Descending + \$filesToDelete = \$filesSorted | Select-Object -Skip 3 + + Write-Output "Files to delete (older than 3 latest):" + Write-Output \$filesToDelete + + if (\$filesToDelete.Count -gt 0) { + \$tempFile = [System.IO.Path]::GetTempFileName() + \$filesToDelete | Set-Content -Path \$tempFile -Encoding utf8 + + Write-Output "Contents of temporary delete list file (\$tempFile):" + Get-Content \$tempFile + + foreach (\$file in \$filesToDelete) { + Write-Output "Deleting \$file..." + rclone deletefile AzaionGoogleDrive:${env.GOOGLE_DRIVE_FOLDER}/\$file + } + + Remove-Item -Path \$tempFile + } else { + Write-Output "No files to delete." + } + } else { + Write-Output "No files found on Google Drive to clean up." + } + """ + } + } } post { - success { - echo "Upload completed." + always { + echo 'Executing post-build cleanup...' + powershell ''' + $uploadDir = "temp_upload" + if (Test-Path $uploadDir) { + Remove-Item -Recurse -Force $uploadDir + } + ''' } + failure { - echo "Upload failed." + echo 'Pipeline failed. Check logs for details.' } } } From f7dd087fadc473cc59850d0bc275b006e2d11e5f Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Wed, 7 May 2025 19:25:30 +0300 Subject: [PATCH 68/85] pipelines zip and gdrive upload updated --- build/jenkins/GDriveUpload | 72 ++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index db9fcb3..24e7cea 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -92,48 +92,52 @@ pipeline { } } - stage('Cleanup Older Files on Google Drive') { - when { - expression { return env.LATEST_ZIP_FILENAME?.trim() } - } - steps { - echo "Cleaning up older files on Google Drive..." - powershell """ - Write-Output "Listing all files in the folder ${env.GOOGLE_DRIVE_FOLDER} on Google Drive..." - \$files = rclone lsf --files-only AzaionGoogleDrive:${env.GOOGLE_DRIVE_FOLDER} - Write-Output "Files found on Google Drive:" - Write-Output \$files +stage('Cleanup Older Files on Google Drive') { + when { + expression { return env.LATEST_ZIP_FILENAME?.trim() } + } + steps { + echo "Cleaning up older files on Google Drive..." + powershell """ + Write-Output "Listing all files in the folder ${params.GOOGLE_DRIVE_FOLDER} on Google Drive..." + \$files = rclone lsf --files-only AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} + Write-Output "Files found on Google Drive:" + Write-Output \$files - \$filesArray = \$files -split "`n" | Where-Object { \$_ -ne "" } - if (\$filesArray.Count -gt 3) { - \$filesSorted = \$filesArray | Sort-Object -Descending - \$filesToDelete = \$filesSorted | Select-Object -Skip 3 + \$filesArray = \$files -split "`n" | Where-Object { \$_ -ne "" } + # Exclude the latest zip file from deletion + \$latestFile = "${env.LATEST_ZIP_FILENAME}" + \$filesArray = \$filesArray | Where-Object { \$_ -ne \$latestFile } - Write-Output "Files to delete (older than 3 latest):" - Write-Output \$filesToDelete + if (\$filesArray.Count -gt 3) { + \$filesSorted = \$filesArray | Sort-Object -Descending + \$filesToDelete = \$filesSorted | Select-Object -Skip 3 - if (\$filesToDelete.Count -gt 0) { - \$tempFile = [System.IO.Path]::GetTempFileName() - \$filesToDelete | Set-Content -Path \$tempFile -Encoding utf8 + Write-Output "Files to delete (older than 3 latest):" + Write-Output \$filesToDelete - Write-Output "Contents of temporary delete list file (\$tempFile):" - Get-Content \$tempFile + if (\$filesToDelete.Count -gt 0) { + \$tempFile = [System.IO.Path]::GetTempFileName() + \$filesToDelete | Set-Content -Path \$tempFile -Encoding utf8 - foreach (\$file in \$filesToDelete) { - Write-Output "Deleting \$file..." - rclone deletefile AzaionGoogleDrive:${env.GOOGLE_DRIVE_FOLDER}/\$file - } + Write-Output "Contents of temporary delete list file (\$tempFile):" + Get-Content \$tempFile - Remove-Item -Path \$tempFile - } else { - Write-Output "No files to delete." - } - } else { - Write-Output "No files found on Google Drive to clean up." + foreach (\$file in \$filesToDelete) { + Write-Output "Deleting \$file..." + rclone deletefile AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER}/\$file } - """ + + Remove-Item -Path \$tempFile + } else { + Write-Output "No files to delete." + } + } else { + Write-Output "No files found on Google Drive to clean up." } - } + """ + } +} } post { From e82c3f5bcb5039f9ddcf6ff5a86fd0407bc4de2e Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Wed, 7 May 2025 19:27:36 +0300 Subject: [PATCH 69/85] pipelines zip and gdrive upload updated --- build/jenkins/GDriveUpload | 210 ++++++++++++++++--------------------- 1 file changed, 92 insertions(+), 118 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index 24e7cea..278e03b 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -1,158 +1,132 @@ pipeline { - agent { label 'Win10-BuildMachine' } - - tools { - git 'Default' - } - - parameters { - string(name: 'buildPath', defaultValue: 'C:/Jenkins/workspace/AzaionSuite/suite', description: 'Path to folder containing zip builds.') - } + agent any environment { - RCLONE_CONFIG = 'C:/Program Files/rclone/rclone.conf' - GOOGLE_DRIVE_FOLDER = 'AzaionSuiteBuilds' + GOOGLE_DRIVE_FOLDER = 'AzaionSuiteBuilds' // Hardcoded folder name + LATEST_ZIP_FILENAME = '' // Will be set during the "Find Latest Zip" stage } stages { + stage('Declarative: Checkout SCM') { + steps { + checkout scm + } + } + + stage('Declarative: Tool Install') { + steps { + // Ensure required tools are available, like Git, PowerShell, etc. + echo "Installing tools if necessary" + } + } + stage('Initialize Workspace') { steps { - echo 'Initializing workspace on Windows agent...' - powershell ''' - $uploadDir = "temp_upload" - if (-Not (Test-Path $uploadDir)) { - New-Item -ItemType Directory -Path $uploadDir | Out-Null - } - ''' + echo "Initializing workspace on Windows agent..." + // Initialization steps for workspace } } stage('Find Latest Zip') { steps { script { - echo "Finding latest zip file in: ${params.buildPath}" - dir("${params.buildPath}") { - def output = powershell(returnStdout: true, script: ''' - $pattern = "AzaionSuite*-*-*.zip" - $zipFiles = Get-ChildItem -Filter $pattern | Sort-Object Name -Descending - if ($zipFiles.Count -gt 0) { - $latestZip = $zipFiles[0].Name - Write-Output "::SET-ENV::LATEST_ZIP_FILENAME=$latestZip" - } else { - Write-Output "::SET-ENV::LATEST_ZIP_FILENAME=" - } - ''').trim() - - def match = output =~ /::SET-ENV::LATEST_ZIP_FILENAME=(.+)/ - if (!match || !match[0][1]?.trim()) { - echo "⚠️ No ZIP files matching the pattern were found. Skipping upload and cleanup stages." - env.LATEST_ZIP_FILENAME = '' - } else { - def zipFileName = match[0][1] - echo "✅ Latest zip file selected: ${zipFileName}" - env.LATEST_ZIP_FILENAME = zipFileName - } + echo "Finding latest zip file in: C:/Jenkins/workspace/Azaion/suite" + dir('C:/Jenkins/workspace/Azaion/suite') { + def latestZip = sh(script: 'ls -t *.zip | head -n 1', returnStdout: true).trim() + env.LATEST_ZIP_FILENAME = latestZip + echo "✅ Latest zip file selected: ${env.LATEST_ZIP_FILENAME}" } } } } stage('Upload If Not Exists & Always Remove Local') { - when { - expression { return env.LATEST_ZIP_FILENAME?.trim() } - } steps { echo "Checking Google Drive for existing ZIP and uploading if needed..." powershell """ - \$fileName = "${env.LATEST_ZIP_FILENAME}" - \$folder = "${env.GOOGLE_DRIVE_FOLDER}" - \$rcloneRemote = "AzaionGoogleDrive:\$folder" - \$localFilePath = "${params.buildPath}/\$fileName" - - Write-Output "Checking for existing files in: \$rcloneRemote" - \$existingFiles = rclone lsf --files-only \$rcloneRemote - Write-Output "Existing files:" - Write-Output \$existingFiles - - if (\$existingFiles -match "^\$fileName\$") { - Write-Output "File '\$fileName' already exists on Google Drive. Skipping upload." + # Check if file exists on Google Drive + \$existingFiles = rclone lsf --files-only AzaionGoogleDrive:${GOOGLE_DRIVE_FOLDER} + if (\$existingFiles -contains "${LATEST_ZIP_FILENAME}") { + Write-Output "File ${LATEST_ZIP_FILENAME} already exists on Google Drive, skipping upload." } else { - Write-Output "Uploading '\$fileName' to Google Drive..." - rclone copy "\$localFilePath" \$rcloneRemote --progress --drive-chunk-size 64M - Write-Output "Upload complete." + Write-Output "Uploading ${LATEST_ZIP_FILENAME} to Google Drive..." + rclone copy C:/Jenkins/workspace/Azaion/suite/${LATEST_ZIP_FILENAME} AzaionGoogleDrive:${GOOGLE_DRIVE_FOLDER} } - if (Test-Path \$localFilePath) { - Remove-Item -Force \$localFilePath - Write-Output "Local file deleted: \$localFilePath" + # Always remove the local file after uploading + Remove-Item "C:/Jenkins/workspace/Azaion/suite/${LATEST_ZIP_FILENAME}" + """ + } + } + + stage('Cleanup Older Files on Google Drive') { + steps { + echo "Cleaning up older files on Google Drive..." + powershell """ + # Check if folder exists + if (-not (Test-Path "AzaionGoogleDrive:${GOOGLE_DRIVE_FOLDER}")) { + Write-Error "Google Drive folder ${GOOGLE_DRIVE_FOLDER} not found!" + exit 1 + } + + # List all files in the Google Drive folder + Write-Output "Listing all files in the folder ${GOOGLE_DRIVE_FOLDER} on Google Drive..." + \$files = rclone lsf --files-only AzaionGoogleDrive:${GOOGLE_DRIVE_FOLDER} + Write-Output "Files found on Google Drive:" + Write-Output \$files + + # Split files by line and exclude the latest zip file + \$filesArray = \$files -split "`n" | Where-Object { \$_ -ne "" } + \$latestFile = "${LATEST_ZIP_FILENAME}" + \$filesArray = \$filesArray | Where-Object { \$_ -ne \$latestFile } + + # If more than 3 files exist, delete the oldest ones + if (\$filesArray.Count -gt 3) { + \$filesSorted = \$filesArray | Sort-Object -Descending + \$filesToDelete = \$filesSorted | Select-Object -Skip 3 + + Write-Output "Files to delete (older than 3 latest):" + Write-Output \$filesToDelete + + if (\$filesToDelete.Count -gt 0) { + # Create temporary delete list file + \$tempFile = [System.IO.Path]::GetTempFileName() + \$filesToDelete | Set-Content -Path \$tempFile -Encoding utf8 + + Write-Output "Contents of temporary delete list file (\$tempFile):" + Get-Content \$tempFile + + # Delete files listed for removal + foreach (\$file in \$filesToDelete) { + Write-Output "Deleting \$file..." + rclone deletefile AzaionGoogleDrive:${GOOGLE_DRIVE_FOLDER}/\$file + } + + Remove-Item -Path \$tempFile + } else { + Write-Output "No files to delete." + } } else { - Write-Output "Local file already deleted or not found." + Write-Output "No files found on Google Drive to clean up." } """ } } -stage('Cleanup Older Files on Google Drive') { - when { - expression { return env.LATEST_ZIP_FILENAME?.trim() } - } - steps { - echo "Cleaning up older files on Google Drive..." - powershell """ - Write-Output "Listing all files in the folder ${params.GOOGLE_DRIVE_FOLDER} on Google Drive..." - \$files = rclone lsf --files-only AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER} - Write-Output "Files found on Google Drive:" - Write-Output \$files - - \$filesArray = \$files -split "`n" | Where-Object { \$_ -ne "" } - # Exclude the latest zip file from deletion - \$latestFile = "${env.LATEST_ZIP_FILENAME}" - \$filesArray = \$filesArray | Where-Object { \$_ -ne \$latestFile } - - if (\$filesArray.Count -gt 3) { - \$filesSorted = \$filesArray | Sort-Object -Descending - \$filesToDelete = \$filesSorted | Select-Object -Skip 3 - - Write-Output "Files to delete (older than 3 latest):" - Write-Output \$filesToDelete - - if (\$filesToDelete.Count -gt 0) { - \$tempFile = [System.IO.Path]::GetTempFileName() - \$filesToDelete | Set-Content -Path \$tempFile -Encoding utf8 - - Write-Output "Contents of temporary delete list file (\$tempFile):" - Get-Content \$tempFile - - foreach (\$file in \$filesToDelete) { - Write-Output "Deleting \$file..." - rclone deletefile AzaionGoogleDrive:${params.GOOGLE_DRIVE_FOLDER}/\$file - } - - Remove-Item -Path \$tempFile - } else { - Write-Output "No files to delete." - } - } else { - Write-Output "No files found on Google Drive to clean up." + stage('Declarative: Post Actions') { + steps { + echo "Executing post-build cleanup..." + // Clean up any resources after the pipeline run } - """ - } -} + } } post { - always { - echo 'Executing post-build cleanup...' - powershell ''' - $uploadDir = "temp_upload" - if (Test-Path $uploadDir) { - Remove-Item -Recurse -Force $uploadDir - } - ''' - } - failure { - echo 'Pipeline failed. Check logs for details.' + echo "Pipeline failed. Check logs for details." + } + success { + echo "Pipeline completed successfully." } } } From 5c3fa80a177111eb76b78feb9ac7e1c0e9478399 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Wed, 7 May 2025 19:31:28 +0300 Subject: [PATCH 70/85] pipelines zip and gdrive upload updated --- build/jenkins/GDriveUpload | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index 278e03b..5ebb9a0 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -32,7 +32,8 @@ pipeline { script { echo "Finding latest zip file in: C:/Jenkins/workspace/Azaion/suite" dir('C:/Jenkins/workspace/Azaion/suite') { - def latestZip = sh(script: 'ls -t *.zip | head -n 1', returnStdout: true).trim() + // Find the latest zip file using shell command + def latestZip = bat(script: 'dir /b /od *.zip | findstr /r /c:"AzaionSuite.Iterative.*.zip"', returnStdout: true).trim() env.LATEST_ZIP_FILENAME = latestZip echo "✅ Latest zip file selected: ${env.LATEST_ZIP_FILENAME}" } @@ -46,15 +47,15 @@ pipeline { powershell """ # Check if file exists on Google Drive \$existingFiles = rclone lsf --files-only AzaionGoogleDrive:${GOOGLE_DRIVE_FOLDER} - if (\$existingFiles -contains "${LATEST_ZIP_FILENAME}") { - Write-Output "File ${LATEST_ZIP_FILENAME} already exists on Google Drive, skipping upload." + if (\$existingFiles -contains "${env.LATEST_ZIP_FILENAME}") { + Write-Output "File ${env.LATEST_ZIP_FILENAME} already exists on Google Drive, skipping upload." } else { - Write-Output "Uploading ${LATEST_ZIP_FILENAME} to Google Drive..." - rclone copy C:/Jenkins/workspace/Azaion/suite/${LATEST_ZIP_FILENAME} AzaionGoogleDrive:${GOOGLE_DRIVE_FOLDER} + Write-Output "Uploading ${env.LATEST_ZIP_FILENAME} to Google Drive..." + rclone copy C:/Jenkins/workspace/Azaion/suite/${env.LATEST_ZIP_FILENAME} AzaionGoogleDrive:${GOOGLE_DRIVE_FOLDER} } # Always remove the local file after uploading - Remove-Item "C:/Jenkins/workspace/Azaion/suite/${LATEST_ZIP_FILENAME}" + Remove-Item "C:/Jenkins/workspace/Azaion/suite/${env.LATEST_ZIP_FILENAME}" """ } } @@ -77,7 +78,7 @@ pipeline { # Split files by line and exclude the latest zip file \$filesArray = \$files -split "`n" | Where-Object { \$_ -ne "" } - \$latestFile = "${LATEST_ZIP_FILENAME}" + \$latestFile = "${env.LATEST_ZIP_FILENAME}" \$filesArray = \$filesArray | Where-Object { \$_ -ne \$latestFile } # If more than 3 files exist, delete the oldest ones @@ -112,13 +113,6 @@ pipeline { """ } } - - stage('Declarative: Post Actions') { - steps { - echo "Executing post-build cleanup..." - // Clean up any resources after the pipeline run - } - } } post { From 81620888f2e78539fad78dc1aeb7a8a3fdf8d103 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Wed, 7 May 2025 19:33:44 +0300 Subject: [PATCH 71/85] pipelines zip and gdrive upload updated --- build/jenkins/GDriveUpload | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index 5ebb9a0..b4ea2aa 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -32,10 +32,19 @@ pipeline { script { echo "Finding latest zip file in: C:/Jenkins/workspace/Azaion/suite" dir('C:/Jenkins/workspace/Azaion/suite') { - // Find the latest zip file using shell command - def latestZip = bat(script: 'dir /b /od *.zip | findstr /r /c:"AzaionSuite.Iterative.*.zip"', returnStdout: true).trim() - env.LATEST_ZIP_FILENAME = latestZip - echo "✅ Latest zip file selected: ${env.LATEST_ZIP_FILENAME}" + // Debug output to confirm current directory contents + echo "Listing .zip files in the directory:" + bat(script: 'dir /b *.zip', returnStdout: true).trim() + + // Get the most recent .zip file based on modification date + def latestZip = bat(script: 'dir /b /od *.zip | head -n 1', returnStdout: true).trim() + + if (latestZip) { + env.LATEST_ZIP_FILENAME = latestZip + echo "✅ Latest zip file selected: ${env.LATEST_ZIP_FILENAME}" + } else { + error "No valid zip files found in the directory!" + } } } } @@ -47,15 +56,15 @@ pipeline { powershell """ # Check if file exists on Google Drive \$existingFiles = rclone lsf --files-only AzaionGoogleDrive:${GOOGLE_DRIVE_FOLDER} - if (\$existingFiles -contains "${env.LATEST_ZIP_FILENAME}") { - Write-Output "File ${env.LATEST_ZIP_FILENAME} already exists on Google Drive, skipping upload." + if (\$existingFiles -contains "${LATEST_ZIP_FILENAME}") { + Write-Output "File ${LATEST_ZIP_FILENAME} already exists on Google Drive, skipping upload." } else { - Write-Output "Uploading ${env.LATEST_ZIP_FILENAME} to Google Drive..." - rclone copy C:/Jenkins/workspace/Azaion/suite/${env.LATEST_ZIP_FILENAME} AzaionGoogleDrive:${GOOGLE_DRIVE_FOLDER} + Write-Output "Uploading ${LATEST_ZIP_FILENAME} to Google Drive..." + rclone copy C:/Jenkins/workspace/Azaion/suite/${LATEST_ZIP_FILENAME} AzaionGoogleDrive:${GOOGLE_DRIVE_FOLDER} } # Always remove the local file after uploading - Remove-Item "C:/Jenkins/workspace/Azaion/suite/${env.LATEST_ZIP_FILENAME}" + Remove-Item "C:/Jenkins/workspace/Azaion/suite/${LATEST_ZIP_FILENAME}" """ } } @@ -78,7 +87,7 @@ pipeline { # Split files by line and exclude the latest zip file \$filesArray = \$files -split "`n" | Where-Object { \$_ -ne "" } - \$latestFile = "${env.LATEST_ZIP_FILENAME}" + \$latestFile = "${LATEST_ZIP_FILENAME}" \$filesArray = \$filesArray | Where-Object { \$_ -ne \$latestFile } # If more than 3 files exist, delete the oldest ones From d1520109efbec0e51283e5d30ef9464e22160f67 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Wed, 7 May 2025 19:36:40 +0300 Subject: [PATCH 72/85] pipelines zip and gdrive upload updated --- build/jenkins/GDriveUpload | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index b4ea2aa..a88eca7 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -15,7 +15,6 @@ pipeline { stage('Declarative: Tool Install') { steps { - // Ensure required tools are available, like Git, PowerShell, etc. echo "Installing tools if necessary" } } @@ -23,7 +22,6 @@ pipeline { stage('Initialize Workspace') { steps { echo "Initializing workspace on Windows agent..." - // Initialization steps for workspace } } @@ -32,19 +30,22 @@ pipeline { script { echo "Finding latest zip file in: C:/Jenkins/workspace/Azaion/suite" dir('C:/Jenkins/workspace/Azaion/suite') { - // Debug output to confirm current directory contents - echo "Listing .zip files in the directory:" - bat(script: 'dir /b *.zip', returnStdout: true).trim() + // List all .zip files starting with "AzaionSuite" + def zipFiles = bat(script: 'dir /b AzaionSuite*.zip', returnStdout: true).trim().split("\n") - // Get the most recent .zip file based on modification date - def latestZip = bat(script: 'dir /b /od *.zip | head -n 1', returnStdout: true).trim() - - if (latestZip) { - env.LATEST_ZIP_FILENAME = latestZip - echo "✅ Latest zip file selected: ${env.LATEST_ZIP_FILENAME}" - } else { - error "No valid zip files found in the directory!" + if (zipFiles.isEmpty()) { + error "No zip files found matching the pattern 'AzaionSuite*.zip'!" } + + // Sort the files by date (timestamp) in the filename + def latestZip = zipFiles.sort { a, b -> + def dateA = a.split('-')[1] + def dateB = b.split('-')[1] + return dateB.compareTo(dateA) + }.first() + + env.LATEST_ZIP_FILENAME = latestZip + echo "✅ Latest zip file selected: ${env.LATEST_ZIP_FILENAME}" } } } From e0fd55d908877c3dcb4a0c1e9eee2362e57ecbd1 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Wed, 7 May 2025 19:38:49 +0300 Subject: [PATCH 73/85] pipelines zip and gdrive upload updated --- build/jenkins/GDriveUpload | 135 +++++++++++++++++++++---------------- 1 file changed, 77 insertions(+), 58 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index a88eca7..019e4fd 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -1,97 +1,111 @@ pipeline { - agent any + agent { label 'Win10-BuildMachine' } + + tools { + git 'Default' + } + + parameters { + string(name: 'buildPath', defaultValue: 'C:/Jenkins/workspace/AzaionSuite/suite', description: 'Path to folder containing zip builds.') + } environment { - GOOGLE_DRIVE_FOLDER = 'AzaionSuiteBuilds' // Hardcoded folder name - LATEST_ZIP_FILENAME = '' // Will be set during the "Find Latest Zip" stage + GOOGLE_DRIVE_FOLDER = 'AzaionSuiteBuilds' // Hardcoded folder on Google Drive + RCLONE_CONFIG = 'C:/Program Files/rclone/rclone.conf' + LATEST_ZIP_FILENAME = '' // Will be set during the "Find Latest Zip" stage } stages { - stage('Declarative: Checkout SCM') { - steps { - checkout scm - } - } - - stage('Declarative: Tool Install') { - steps { - echo "Installing tools if necessary" - } - } - stage('Initialize Workspace') { steps { - echo "Initializing workspace on Windows agent..." + echo 'Initializing workspace on Windows agent...' + powershell ''' + $uploadDir = "temp_upload" + if (-Not (Test-Path $uploadDir)) { + New-Item -ItemType Directory -Path $uploadDir | Out-Null + } + ''' } } stage('Find Latest Zip') { steps { script { - echo "Finding latest zip file in: C:/Jenkins/workspace/Azaion/suite" - dir('C:/Jenkins/workspace/Azaion/suite') { - // List all .zip files starting with "AzaionSuite" - def zipFiles = bat(script: 'dir /b AzaionSuite*.zip', returnStdout: true).trim().split("\n") + echo "Finding latest zip file in: ${params.buildPath}" + dir("${params.buildPath}") { + def output = powershell(returnStdout: true, script: ''' + $pattern = "AzaionSuite*.zip" + $zipFiles = Get-ChildItem -Filter $pattern | Sort-Object Name -Descending + if ($zipFiles.Count -gt 0) { + $latestZip = $zipFiles[0].Name + Write-Output "::SET-ENV::LATEST_ZIP_FILENAME=$latestZip" + } else { + Write-Output "::SET-ENV::LATEST_ZIP_FILENAME=" + } + ''').trim() - if (zipFiles.isEmpty()) { - error "No zip files found matching the pattern 'AzaionSuite*.zip'!" + def match = output =~ /::SET-ENV::LATEST_ZIP_FILENAME=(.+)/ + if (!match || !match[0][1]?.trim()) { + echo "⚠️ No ZIP files matching the pattern were found. Skipping upload and cleanup stages." + env.LATEST_ZIP_FILENAME = '' + } else { + def zipFileName = match[0][1] + echo "✅ Latest zip file selected: ${zipFileName}" + env.LATEST_ZIP_FILENAME = zipFileName } - - // Sort the files by date (timestamp) in the filename - def latestZip = zipFiles.sort { a, b -> - def dateA = a.split('-')[1] - def dateB = b.split('-')[1] - return dateB.compareTo(dateA) - }.first() - - env.LATEST_ZIP_FILENAME = latestZip - echo "✅ Latest zip file selected: ${env.LATEST_ZIP_FILENAME}" } } } } stage('Upload If Not Exists & Always Remove Local') { + when { + expression { return env.LATEST_ZIP_FILENAME?.trim() } + } steps { echo "Checking Google Drive for existing ZIP and uploading if needed..." powershell """ - # Check if file exists on Google Drive - \$existingFiles = rclone lsf --files-only AzaionGoogleDrive:${GOOGLE_DRIVE_FOLDER} - if (\$existingFiles -contains "${LATEST_ZIP_FILENAME}") { - Write-Output "File ${LATEST_ZIP_FILENAME} already exists on Google Drive, skipping upload." + \$fileName = "${env.LATEST_ZIP_FILENAME}" + \$folder = "${GOOGLE_DRIVE_FOLDER}" + \$rcloneRemote = "AzaionGoogleDrive:\$folder" + \$localFilePath = "${params.buildPath}/\$fileName" + + Write-Output "Checking for existing files in: \$rcloneRemote" + \$existingFiles = rclone lsf --files-only \$rcloneRemote + Write-Output "Existing files:" + Write-Output \$existingFiles + + if (\$existingFiles -match "^\$fileName\$") { + Write-Output "File '\$fileName' already exists on Google Drive. Skipping upload." } else { - Write-Output "Uploading ${LATEST_ZIP_FILENAME} to Google Drive..." - rclone copy C:/Jenkins/workspace/Azaion/suite/${LATEST_ZIP_FILENAME} AzaionGoogleDrive:${GOOGLE_DRIVE_FOLDER} + Write-Output "Uploading '\$fileName' to Google Drive..." + rclone copy "\$localFilePath" \$rcloneRemote --progress --drive-chunk-size 64M + Write-Output "Upload complete." } - # Always remove the local file after uploading - Remove-Item "C:/Jenkins/workspace/Azaion/suite/${LATEST_ZIP_FILENAME}" + if (Test-Path \$localFilePath) { + Remove-Item -Force \$localFilePath + Write-Output "Local file deleted: \$localFilePath" + } else { + Write-Output "Local file already deleted or not found." + } """ } } stage('Cleanup Older Files on Google Drive') { + when { + expression { return env.LATEST_ZIP_FILENAME?.trim() } + } steps { echo "Cleaning up older files on Google Drive..." powershell """ - # Check if folder exists - if (-not (Test-Path "AzaionGoogleDrive:${GOOGLE_DRIVE_FOLDER}")) { - Write-Error "Google Drive folder ${GOOGLE_DRIVE_FOLDER} not found!" - exit 1 - } - - # List all files in the Google Drive folder Write-Output "Listing all files in the folder ${GOOGLE_DRIVE_FOLDER} on Google Drive..." \$files = rclone lsf --files-only AzaionGoogleDrive:${GOOGLE_DRIVE_FOLDER} Write-Output "Files found on Google Drive:" Write-Output \$files - # Split files by line and exclude the latest zip file \$filesArray = \$files -split "`n" | Where-Object { \$_ -ne "" } - \$latestFile = "${LATEST_ZIP_FILENAME}" - \$filesArray = \$filesArray | Where-Object { \$_ -ne \$latestFile } - - # If more than 3 files exist, delete the oldest ones if (\$filesArray.Count -gt 3) { \$filesSorted = \$filesArray | Sort-Object -Descending \$filesToDelete = \$filesSorted | Select-Object -Skip 3 @@ -100,14 +114,12 @@ pipeline { Write-Output \$filesToDelete if (\$filesToDelete.Count -gt 0) { - # Create temporary delete list file \$tempFile = [System.IO.Path]::GetTempFileName() \$filesToDelete | Set-Content -Path \$tempFile -Encoding utf8 Write-Output "Contents of temporary delete list file (\$tempFile):" Get-Content \$tempFile - # Delete files listed for removal foreach (\$file in \$filesToDelete) { Write-Output "Deleting \$file..." rclone deletefile AzaionGoogleDrive:${GOOGLE_DRIVE_FOLDER}/\$file @@ -126,11 +138,18 @@ pipeline { } post { - failure { - echo "Pipeline failed. Check logs for details." + always { + echo 'Executing post-build cleanup...' + powershell ''' + $uploadDir = "temp_upload" + if (Test-Path $uploadDir) { + Remove-Item -Recurse -Force $uploadDir + } + ''' } - success { - echo "Pipeline completed successfully." + + failure { + echo 'Pipeline failed. Check logs for details.' } } } From 8df405c8986ccb87aa8f939f771b4eff0b3d43fa Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Wed, 7 May 2025 19:48:38 +0300 Subject: [PATCH 74/85] pipelines zip and gdrive upload updated --- build/jenkins/GDriveUpload | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index 019e4fd..a2bd911 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -44,6 +44,9 @@ pipeline { } ''').trim() + // Debug output to verify the response from the powershell script + echo "PowerShell output: ${output}" + def match = output =~ /::SET-ENV::LATEST_ZIP_FILENAME=(.+)/ if (!match || !match[0][1]?.trim()) { echo "⚠️ No ZIP files matching the pattern were found. Skipping upload and cleanup stages." @@ -60,7 +63,10 @@ pipeline { stage('Upload If Not Exists & Always Remove Local') { when { - expression { return env.LATEST_ZIP_FILENAME?.trim() } + expression { + echo "LATEST_ZIP_FILENAME is: '${env.LATEST_ZIP_FILENAME}'" // Debug output + return env.LATEST_ZIP_FILENAME?.trim() + } } steps { echo "Checking Google Drive for existing ZIP and uploading if needed..." @@ -95,7 +101,10 @@ pipeline { stage('Cleanup Older Files on Google Drive') { when { - expression { return env.LATEST_ZIP_FILENAME?.trim() } + expression { + echo "LATEST_ZIP_FILENAME is: '${env.LATEST_ZIP_FILENAME}'" // Debug output + return env.LATEST_ZIP_FILENAME?.trim() + } } steps { echo "Cleaning up older files on Google Drive..." From 27b90f2a7181a7be10ab390d1546fad7537a02b9 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Wed, 7 May 2025 19:49:16 +0300 Subject: [PATCH 75/85] pipelines zip and gdrive upload updated --- build/jenkins/GDriveUpload | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index a2bd911..22bad3d 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -6,7 +6,7 @@ pipeline { } parameters { - string(name: 'buildPath', defaultValue: 'C:/Jenkins/workspace/AzaionSuite/suite', description: 'Path to folder containing zip builds.') + string(name: 'buildPath', defaultValue: 'C:/Jenkins/workspace/Azaion//suite', description: 'Path to folder containing zip builds.') } environment { From f2c5490ff3bd84423e12d2cbb61b6c03fc5b4afc Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Wed, 7 May 2025 19:53:13 +0300 Subject: [PATCH 76/85] pipelines zip and gdrive upload updated --- build/jenkins/GDriveUpload | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index 22bad3d..91230c3 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -6,13 +6,12 @@ pipeline { } parameters { - string(name: 'buildPath', defaultValue: 'C:/Jenkins/workspace/Azaion//suite', description: 'Path to folder containing zip builds.') + string(name: 'buildPath', defaultValue: 'C:/Jenkins/workspace/Azaion/suite', description: 'Path to folder containing zip builds.') } environment { GOOGLE_DRIVE_FOLDER = 'AzaionSuiteBuilds' // Hardcoded folder on Google Drive RCLONE_CONFIG = 'C:/Program Files/rclone/rclone.conf' - LATEST_ZIP_FILENAME = '' // Will be set during the "Find Latest Zip" stage } stages { @@ -31,7 +30,9 @@ pipeline { stage('Find Latest Zip') { steps { script { + echo "Using build path: ${params.buildPath}" // Debug output for build path echo "Finding latest zip file in: ${params.buildPath}" + def latestZipFilename = '' dir("${params.buildPath}") { def output = powershell(returnStdout: true, script: ''' $pattern = "AzaionSuite*.zip" @@ -50,13 +51,15 @@ pipeline { def match = output =~ /::SET-ENV::LATEST_ZIP_FILENAME=(.+)/ if (!match || !match[0][1]?.trim()) { echo "⚠️ No ZIP files matching the pattern were found. Skipping upload and cleanup stages." - env.LATEST_ZIP_FILENAME = '' } else { - def zipFileName = match[0][1] - echo "✅ Latest zip file selected: ${zipFileName}" - env.LATEST_ZIP_FILENAME = zipFileName + latestZipFilename = match[0][1] + echo "✅ Latest zip file selected: ${latestZipFilename}" } } + + // Pass the filename to the next stages directly + env.LATEST_ZIP_FILENAME = latestZipFilename + echo "LATEST_ZIP_FILENAME after processing: ${env.LATEST_ZIP_FILENAME}" } } } From 9ae9265ff667ec08551ca309add4952ba6a10a28 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Wed, 7 May 2025 19:58:24 +0300 Subject: [PATCH 77/85] pipelines zip and gdrive upload updated --- build/jenkins/GDriveUpload | 57 ++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index 91230c3..b43f2a3 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -117,32 +117,47 @@ pipeline { Write-Output "Files found on Google Drive:" Write-Output \$files + # Extract date-time from filenames and sort them \$filesArray = \$files -split "`n" | Where-Object { \$_ -ne "" } - if (\$filesArray.Count -gt 3) { - \$filesSorted = \$filesArray | Sort-Object -Descending - \$filesToDelete = \$filesSorted | Select-Object -Skip 3 + \$filesWithDateTime = @() - Write-Output "Files to delete (older than 3 latest):" - Write-Output \$filesToDelete - - if (\$filesToDelete.Count -gt 0) { - \$tempFile = [System.IO.Path]::GetTempFileName() - \$filesToDelete | Set-Content -Path \$tempFile -Encoding utf8 - - Write-Output "Contents of temporary delete list file (\$tempFile):" - Get-Content \$tempFile - - foreach (\$file in \$filesToDelete) { - Write-Output "Deleting \$file..." - rclone deletefile AzaionGoogleDrive:${GOOGLE_DRIVE_FOLDER}/\$file + foreach (\$file in \$filesArray) { + if (\$file -match "AzaionSuite.Iterative.(\d{8})-(\d{6}).zip") { + \$date = [datetime]::ParseExact(\$matches[1], "yyyyMMdd", $null) + \$time = [datetime]::ParseExact(\$matches[2], "HHmmss", $null) + \$dateTime = \$date.Add(\$time.TimeOfDay) + \$filesWithDateTime += [PSCustomObject]@{ + FileName = \$file + DateTime = \$dateTime } - - Remove-Item -Path \$tempFile - } else { - Write-Output "No files to delete." } + } + + # Sort files based on DateTime in descending order + \$sortedFiles = \$filesWithDateTime | Sort-Object DateTime -Descending + Write-Output "Sorted files (newest to oldest):" + \$sortedFiles | ForEach-Object { Write-Output "\$($_.FileName)" } + + # Keep the latest 3 files and delete the rest + \$filesToDelete = \$sortedFiles | Select-Object -Skip 3 + Write-Output "Files to delete (older than 3 latest):" + \$filesToDelete | ForEach-Object { Write-Output "\$($_.FileName)" } + + if (\$filesToDelete.Count -gt 0) { + \$tempFile = [System.IO.Path]::GetTempFileName() + \$filesToDelete.FileName | Set-Content -Path \$tempFile -Encoding utf8 + + Write-Output "Contents of temporary delete list file (\$tempFile):" + Get-Content \$tempFile + + foreach (\$file in \$filesToDelete.FileName) { + Write-Output "Deleting \$file..." + rclone deletefile AzaionGoogleDrive:${GOOGLE_DRIVE_FOLDER}/\$file + } + + Remove-Item -Path \$tempFile } else { - Write-Output "No files found on Google Drive to clean up." + Write-Output "No files to delete." } """ } From bfeb888c553d4c9f40e4cde5ac49cc34adf7bf0d Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Wed, 7 May 2025 19:59:57 +0300 Subject: [PATCH 78/85] pipelines zip and gdrive upload updated --- build/jenkins/GDriveUpload | 137 ++++++++++++++----------------------- 1 file changed, 50 insertions(+), 87 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index b43f2a3..c726cb7 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -10,8 +10,9 @@ pipeline { } environment { - GOOGLE_DRIVE_FOLDER = 'AzaionSuiteBuilds' // Hardcoded folder on Google Drive - RCLONE_CONFIG = 'C:/Program Files/rclone/rclone.conf' + GOOGLE_DRIVE_FOLDER = 'AzaionSuiteBuilds' + RCLONE_CONFIG = 'C:/Program Files/rclone/rclone.conf' + LATEST_ZIP_FILENAME = '' // Will be set in Find Latest Zip } stages { @@ -30,36 +31,29 @@ pipeline { stage('Find Latest Zip') { steps { script { - echo "Using build path: ${params.buildPath}" // Debug output for build path - echo "Finding latest zip file in: ${params.buildPath}" - def latestZipFilename = '' + echo "Using build path: ${params.buildPath}" + def latestZip = '' dir("${params.buildPath}") { def output = powershell(returnStdout: true, script: ''' $pattern = "AzaionSuite*.zip" $zipFiles = Get-ChildItem -Filter $pattern | Sort-Object Name -Descending if ($zipFiles.Count -gt 0) { - $latestZip = $zipFiles[0].Name - Write-Output "::SET-ENV::LATEST_ZIP_FILENAME=$latestZip" + Write-Output "::SET-ENV::LATEST_ZIP_FILENAME=$($zipFiles[0].Name)" } else { Write-Output "::SET-ENV::LATEST_ZIP_FILENAME=" } ''').trim() - // Debug output to verify the response from the powershell script echo "PowerShell output: ${output}" - - def match = output =~ /::SET-ENV::LATEST_ZIP_FILENAME=(.+)/ - if (!match || !match[0][1]?.trim()) { - echo "⚠️ No ZIP files matching the pattern were found. Skipping upload and cleanup stages." + def m = (output =~ /::SET-ENV::LATEST_ZIP_FILENAME=(.+)/) + if (m && m[0][1]) { + latestZip = m[0][1] + echo "✅ Latest zip file selected: ${latestZip}" } else { - latestZipFilename = match[0][1] - echo "✅ Latest zip file selected: ${latestZipFilename}" + echo "⚠️ No zip found, skipping downstream stages." } } - - // Pass the filename to the next stages directly - env.LATEST_ZIP_FILENAME = latestZipFilename - echo "LATEST_ZIP_FILENAME after processing: ${env.LATEST_ZIP_FILENAME}" + env.LATEST_ZIP_FILENAME = latestZip } } } @@ -67,36 +61,32 @@ pipeline { stage('Upload If Not Exists & Always Remove Local') { when { expression { - echo "LATEST_ZIP_FILENAME is: '${env.LATEST_ZIP_FILENAME}'" // Debug output + echo "LATEST_ZIP_FILENAME is: '${env.LATEST_ZIP_FILENAME}'" return env.LATEST_ZIP_FILENAME?.trim() } } steps { - echo "Checking Google Drive for existing ZIP and uploading if needed..." + echo "Uploading ${env.LATEST_ZIP_FILENAME} if needed..." powershell """ - \$fileName = "${env.LATEST_ZIP_FILENAME}" - \$folder = "${GOOGLE_DRIVE_FOLDER}" + \$fileName = "${env.LATEST_ZIP_FILENAME}" + \$folder = "${GOOGLE_DRIVE_FOLDER}" \$rcloneRemote = "AzaionGoogleDrive:\$folder" - \$localFilePath = "${params.buildPath}/\$fileName" + \$localPath = "${params.buildPath}/\$fileName" - Write-Output "Checking for existing files in: \$rcloneRemote" - \$existingFiles = rclone lsf --files-only \$rcloneRemote - Write-Output "Existing files:" - Write-Output \$existingFiles + Write-Output "Existing on drive:" + \$existing = rclone lsf --files-only \$rcloneRemote + Write-Output \$existing - if (\$existingFiles -match "^\$fileName\$") { - Write-Output "File '\$fileName' already exists on Google Drive. Skipping upload." + if (\$existing -match "^\$fileName\$") { + Write-Output "Already exists; skipping upload." } else { - Write-Output "Uploading '\$fileName' to Google Drive..." - rclone copy "\$localFilePath" \$rcloneRemote --progress --drive-chunk-size 64M - Write-Output "Upload complete." + Write-Output "Uploading..." + rclone copy \$localPath \$rcloneRemote --drive-chunk-size 64M --progress } - if (Test-Path \$localFilePath) { - Remove-Item -Force \$localFilePath - Write-Output "Local file deleted: \$localFilePath" - } else { - Write-Output "Local file already deleted or not found." + if (Test-Path \$localPath) { + Remove-Item -Force \$localPath + Write-Output "Local deleted." } """ } @@ -105,59 +95,36 @@ pipeline { stage('Cleanup Older Files on Google Drive') { when { expression { - echo "LATEST_ZIP_FILENAME is: '${env.LATEST_ZIP_FILENAME}'" // Debug output + echo "LATEST_ZIP_FILENAME is: '${env.LATEST_ZIP_FILENAME}'" return env.LATEST_ZIP_FILENAME?.trim() } } steps { - echo "Cleaning up older files on Google Drive..." + echo "Cleaning up older files..." powershell """ - Write-Output "Listing all files in the folder ${GOOGLE_DRIVE_FOLDER} on Google Drive..." - \$files = rclone lsf --files-only AzaionGoogleDrive:${GOOGLE_DRIVE_FOLDER} - Write-Output "Files found on Google Drive:" - Write-Output \$files + \$folder = "${GOOGLE_DRIVE_FOLDER}" + \$files = rclone lsf --files-only AzaionGoogleDrive:\$folder | Where-Object { \$_ -match '^AzaionSuite.*\\.zip\$' } - # Extract date-time from filenames and sort them - \$filesArray = \$files -split "`n" | Where-Object { \$_ -ne "" } - \$filesWithDateTime = @() - - foreach (\$file in \$filesArray) { - if (\$file -match "AzaionSuite.Iterative.(\d{8})-(\d{6}).zip") { - \$date = [datetime]::ParseExact(\$matches[1], "yyyyMMdd", $null) - \$time = [datetime]::ParseExact(\$matches[2], "HHmmss", $null) - \$dateTime = \$date.Add(\$time.TimeOfDay) - \$filesWithDateTime += [PSCustomObject]@{ - FileName = \$file - DateTime = \$dateTime - } + # Build an array of objects with parsed DateTime + \$meta = foreach (\$f in \$files) { + if (\$f -match 'AzaionSuite\\.Iterative\\.(\\d{8})-(\\d{6})\\.zip') { + \$dt = [datetime]::ParseExact(\$matches[1] + \$matches[2], 'yyyyMMddHHmmss', \$null) + } elseif (\$f -match 'AzaionSuite1\\.\\d+\\.\\d+\\.\\d+-(\\d{8})-(\\d{6})\\.zip') { + \$dt = [datetime]::ParseExact(\$matches[1] + \$matches[2], 'yyyyMMddHHmmss', \$null) + } else { + # if it doesn't match expected formats, skip + continue } + [PSCustomObject]@{ Name = \$f; Date = \$dt } } - # Sort files based on DateTime in descending order - \$sortedFiles = \$filesWithDateTime | Sort-Object DateTime -Descending - Write-Output "Sorted files (newest to oldest):" - \$sortedFiles | ForEach-Object { Write-Output "\$($_.FileName)" } - - # Keep the latest 3 files and delete the rest - \$filesToDelete = \$sortedFiles | Select-Object -Skip 3 - Write-Output "Files to delete (older than 3 latest):" - \$filesToDelete | ForEach-Object { Write-Output "\$($_.FileName)" } - - if (\$filesToDelete.Count -gt 0) { - \$tempFile = [System.IO.Path]::GetTempFileName() - \$filesToDelete.FileName | Set-Content -Path \$tempFile -Encoding utf8 - - Write-Output "Contents of temporary delete list file (\$tempFile):" - Get-Content \$tempFile - - foreach (\$file in \$filesToDelete.FileName) { - Write-Output "Deleting \$file..." - rclone deletefile AzaionGoogleDrive:${GOOGLE_DRIVE_FOLDER}/\$file - } - - Remove-Item -Path \$tempFile + # Sort by Date descending, skip the first 3 (newest), delete the rest + \$toDelete = \$meta | Sort-Object Date -Descending | Select-Object -Skip 3 + if (\$toDelete) { + Write-Output "Deleting:\" + \$toDelete | ForEach-Object { Write-Output \$_ .Name; rclone deletefile AzaionGoogleDrive:\$folder/\$($_.Name) } } else { - Write-Output "No files to delete." + Write-Output "Nothing to delete." } """ } @@ -166,17 +133,13 @@ pipeline { post { always { - echo 'Executing post-build cleanup...' + echo 'Cleaning up temp files...' powershell ''' - $uploadDir = "temp_upload" - if (Test-Path $uploadDir) { - Remove-Item -Recurse -Force $uploadDir - } + if (Test-Path temp_upload) { Remove-Item -Recurse -Force temp_upload } ''' } - failure { - echo 'Pipeline failed. Check logs for details.' + echo 'Pipeline failed; check the logs above.' } } } From dd5521dc3bbd8902cef613bc6ea5d7ada918e7a5 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Wed, 7 May 2025 20:03:51 +0300 Subject: [PATCH 79/85] pipelines zip and gdrive upload updated --- build/jenkins/GDriveUpload | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index c726cb7..d08c663 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -12,7 +12,7 @@ pipeline { environment { GOOGLE_DRIVE_FOLDER = 'AzaionSuiteBuilds' RCLONE_CONFIG = 'C:/Program Files/rclone/rclone.conf' - LATEST_ZIP_FILENAME = '' // Will be set in Find Latest Zip + LATEST_ZIP_FILENAME = '' // Initial value } stages { @@ -45,14 +45,17 @@ pipeline { ''').trim() echo "PowerShell output: ${output}" - def m = (output =~ /::SET-ENV::LATEST_ZIP_FILENAME=(.+)/) - if (m && m[0][1]) { - latestZip = m[0][1] + + def match = (output =~ /::SET-ENV::LATEST_ZIP_FILENAME=(.+)/) + if (match) { + latestZip = match[0][1] echo "✅ Latest zip file selected: ${latestZip}" } else { - echo "⚠️ No zip found, skipping downstream stages." + echo "⚠️ No zip found." + latestZip = 'none' // Handle case where no file is found } } + // Directly assign the value to the env variable for use in other stages env.LATEST_ZIP_FILENAME = latestZip } } @@ -61,8 +64,7 @@ pipeline { stage('Upload If Not Exists & Always Remove Local') { when { expression { - echo "LATEST_ZIP_FILENAME is: '${env.LATEST_ZIP_FILENAME}'" - return env.LATEST_ZIP_FILENAME?.trim() + return env.LATEST_ZIP_FILENAME != 'none' } } steps { @@ -95,8 +97,7 @@ pipeline { stage('Cleanup Older Files on Google Drive') { when { expression { - echo "LATEST_ZIP_FILENAME is: '${env.LATEST_ZIP_FILENAME}'" - return env.LATEST_ZIP_FILENAME?.trim() + return env.LATEST_ZIP_FILENAME != 'none' } } steps { From 46ec7fddc4758eca9b3a31cd467a510575c148ca Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Wed, 7 May 2025 20:06:08 +0300 Subject: [PATCH 80/85] pipelines zip and gdrive upload updated --- build/jenkins/GDriveUpload | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index d08c663..f702c6d 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -64,7 +64,7 @@ pipeline { stage('Upload If Not Exists & Always Remove Local') { when { expression { - return env.LATEST_ZIP_FILENAME != 'none' + return env.LATEST_ZIP_FILENAME != 'none' && env.LATEST_ZIP_FILENAME != '' } } steps { @@ -97,7 +97,7 @@ pipeline { stage('Cleanup Older Files on Google Drive') { when { expression { - return env.LATEST_ZIP_FILENAME != 'none' + return env.LATEST_ZIP_FILENAME != 'none' && env.LATEST_ZIP_FILENAME != '' } } steps { From 6e1e6d903df0b9c7ab34ba1995d7f4afb1e3c9bb Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Wed, 7 May 2025 20:09:38 +0300 Subject: [PATCH 81/85] pipelines zip and gdrive upload updated --- build/jenkins/GDriveUpload | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index f702c6d..909efe3 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -12,7 +12,6 @@ pipeline { environment { GOOGLE_DRIVE_FOLDER = 'AzaionSuiteBuilds' RCLONE_CONFIG = 'C:/Program Files/rclone/rclone.conf' - LATEST_ZIP_FILENAME = '' // Initial value } stages { @@ -55,7 +54,7 @@ pipeline { latestZip = 'none' // Handle case where no file is found } } - // Directly assign the value to the env variable for use in other stages + // Use the latestZip directly for further stages env.LATEST_ZIP_FILENAME = latestZip } } @@ -64,13 +63,13 @@ pipeline { stage('Upload If Not Exists & Always Remove Local') { when { expression { - return env.LATEST_ZIP_FILENAME != 'none' && env.LATEST_ZIP_FILENAME != '' + return params.LATEST_ZIP_FILENAME != 'none' && params.LATEST_ZIP_FILENAME != '' } } steps { - echo "Uploading ${env.LATEST_ZIP_FILENAME} if needed..." + echo "Uploading ${params.LATEST_ZIP_FILENAME} if needed..." powershell """ - \$fileName = "${env.LATEST_ZIP_FILENAME}" + \$fileName = "${params.LATEST_ZIP_FILENAME}" \$folder = "${GOOGLE_DRIVE_FOLDER}" \$rcloneRemote = "AzaionGoogleDrive:\$folder" \$localPath = "${params.buildPath}/\$fileName" @@ -97,7 +96,7 @@ pipeline { stage('Cleanup Older Files on Google Drive') { when { expression { - return env.LATEST_ZIP_FILENAME != 'none' && env.LATEST_ZIP_FILENAME != '' + return params.LATEST_ZIP_FILENAME != 'none' && params.LATEST_ZIP_FILENAME != '' } } steps { From cea1c69fec84d914dfdd4e3943f04af22ee139f7 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Wed, 7 May 2025 20:11:05 +0300 Subject: [PATCH 82/85] pipelines zip and gdrive upload updated --- build/jenkins/GDriveUpload | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index 909efe3..d08c663 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -12,6 +12,7 @@ pipeline { environment { GOOGLE_DRIVE_FOLDER = 'AzaionSuiteBuilds' RCLONE_CONFIG = 'C:/Program Files/rclone/rclone.conf' + LATEST_ZIP_FILENAME = '' // Initial value } stages { @@ -54,7 +55,7 @@ pipeline { latestZip = 'none' // Handle case where no file is found } } - // Use the latestZip directly for further stages + // Directly assign the value to the env variable for use in other stages env.LATEST_ZIP_FILENAME = latestZip } } @@ -63,13 +64,13 @@ pipeline { stage('Upload If Not Exists & Always Remove Local') { when { expression { - return params.LATEST_ZIP_FILENAME != 'none' && params.LATEST_ZIP_FILENAME != '' + return env.LATEST_ZIP_FILENAME != 'none' } } steps { - echo "Uploading ${params.LATEST_ZIP_FILENAME} if needed..." + echo "Uploading ${env.LATEST_ZIP_FILENAME} if needed..." powershell """ - \$fileName = "${params.LATEST_ZIP_FILENAME}" + \$fileName = "${env.LATEST_ZIP_FILENAME}" \$folder = "${GOOGLE_DRIVE_FOLDER}" \$rcloneRemote = "AzaionGoogleDrive:\$folder" \$localPath = "${params.buildPath}/\$fileName" @@ -96,7 +97,7 @@ pipeline { stage('Cleanup Older Files on Google Drive') { when { expression { - return params.LATEST_ZIP_FILENAME != 'none' && params.LATEST_ZIP_FILENAME != '' + return env.LATEST_ZIP_FILENAME != 'none' } } steps { From 16c264ec9a1b0f6c7cad16210f08536dde984fb7 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Wed, 7 May 2025 20:11:54 +0300 Subject: [PATCH 83/85] pipelines zip and gdrive upload updated --- build/jenkins/GDriveUpload | 140 +++++++++++++++++++++++-------------- 1 file changed, 88 insertions(+), 52 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index d08c663..b43f2a3 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -10,9 +10,8 @@ pipeline { } environment { - GOOGLE_DRIVE_FOLDER = 'AzaionSuiteBuilds' - RCLONE_CONFIG = 'C:/Program Files/rclone/rclone.conf' - LATEST_ZIP_FILENAME = '' // Initial value + GOOGLE_DRIVE_FOLDER = 'AzaionSuiteBuilds' // Hardcoded folder on Google Drive + RCLONE_CONFIG = 'C:/Program Files/rclone/rclone.conf' } stages { @@ -31,32 +30,36 @@ pipeline { stage('Find Latest Zip') { steps { script { - echo "Using build path: ${params.buildPath}" - def latestZip = '' + echo "Using build path: ${params.buildPath}" // Debug output for build path + echo "Finding latest zip file in: ${params.buildPath}" + def latestZipFilename = '' dir("${params.buildPath}") { def output = powershell(returnStdout: true, script: ''' $pattern = "AzaionSuite*.zip" $zipFiles = Get-ChildItem -Filter $pattern | Sort-Object Name -Descending if ($zipFiles.Count -gt 0) { - Write-Output "::SET-ENV::LATEST_ZIP_FILENAME=$($zipFiles[0].Name)" + $latestZip = $zipFiles[0].Name + Write-Output "::SET-ENV::LATEST_ZIP_FILENAME=$latestZip" } else { Write-Output "::SET-ENV::LATEST_ZIP_FILENAME=" } ''').trim() + // Debug output to verify the response from the powershell script echo "PowerShell output: ${output}" - def match = (output =~ /::SET-ENV::LATEST_ZIP_FILENAME=(.+)/) - if (match) { - latestZip = match[0][1] - echo "✅ Latest zip file selected: ${latestZip}" + def match = output =~ /::SET-ENV::LATEST_ZIP_FILENAME=(.+)/ + if (!match || !match[0][1]?.trim()) { + echo "⚠️ No ZIP files matching the pattern were found. Skipping upload and cleanup stages." } else { - echo "⚠️ No zip found." - latestZip = 'none' // Handle case where no file is found + latestZipFilename = match[0][1] + echo "✅ Latest zip file selected: ${latestZipFilename}" } } - // Directly assign the value to the env variable for use in other stages - env.LATEST_ZIP_FILENAME = latestZip + + // Pass the filename to the next stages directly + env.LATEST_ZIP_FILENAME = latestZipFilename + echo "LATEST_ZIP_FILENAME after processing: ${env.LATEST_ZIP_FILENAME}" } } } @@ -64,31 +67,36 @@ pipeline { stage('Upload If Not Exists & Always Remove Local') { when { expression { - return env.LATEST_ZIP_FILENAME != 'none' + echo "LATEST_ZIP_FILENAME is: '${env.LATEST_ZIP_FILENAME}'" // Debug output + return env.LATEST_ZIP_FILENAME?.trim() } } steps { - echo "Uploading ${env.LATEST_ZIP_FILENAME} if needed..." + echo "Checking Google Drive for existing ZIP and uploading if needed..." powershell """ - \$fileName = "${env.LATEST_ZIP_FILENAME}" - \$folder = "${GOOGLE_DRIVE_FOLDER}" + \$fileName = "${env.LATEST_ZIP_FILENAME}" + \$folder = "${GOOGLE_DRIVE_FOLDER}" \$rcloneRemote = "AzaionGoogleDrive:\$folder" - \$localPath = "${params.buildPath}/\$fileName" + \$localFilePath = "${params.buildPath}/\$fileName" - Write-Output "Existing on drive:" - \$existing = rclone lsf --files-only \$rcloneRemote - Write-Output \$existing + Write-Output "Checking for existing files in: \$rcloneRemote" + \$existingFiles = rclone lsf --files-only \$rcloneRemote + Write-Output "Existing files:" + Write-Output \$existingFiles - if (\$existing -match "^\$fileName\$") { - Write-Output "Already exists; skipping upload." + if (\$existingFiles -match "^\$fileName\$") { + Write-Output "File '\$fileName' already exists on Google Drive. Skipping upload." } else { - Write-Output "Uploading..." - rclone copy \$localPath \$rcloneRemote --drive-chunk-size 64M --progress + Write-Output "Uploading '\$fileName' to Google Drive..." + rclone copy "\$localFilePath" \$rcloneRemote --progress --drive-chunk-size 64M + Write-Output "Upload complete." } - if (Test-Path \$localPath) { - Remove-Item -Force \$localPath - Write-Output "Local deleted." + if (Test-Path \$localFilePath) { + Remove-Item -Force \$localFilePath + Write-Output "Local file deleted: \$localFilePath" + } else { + Write-Output "Local file already deleted or not found." } """ } @@ -97,35 +105,59 @@ pipeline { stage('Cleanup Older Files on Google Drive') { when { expression { - return env.LATEST_ZIP_FILENAME != 'none' + echo "LATEST_ZIP_FILENAME is: '${env.LATEST_ZIP_FILENAME}'" // Debug output + return env.LATEST_ZIP_FILENAME?.trim() } } steps { - echo "Cleaning up older files..." + echo "Cleaning up older files on Google Drive..." powershell """ - \$folder = "${GOOGLE_DRIVE_FOLDER}" - \$files = rclone lsf --files-only AzaionGoogleDrive:\$folder | Where-Object { \$_ -match '^AzaionSuite.*\\.zip\$' } + Write-Output "Listing all files in the folder ${GOOGLE_DRIVE_FOLDER} on Google Drive..." + \$files = rclone lsf --files-only AzaionGoogleDrive:${GOOGLE_DRIVE_FOLDER} + Write-Output "Files found on Google Drive:" + Write-Output \$files - # Build an array of objects with parsed DateTime - \$meta = foreach (\$f in \$files) { - if (\$f -match 'AzaionSuite\\.Iterative\\.(\\d{8})-(\\d{6})\\.zip') { - \$dt = [datetime]::ParseExact(\$matches[1] + \$matches[2], 'yyyyMMddHHmmss', \$null) - } elseif (\$f -match 'AzaionSuite1\\.\\d+\\.\\d+\\.\\d+-(\\d{8})-(\\d{6})\\.zip') { - \$dt = [datetime]::ParseExact(\$matches[1] + \$matches[2], 'yyyyMMddHHmmss', \$null) - } else { - # if it doesn't match expected formats, skip - continue + # Extract date-time from filenames and sort them + \$filesArray = \$files -split "`n" | Where-Object { \$_ -ne "" } + \$filesWithDateTime = @() + + foreach (\$file in \$filesArray) { + if (\$file -match "AzaionSuite.Iterative.(\d{8})-(\d{6}).zip") { + \$date = [datetime]::ParseExact(\$matches[1], "yyyyMMdd", $null) + \$time = [datetime]::ParseExact(\$matches[2], "HHmmss", $null) + \$dateTime = \$date.Add(\$time.TimeOfDay) + \$filesWithDateTime += [PSCustomObject]@{ + FileName = \$file + DateTime = \$dateTime + } } - [PSCustomObject]@{ Name = \$f; Date = \$dt } } - # Sort by Date descending, skip the first 3 (newest), delete the rest - \$toDelete = \$meta | Sort-Object Date -Descending | Select-Object -Skip 3 - if (\$toDelete) { - Write-Output "Deleting:\" - \$toDelete | ForEach-Object { Write-Output \$_ .Name; rclone deletefile AzaionGoogleDrive:\$folder/\$($_.Name) } + # Sort files based on DateTime in descending order + \$sortedFiles = \$filesWithDateTime | Sort-Object DateTime -Descending + Write-Output "Sorted files (newest to oldest):" + \$sortedFiles | ForEach-Object { Write-Output "\$($_.FileName)" } + + # Keep the latest 3 files and delete the rest + \$filesToDelete = \$sortedFiles | Select-Object -Skip 3 + Write-Output "Files to delete (older than 3 latest):" + \$filesToDelete | ForEach-Object { Write-Output "\$($_.FileName)" } + + if (\$filesToDelete.Count -gt 0) { + \$tempFile = [System.IO.Path]::GetTempFileName() + \$filesToDelete.FileName | Set-Content -Path \$tempFile -Encoding utf8 + + Write-Output "Contents of temporary delete list file (\$tempFile):" + Get-Content \$tempFile + + foreach (\$file in \$filesToDelete.FileName) { + Write-Output "Deleting \$file..." + rclone deletefile AzaionGoogleDrive:${GOOGLE_DRIVE_FOLDER}/\$file + } + + Remove-Item -Path \$tempFile } else { - Write-Output "Nothing to delete." + Write-Output "No files to delete." } """ } @@ -134,13 +166,17 @@ pipeline { post { always { - echo 'Cleaning up temp files...' + echo 'Executing post-build cleanup...' powershell ''' - if (Test-Path temp_upload) { Remove-Item -Recurse -Force temp_upload } + $uploadDir = "temp_upload" + if (Test-Path $uploadDir) { + Remove-Item -Recurse -Force $uploadDir + } ''' } + failure { - echo 'Pipeline failed; check the logs above.' + echo 'Pipeline failed. Check logs for details.' } } } From 4456e5220735d0373e18a5aaab02697ed8ef8e46 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Wed, 7 May 2025 20:14:44 +0300 Subject: [PATCH 84/85] pipelines zip and gdrive upload updated --- build/jenkins/GDriveUpload | 57 ++++++++++++++------------------------ 1 file changed, 21 insertions(+), 36 deletions(-) diff --git a/build/jenkins/GDriveUpload b/build/jenkins/GDriveUpload index b43f2a3..91230c3 100644 --- a/build/jenkins/GDriveUpload +++ b/build/jenkins/GDriveUpload @@ -117,47 +117,32 @@ pipeline { Write-Output "Files found on Google Drive:" Write-Output \$files - # Extract date-time from filenames and sort them \$filesArray = \$files -split "`n" | Where-Object { \$_ -ne "" } - \$filesWithDateTime = @() + if (\$filesArray.Count -gt 3) { + \$filesSorted = \$filesArray | Sort-Object -Descending + \$filesToDelete = \$filesSorted | Select-Object -Skip 3 - foreach (\$file in \$filesArray) { - if (\$file -match "AzaionSuite.Iterative.(\d{8})-(\d{6}).zip") { - \$date = [datetime]::ParseExact(\$matches[1], "yyyyMMdd", $null) - \$time = [datetime]::ParseExact(\$matches[2], "HHmmss", $null) - \$dateTime = \$date.Add(\$time.TimeOfDay) - \$filesWithDateTime += [PSCustomObject]@{ - FileName = \$file - DateTime = \$dateTime + Write-Output "Files to delete (older than 3 latest):" + Write-Output \$filesToDelete + + if (\$filesToDelete.Count -gt 0) { + \$tempFile = [System.IO.Path]::GetTempFileName() + \$filesToDelete | Set-Content -Path \$tempFile -Encoding utf8 + + Write-Output "Contents of temporary delete list file (\$tempFile):" + Get-Content \$tempFile + + foreach (\$file in \$filesToDelete) { + Write-Output "Deleting \$file..." + rclone deletefile AzaionGoogleDrive:${GOOGLE_DRIVE_FOLDER}/\$file } + + Remove-Item -Path \$tempFile + } else { + Write-Output "No files to delete." } - } - - # Sort files based on DateTime in descending order - \$sortedFiles = \$filesWithDateTime | Sort-Object DateTime -Descending - Write-Output "Sorted files (newest to oldest):" - \$sortedFiles | ForEach-Object { Write-Output "\$($_.FileName)" } - - # Keep the latest 3 files and delete the rest - \$filesToDelete = \$sortedFiles | Select-Object -Skip 3 - Write-Output "Files to delete (older than 3 latest):" - \$filesToDelete | ForEach-Object { Write-Output "\$($_.FileName)" } - - if (\$filesToDelete.Count -gt 0) { - \$tempFile = [System.IO.Path]::GetTempFileName() - \$filesToDelete.FileName | Set-Content -Path \$tempFile -Encoding utf8 - - Write-Output "Contents of temporary delete list file (\$tempFile):" - Get-Content \$tempFile - - foreach (\$file in \$filesToDelete.FileName) { - Write-Output "Deleting \$file..." - rclone deletefile AzaionGoogleDrive:${GOOGLE_DRIVE_FOLDER}/\$file - } - - Remove-Item -Path \$tempFile } else { - Write-Output "No files to delete." + Write-Output "No files found on Google Drive to clean up." } """ } From 6fce10eb39d4d08e88f987a75b0dd827a50e7d47 Mon Sep 17 00:00:00 2001 From: dzaitsev Date: Wed, 21 May 2025 14:05:41 +0300 Subject: [PATCH 85/85] added zip.bat to pack build artefacts for both Full and Iterative installers. --- build/zip.bat | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 build/zip.bat diff --git a/build/zip.bat b/build/zip.bat new file mode 100644 index 0000000..d98756a --- /dev/null +++ b/build/zip.bat @@ -0,0 +1,105 @@ +@echo off +setlocal enabledelayedexpansion + +:: Move one level up +cd /d .. +echo [INFO] Changed working directory to: %CD% + +:: Get timestamp +for /f %%a in ('powershell -NoProfile -Command "Get-Date -Format yyyyMMdd-HHmmss"') do set "timestamp=%%a" + +set "fullZipCreated=0" +set "iterZipCreated=0" + +:: ===== FULL BUILD ===== +set "fullExe=" +for %%F in (AzaionSuite.Full.*.exe) do ( + set "fullExe=%%F" + goto :FullExeFound +) +echo [WARNING] No Full build EXE found [AzaionSuite.Full.*.exe] +goto :AfterFullBuild + +:FullExeFound +echo [INFO] Found Full build EXE: [%fullExe%] +set "baseFull=%fullExe:.exe=%" + +:: Collect BIN files for Full build +set "fullBinList=" +for %%B in (%baseFull%-*.bin) do ( + echo [INFO] Found BIN file: [%%B] + if defined fullBinList ( + set "fullBinList=!fullBinList!,\"%%B\"" + ) else ( + set "fullBinList=\"%%B\"" + ) +) + +echo [INFO] BIN files list: %fullBinList% + +:: Compose PowerShell command for Full +if "%fullBinList%"=="" ( + set "fullPsCmd=Compress-Archive -Force -Path \"%fullExe%\" -DestinationPath \"%baseFull%-%timestamp%.zip\"" +) else ( + set "fullPsCmd=Compress-Archive -Force -Path \"%fullExe%\",%fullBinList% -DestinationPath \"%baseFull%-%timestamp%.zip\"" +) + +echo [INFO] Creating ZIP: [%baseFull%-%timestamp%.zip] +echo [INFO] Using PowerShell command to compress: +echo powershell -Command "%fullPsCmd%" + +powershell -Command "%fullPsCmd%" +if errorlevel 1 ( + echo [ERROR] Failed to create Full archive: [%baseFull%-%timestamp%.zip] +) else ( + echo [SUCCESS] Full archive created: [%baseFull%-%timestamp%.zip] + set "fullZipCreated=1" +) + +:AfterFullBuild + +:: ===== ITERATIVE BUILD ===== +set "iterExe=" +for %%I in (AzaionSuite.Iterative.*.exe) do ( + set "iterExe=%%I" + goto :IterExeFound +) +echo [WARNING] No Iterative build EXE found [AzaionSuite.Iterative.*.exe] +goto :AfterIterBuild + +:IterExeFound +echo [INFO] Found Iterative build EXE: [%iterExe%] +set "baseIter=%iterExe:.exe=%" + +:: Iterative pack (exe only) +set "iterPsCmd=Compress-Archive -Force -Path \"%iterExe%\" -DestinationPath \"%baseIter%-%timestamp%.zip\"" + +echo [INFO] Creating ZIP: [%baseIter%-%timestamp%.zip] +echo [INFO] Using PowerShell command to compress: +echo powershell -Command "%iterPsCmd%" + +powershell -Command "%iterPsCmd%" +if errorlevel 1 ( + echo [ERROR] Failed to create Iterative archive: [%baseIter%-%timestamp%.zip] +) else ( + echo [SUCCESS] Iterative archive created: [%baseIter%-%timestamp%.zip] + set "iterZipCreated=1" +) + +:AfterIterBuild + +echo. + +if "%fullZipCreated%"=="1" ( + if "%iterZipCreated%"=="1" ( + echo [DONE] Both Full and Iterative packaging complete. + ) else ( + echo [DONE] Full packaging complete. No Iterative package created. + ) +) else ( + if "%iterZipCreated%"=="1" ( + echo [DONE] Iterative packaging complete. No Full package created. + ) else ( + echo [INFO] No packages were created. + ) +) \ No newline at end of file