Skip to content

Commit 861d6b6

Browse files
committed
Automate the bootimage bump process
This bootimagebump job would automate a part of the bootimage bump process by running the plume-cosa script and creating a PR for the rhcos build that is currently done manually.
1 parent 38614b6 commit 861d6b6

File tree

1 file changed

+157
-0
lines changed

1 file changed

+157
-0
lines changed

jobs/bootimagebump.Jenkinsfile

+157
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
botCreds = "github-coreosbot-releng-token-username-password"
2+
releng_installer = "coreosbot-releng/installer"
3+
4+
node {
5+
checkout scm: [
6+
$class: 'GitSCM',
7+
branches: [[name: "main"]],
8+
userRemoteConfigs: [[url: "https://github.com/${releng_installer}.git"]],
9+
extensions: [
10+
[$class: 'CloneOption', depth: 1, noTags: true, shallow: true],
11+
[$class: 'WipeWorkspace']]
12+
]
13+
14+
properties([
15+
pipelineTriggers([]),
16+
parameters([
17+
string(name: 'STREAM',
18+
description: 'CoreOS stream to build',
19+
defaultValue: '4.16-9.4',
20+
trim: true),
21+
string(name: 'BUILD_VERSION',
22+
description: 'RHCOS build version to use for the bump',
23+
defaultValue: '416.94.202501270445-0',
24+
trim: true),
25+
string(name: 'BOOTIMAGE_BUG_ID',
26+
description: 'JIRA bug ID for the bootimage bump',
27+
defaultValue: 'OCPBUGS-48762',
28+
trim: true),
29+
text(name: 'JIRA_ISSUES',
30+
description: 'JIRA issues for the bootimage bump',
31+
defaultValue: '',
32+
trim: true),
33+
string(name: 'COREOS_ASSEMBLER_IMAGE',
34+
description: 'Override the coreos-assembler image to use',
35+
defaultValue: "quay.io/coreos-assembler/coreos-assembler:rhcos-4.16",
36+
trim: true),
37+
string(name: 'DISTRO',
38+
description: 'Distribution to use',
39+
defaultValue: "rhcos",
40+
trim: true),
41+
string(name: 'URL',
42+
description: 'URL to use',
43+
defaultValue: "https://rhcos.mirror.openshift.com/art/storage/prod/streams",
44+
trim: true),
45+
]),
46+
buildDiscarder(logRotator(
47+
numToKeepStr: '100',
48+
artifactNumToKeepStr: '100'
49+
)),
50+
durabilityHint('PERFORMANCE_OPTIMIZED')
51+
])
52+
53+
RHCOS_METADATA_FILE = "data/data/coreos/rhcos.json"
54+
PR_BRANCH = "bootimage-bump-${params.BUILD_VERSION}"
55+
RELEASE_BRANCH = "release-${params.STREAM.split('-')[0]}"
56+
57+
cosaPod(serviceAccount: "jenkins",
58+
image: params.COREOS_ASSEMBLER_IMAGE,
59+
memory: "512Mi", kvm: false,){
60+
try {
61+
shwrap("""
62+
git config --global user.name "CoreOS Bot"
63+
git config --global user.email "[email protected]"
64+
""")
65+
// Clone the openshift/installer repository and fetch the required release branch
66+
stage('Setup workspace') {
67+
shwrap("""
68+
git clone --depth=1 --branch main https://github.com/${releng_installer}.git
69+
cd installer
70+
git remote -v
71+
git remote add upstream https://github.com/openshift/installer.git
72+
retries=3
73+
for i in \$(seq 1 \$retries); do
74+
echo "Attempt \$i of \$retries to fetch upstream/${RELEASE_BRANCH}"
75+
git fetch upstream ${RELEASE_BRANCH} && break || sleep 10
76+
done
77+
git checkout -b ${PR_BRANCH} upstream/${RELEASE_BRANCH}
78+
git remote -v
79+
""")
80+
}
81+
82+
// Run plume cosa2stream to update the RHCOS bootimage metadata (rhcos.json)
83+
stage('Bump Bootimage Metadata') {
84+
shwrap("""
85+
cd installer
86+
plume cosa2stream \
87+
--target ${RHCOS_METADATA_FILE} \
88+
--distro ${params.DISTRO} \
89+
--no-signatures \
90+
--name ${params.STREAM} \
91+
--url ${params.URL} \
92+
x86_64=${params.BUILD_VERSION} \
93+
aarch64=${params.BUILD_VERSION} \
94+
s390x=${params.BUILD_VERSION} \
95+
ppc64le=${params.BUILD_VERSION}
96+
git diff --exit-code; echo \$? > changes
97+
cat changes
98+
""")
99+
}
100+
101+
// Commit the updated metadata.
102+
stage('Create Pull Request') {
103+
if (shwrapCapture("git -C installer diff --exit-code") != 0){
104+
def message = "${params.BOOTIMAGE_BUG_ID}: Update RHCOS-${RELEASE_BRANCH} bootimage metadata to ${params.BUILD_VERSION}"
105+
def commit_message = """\
106+
${params.BOOTIMAGE_BUG_ID}: Update RHCOS ${RELEASE_BRANCH} bootimage metadata to ${params.BUILD_VERSION}
107+
108+
The changes done here will update the RHCOS ${RELEASE_BRANCH} bootimage metadata and address the following issues:
109+
${params.JIRA_ISSUES}
110+
111+
This change was generated using:
112+
113+
plume cosa2stream --target ${RHCOS_METADATA_FILE} \\
114+
--distro ${params.DISTRO} --no-signatures --name ${params.STREAM} \\
115+
--url ${params.URL} \\
116+
x86_64=${params.BUILD_VERSION} \\
117+
aarch64=${params.BUILD_VERSION} \\
118+
s390x=${params.BUILD_VERSION} \\
119+
ppc64le=${params.BUILD_VERSION}
120+
121+
""".stripIndent().trim()
122+
123+
shwrap ("""
124+
cd installer
125+
git add ${RHCOS_METADATA_FILE}
126+
git commit -m '${commit_message}'
127+
""")
128+
129+
withCredentials([usernamePassword(credentialsId: botCreds,
130+
usernameVariable: 'GHUSER',
131+
passwordVariable: 'GHTOKEN')]) {
132+
shwrap("""
133+
cd installer
134+
git push -f https://\${GHUSER}:\${GHTOKEN}@github.com/${releng_installer} ${PR_BRANCH}
135+
curl -H "Authorization: token ${GHTOKEN}" -X POST -d '{ "title": "${message}", "head": "coreosbot-releng:${PR_BRANCH}", "base": "${RELEASE_BRANCH}" }' https://api.github.com/repos/openshift/installer/pulls --fail
136+
""")
137+
}
138+
}
139+
currentBuild.result = 'SUCCESS'
140+
}
141+
} catch (e) {
142+
currentBuild.result = 'FAILURE'
143+
throw e
144+
} finally {
145+
def message = "[${params.STREAM}][bootimage-bump] #${env.BUILD_NUMBER} <${env.BUILD_URL}|:jenkins:> <${env.RUN_DISPLAY_URL}|:ocean:>"
146+
if (currentBuild.result == 'SUCCESS') {
147+
message = ":sparkles: ${message}"
148+
} else if (currentBuild.result == 'UNSTABLE') {
149+
message = ":warning: ${message}"
150+
} else {
151+
message = ":fire: ${message}"
152+
}
153+
echo message
154+
//pipeutils.trySlackSend(message: message)
155+
}
156+
}
157+
}

0 commit comments

Comments
 (0)