|
| 1 | +node('built-in') { |
| 2 | + def repoUrl = 'https://github.com/ceph/ceph' |
| 3 | + def branches = ['main','tentacle','squid','reef'] |
| 4 | + |
| 5 | + // Define flavor/distro combinations |
| 6 | + def cfg = [ |
| 7 | + reef: [ |
| 8 | + distros: 'jammy focal centos9 windows', |
| 9 | + extras : [] |
| 10 | + ], |
| 11 | + squid: [ |
| 12 | + distros: 'noble jammy centos9 windows', |
| 13 | + extras : [] |
| 14 | + ], |
| 15 | + tentacle: [ |
| 16 | + distros: 'noble jammy rocky10 centos9 windows', |
| 17 | + extras : [ |
| 18 | + [distros:'centos9 rocky10', flavors:'debug', archs:'x86_64'] |
| 19 | + ] |
| 20 | + ], |
| 21 | + main: [ |
| 22 | + distros: 'noble jammy rocky10 centos9 windows', |
| 23 | + extras : [ |
| 24 | + [distros:'centos9 rocky10', flavors:'debug', archs:'x86_64'], |
| 25 | + ] |
| 26 | + ] |
| 27 | + ] |
| 28 | + |
| 29 | + // Initialize some empty vars |
| 30 | + def last = [:] |
| 31 | + def tips = [:] |
| 32 | + def toBuild = [] |
| 33 | + def unchanged = [] |
| 34 | + |
| 35 | + try { |
| 36 | + // The last_shas.properties file ends up looking like: |
| 37 | + // main=c743821fba4c7d4d10b2fc12facd975b6fd18c55 |
| 38 | + // tentacle=9530200d1f382ce628313be8e8b938354d7936cd |
| 39 | + // squid=ab2234593ae767938f06d61a06ac4ff847db0b79 |
| 40 | + // reef=e6ab650721089ed287ed684011c35b550bf20fe7 |
| 41 | + |
| 42 | + // Try to get this file from the last ceph-dev-cron job that ran. Missing is OK (we'll just trigger everything). |
| 43 | + // We define an array, "last" that looks like: |
| 44 | + // [ |
| 45 | + // main : 'a1b2c3d4...', |
| 46 | + // tentacle : 'e5f6g7h8...', |
| 47 | + // squid : 'i9j0k1l2...', |
| 48 | + // reef : 'm3n4o5p6...' |
| 49 | + // ] |
| 50 | + stage('Slurp previous job SHAs') { |
| 51 | + sh 'rm -f last_shas.properties' // ensure no cached copy in job dir |
| 52 | + try { |
| 53 | + copyArtifacts projectName: env.JOB_NAME, |
| 54 | + selector: lastWithArtifacts(), |
| 55 | + filter: 'last_shas.properties', |
| 56 | + optional: true, |
| 57 | + flatten: true |
| 58 | + if (fileExists('last_shas.properties')) { |
| 59 | + last = readProperties file: 'last_shas.properties' |
| 60 | + } else { |
| 61 | + last = [:] |
| 62 | + } |
| 63 | + } catch (e) { |
| 64 | + echo "No prior cache available: ${e}" |
| 65 | + last = [:] |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + // Query the remote Ceph git repository to get the current tip commit SHA |
| 70 | + // for each tracked branch (without cloning). These SHAs are later compared |
| 71 | + // against the previously stored values to determine which branches have |
| 72 | + // changed and need downstream builds triggered. |
| 73 | + |
| 74 | + // branches is the list of branch names (e.g., ['main','tentacle','squid','reef']) |
| 75 | + // b is short for branch. We're just looping over branches here. |
| 76 | + // Ultimately we end up with array "tips" that looks like "last" but is the current |
| 77 | + // tip of each branch instead of the last job's tips. |
| 78 | + stage('Retrieve branch tip SHAs') { |
| 79 | + branches.each { b -> |
| 80 | + def sha = sh( |
| 81 | + script: "git ls-remote ${repoUrl} refs/heads/${b} | awk '{print \$1}'", |
| 82 | + returnStdout: true |
| 83 | + ).trim() |
| 84 | + if (!sha) { error "Could not resolve remote SHA for branch ${b}" } |
| 85 | + tips[b] = sha |
| 86 | + echo "Branch ${b} -> ${sha}" |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | + // For each branch (b), if the previous job's tip does not equal this job's tip, |
| 91 | + // add the branch name to array toBuild, otherwise add to unchanged. |
| 92 | + stage('Compare SHAs') { |
| 93 | + branches.each { b -> |
| 94 | + def prev = (last.getOrDefault(b, '') ?: '').trim() |
| 95 | + def now = (tips[b] ?: '').trim() |
| 96 | + if (prev != now) toBuild << b else unchanged << b |
| 97 | + } |
| 98 | + echo "Changed: ${toBuild}" |
| 99 | + echo "Unchanged: ${unchanged}" |
| 100 | + } |
| 101 | + |
| 102 | + if (toBuild.isEmpty()) { |
| 103 | + currentBuild.description = "No changes: ${branches.join(', ')}" |
| 104 | + return |
| 105 | + } |
| 106 | + |
| 107 | + // Loop through toBuild setting b to the branch name that needs to be built. |
| 108 | + stage('Trigger ceph-dev-pipeline') { |
| 109 | + def triggered = [] |
| 110 | + toBuild.each { b -> |
| 111 | + def sha = tips[b] |
| 112 | + dir("work/${b}") { |
| 113 | + |
| 114 | + // Split the string, DISTROS, out into a list (i.e., tokenize) |
| 115 | + def toks = (cfg[b].distros ?: '').tokenize() |
| 116 | + // Put all of the tokens other than "windows" in linuxDistros list |
| 117 | + def linuxDistros = toks.findAll { it != 'windows' }.join(' ') |
| 118 | + // If "windows" is present, put it in winDistros |
| 119 | + // (Even though there will only ever be "windows" in this "list," it seemed more readable |
| 120 | + // to trigger the Linux distros based on a list and the windows job based on a bool.) |
| 121 | + def winDistros = toks.findAll { it == 'windows' }.join(' ') |
| 122 | + |
| 123 | + if (linuxDistros) { |
| 124 | + echo "Triggering BRANCH=${b}, DISTROS=${linuxDistros}, FLAVOR=default, ARCH=x86_64" |
| 125 | + build job: 'ceph-dev-pipeline', |
| 126 | + parameters: [ |
| 127 | + string(name: 'BRANCH', value: b), |
| 128 | + string(name: 'DISTROS', value: linuxDistros), |
| 129 | + string(name: 'CEPH_REPO', value: repoUrl), |
| 130 | + string(name: 'SETUP_JOB', value: 'ceph-source-dist'), |
| 131 | + booleanParam(name: 'FORCE', value: true) |
| 132 | + ], |
| 133 | + wait: false |
| 134 | + } |
| 135 | + |
| 136 | + if (winDistros) { |
| 137 | + echo "Triggering BRANCH=${b}, DISTROS=${winDistros}, FLAVOR=default, ARCH=x86_64" |
| 138 | + build job: 'ceph-dev', |
| 139 | + parameters: [ |
| 140 | + string(name: 'BRANCH', value: b), |
| 141 | + string(name: 'DISTROS', value: winDistros), |
| 142 | + booleanParam(name: 'FORCE', value: true) |
| 143 | + ], |
| 144 | + wait: false |
| 145 | + } |
| 146 | + |
| 147 | + // This block is for FLAVOR=debug and/or ARCHS=arm64 |
| 148 | + cfg[b].extras.each { ex -> |
| 149 | + echo "Triggering BRANCH=${b}, FLAVOR=${ex.flavors}, ARCH=${ex.archs}" |
| 150 | + build job: 'ceph-dev-pipeline', |
| 151 | + parameters: [ |
| 152 | + string(name: 'BRANCH', value: b), |
| 153 | + string(name: 'DISTROS', value: ex.distros), |
| 154 | + string(name: 'FLAVORS', value: ex.flavors), |
| 155 | + string(name: 'ARCHS', value: ex.archs), |
| 156 | + string(name: 'CEPH_REPO', value: repoUrl), |
| 157 | + string(name: 'SETUP_JOB', value: 'ceph-source-dist'), |
| 158 | + booleanParam(name: 'FORCE', value: true) |
| 159 | + ], |
| 160 | + wait: false |
| 161 | + } |
| 162 | + } |
| 163 | + // For each job we triggered, add "$branch@$short_sha" to array "triggered" |
| 164 | + triggered << "${b}@${sha.take(8)}" |
| 165 | + } |
| 166 | + |
| 167 | + // Set the build description |
| 168 | + def skipped = (branches - toBuild) |
| 169 | + currentBuild.description = triggered.isEmpty() |
| 170 | + ? "No changes: ${branches.join(', ')}" |
| 171 | + : "Triggered:<br>- ${triggered.join('<br>- ')}" + |
| 172 | + (skipped ? "<br><br>Unchanged:<br>- ${skipped.join('<br>- ')}" : "") |
| 173 | + } |
| 174 | + |
| 175 | + } finally { |
| 176 | + // Write last_shas.properties for the next job to consume |
| 177 | + if (tips && tips instanceof Map && !tips.isEmpty()) { |
| 178 | + writeFile file: 'last_shas.properties', |
| 179 | + text: tips.collect { k, v -> "${k}=${v}" }.join('\n') + "\n" |
| 180 | + archiveArtifacts artifacts: 'last_shas.properties', fingerprint: true |
| 181 | + } |
| 182 | + } |
| 183 | +} |
0 commit comments