From 4f3a5629d912612d711f1844be89c638f044e0e8 Mon Sep 17 00:00:00 2001 From: alexandrabain <115022231+alexandrabain@users.noreply.github.com> Date: Tue, 17 Jun 2025 13:29:56 -0400 Subject: [PATCH] TEN-2441 Addition of releases.json file for nightly builds (#876) * Added creation or addition to releases.json including push to train * Corrected paths * Corrected point at which upload folder is cleaned up * Commented out ISO whilst update push release file tested * Reinstated ISO push steps * Corrected indents * Simplified logic to use all the fields from the manifest file and removed sorting of entries as they are added in sequence * Jenkins JSONObject does not implement Cloneable, approach changed * Added order check on 30 days to be certain we retain the correct data --- jenkins/Publish-ISO | 50 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/jenkins/Publish-ISO b/jenkins/Publish-ISO index 48f9a05..03affa9 100644 --- a/jenkins/Publish-ISO +++ b/jenkins/Publish-ISO @@ -17,8 +17,54 @@ pipeline { copyArtifacts filter: '**/*.json', fingerprintArtifacts: true, flatten: true, projectName: 'Build - TrueNAS SCALE (Full - Nightly ISO)', selector: lastSuccessful(), target: 'upload/files' sh 'ssh jenkins@staging.sys.ixsystems.net mkdir -p /zdata/update.sys.truenas.net/scale/TrueNAS-SCALE-Goldeye-Nightlies || true' sh 'scp upload/files/manifest.json upload/files/TrueNAS-SCALE-*.update jenkins@staging.sys.ixsystems.net:/zdata/update.sys.truenas.net/scale/TrueNAS-SCALE-Goldeye-Nightlies/' - sh 'rm -rf upload/files' } - } + } + stage('Update Releases JSON') { + steps { + script { + // Download existing releases.json if it exists + sh '''scp jenkins@staging.sys.ixsystems.net:/zdata/update.sys.truenas.net/scale/TrueNAS-SCALE-Goldeye-Nightlies/releases.json upload/files/releases.json || echo "{}" > upload/files/releases.json''' + + // Read manifest.json and extract information + def manifestContent = readFile('upload/files/manifest.json') + def manifest = readJSON text: manifestContent + + // Read existing releases.json + def existingReleasesContent = readFile('upload/files/releases.json') + def existingReleases = readJSON text: existingReleasesContent + + // Add new release entry to existing releases dictionary + // Copy all manifest fields and add profile + def releaseEntry = [:] + manifest.each { key, value -> + releaseEntry[key] = value + } + releaseEntry.profile = 'DEVELOPER' + existingReleases[manifest.version] = releaseEntry + + // Keep only the last 30 entries by date + if (existingReleases.size() > 30) { + // Sort entries by date and keep only the 30 most recent + def sortedEntries = existingReleases.sort { a, b -> + Date.parse("yyyy-MM-dd'T'HH:mm:ss'Z'", b.value.date).compareTo( + Date.parse("yyyy-MM-dd'T'HH:mm:ss'Z'", a.value.date) + ) + } + def recentEntries = sortedEntries.take(30) + existingReleases = [:] + recentEntries.each { entry -> + existingReleases[entry.key] = entry.value + } + } + + // Write updated releases.json + writeJSON file: 'upload/files/releases.json', json: existingReleases, pretty: 4 + + // Upload updated releases.json + sh '''scp upload/files/releases.json jenkins@staging.sys.ixsystems.net:/zdata/update.sys.truenas.net/scale/TrueNAS-SCALE-Goldeye-Nightlies/''' + sh 'rm -rf upload/files' + } + } + } } }