Skip to content

Commit d1eea05

Browse files
committed
ceph-dev-cron: Convert to groovy, trigger ceph-dev-pipeline instead
Signed-off-by: David Galloway <david.galloway@ibm.com>
1 parent 85e3d6e commit d1eea05

File tree

3 files changed

+203
-125
lines changed

3 files changed

+203
-125
lines changed

ceph-dev-cron/build/Jenkinsfile

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
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+
}

ceph-dev-cron/build/notify

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 20 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
- job:
22
name: 'ceph-dev-cron'
3+
description: 'Twice-daily scheduled build trigger for selected ceph.git branches (only if new commits).'
34
node: built-in
4-
project-type: freestyle
5+
project-type: pipeline
56
defaults: global
67
concurrent: true
7-
quiet-period: 5
8+
quiet-period: 0
89
block-downstream: false
910
block-upstream: false
11+
1012
properties:
1113
- build-discarder:
12-
days-to-keep: -1
13-
num-to-keep: 20
14+
num-to-keep: 200
1415
artifact-days-to-keep: -1
1516
artifact-num-to-keep: -1
1617
- github:
1718
url: https://github.com/ceph/ceph
18-
discard-old-builds: true
19+
- copyartifact:
20+
projects: ceph-dev-cron
1921

2022
triggers:
2123
- pollscm:
@@ -24,114 +26,16 @@
2426
H 14 * * *
2527
H 20 * * *
2628
27-
scm:
28-
- git:
29-
url: https://github.com/ceph/ceph
30-
browser: auto
31-
branches:
32-
- origin/main
33-
- origin/tentacle
34-
- origin/squid
35-
- origin/reef
36-
skip-tag: true
37-
timeout: 20
38-
wipe-workspace: true
39-
40-
builders:
41-
# build reef on:
42-
# default: jammy focal centos9 windows
43-
- conditional-step:
44-
condition-kind: regex-match
45-
regex: .*reef.*
46-
label: '${{GIT_BRANCH}}'
47-
on-evaluation-failure: dont-run
48-
steps:
49-
- shell:
50-
!include-raw-verbatim:
51-
- ../../../scripts/build_utils.sh
52-
- ../../build/notify
53-
- trigger-builds:
54-
- project: 'ceph-dev'
55-
predefined-parameters: |
56-
BRANCH=${{GIT_BRANCH}}
57-
FORCE=True
58-
DISTROS=jammy focal centos9 windows
59-
# build squid on:
60-
# default: noble jammy centos9 windows
61-
- conditional-step:
62-
condition-kind: regex-match
63-
regex: .*squid.*
64-
label: '${{GIT_BRANCH}}'
65-
on-evaluation-failure: dont-run
66-
steps:
67-
- shell:
68-
!include-raw-verbatim:
69-
- ../../../scripts/build_utils.sh
70-
- ../../build/notify
71-
- trigger-builds:
72-
- project: 'ceph-dev'
73-
predefined-parameters: |
74-
BRANCH=${{GIT_BRANCH}}
75-
FORCE=True
76-
DISTROS=noble jammy centos9 windows
77-
# build tentacle on:
78-
# default: noble jammy centos9 windows
79-
# debug: centos9
80-
- conditional-step:
81-
condition-kind: regex-match
82-
regex: .*tentacle.*
83-
label: '${{GIT_BRANCH}}'
84-
on-evaluation-failure: dont-run
85-
steps:
86-
- shell:
87-
!include-raw-verbatim:
88-
- ../../../scripts/build_utils.sh
89-
- ../../build/notify
90-
- trigger-builds:
91-
- project: 'ceph-dev'
92-
predefined-parameters: |
93-
BRANCH=${{GIT_BRANCH}}
94-
FORCE=True
95-
DISTROS=noble jammy centos9 windows
96-
- project: 'ceph-dev'
97-
predefined-parameters: |
98-
BRANCH=${{GIT_BRANCH}}
99-
FORCE=True
100-
DISTROS=centos9
101-
FLAVOR=debug
102-
ARCHS=x86_64
103-
# build main on:
104-
# default: noble jammy centos9 windows
105-
# debug: centos9
106-
- conditional-step:
107-
condition-kind: regex-match
108-
regex: .*main.*
109-
label: '${{GIT_BRANCH}}'
110-
on-evaluation-failure: dont-run
111-
steps:
112-
- shell:
113-
!include-raw-verbatim:
114-
- ../../../scripts/build_utils.sh
115-
- ../../build/notify
116-
- trigger-builds:
117-
- project: 'ceph-dev'
118-
predefined-parameters: |
119-
BRANCH=${{GIT_BRANCH}}
120-
FORCE=True
121-
DISTROS=noble jammy centos9 windows
122-
- project: 'ceph-dev'
123-
predefined-parameters: |
124-
BRANCH=${{GIT_BRANCH}}
125-
FORCE=True
126-
DISTROS=centos9
127-
FLAVOR=debug
128-
ARCHS=x86_64
129-
130-
wrappers:
131-
- inject-passwords:
132-
global: true
133-
mask-password-params: true
134-
- credentials-binding:
135-
- text:
136-
credential-id: shaman-api-key
137-
variable: SHAMAN_API_KEY
29+
pipeline-scm:
30+
scm:
31+
- git:
32+
url: https://github.com/ceph/ceph-build
33+
branches:
34+
- main
35+
shallow-clone: true
36+
submodule:
37+
disable: true
38+
wipe-workspace: true
39+
script-path: ceph-dev-cron/build/Jenkinsfile
40+
lightweight-checkout: false
41+
do-not-fetch-tags: true

0 commit comments

Comments
 (0)