Skip to content

Commit 93f0e74

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. JIRA: https://issues.redhat.com/browse/COS-2205
1 parent 38614b6 commit 93f0e74

File tree

1 file changed

+165
-0
lines changed

1 file changed

+165
-0
lines changed

jobs/bootimagebump.Jenkinsfile

+165
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
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+
streamSplit = params.STREAM.split('-')
56+
if (params.STREAM.startsWith("rhel")) {
57+
RELEASE_BRANCH = "release-${streamSplit[1]}" // this extracts from the rhel format
58+
} else {
59+
RELEASE_BRANCH = "release-${streamSplit[0]}" // this extracts from the RHCOS format
60+
}
61+
RELEASE_BRANCH = "release-${params.STREAM.split('-')[0]}"
62+
63+
cosaPod(serviceAccount: "jenkins",
64+
image: params.COREOS_ASSEMBLER_IMAGE,
65+
memory: "512Mi", kvm: false,){
66+
try {
67+
shwrap("""
68+
git config --global user.name "CoreOS Bot"
69+
git config --global user.email "[email protected]"
70+
""")
71+
// Clone the openshift/installer repository and fetch the required release branch
72+
stage('Setup workspace') {
73+
shwrap("""
74+
git clone --depth=1 --branch main https://github.com/${releng_installer}.git
75+
cd installer
76+
git remote add upstream https://github.com/openshift/installer.git
77+
git fetch upstream ${RELEASE_BRANCH} --depth 1
78+
git checkout -b ${PR_BRANCH} upstream/${RELEASE_BRANCH}
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+
""")
97+
}
98+
99+
// Commit the updated metadata.
100+
stage('Create Pull Request') {
101+
//if (shwrap("git -C installer diff --exit-code") != 0){
102+
pr_title = "${params.BOOTIMAGE_BUG_ID}: Update RHCOS-${RELEASE_BRANCH} bootimage metadata to ${params.BUILD_VERSION}"
103+
commit_message = """
104+
Update RHCOS ${RELEASE_BRANCH} bootimage metadata to ${params.BUILD_VERSION}
105+
106+
The changes done here will update the RHCOS ${RELEASE_BRANCH} bootimage metadata and address the following issues:
107+
108+
${params.JIRA_ISSUES}
109+
110+
This change was generated using:
111+
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+
```
122+
""".stripIndent().trim()
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}" \\
136+
-X POST \\
137+
-d '{
138+
"title": "${pr_title}",
139+
"head": "coreosbot-releng:${PR_BRANCH}",
140+
"base": "${RELEASE_BRANCH}",
141+
"body": "${commit_message.replace("\n", "\\n").replace("\"", "\\\"")}"
142+
}' \\
143+
https://api.github.com/repos/openshift/installer/pulls --fail
144+
""")
145+
}
146+
//}
147+
currentBuild.result = 'SUCCESS'
148+
}
149+
} catch (e) {
150+
currentBuild.result = 'FAILURE'
151+
throw e
152+
} finally {
153+
def message = "[${params.STREAM}][bootimage-bump] #${env.BUILD_NUMBER} <${env.BUILD_URL}|:jenkins:> <${env.RUN_DISPLAY_URL}|:ocean:>"
154+
if (currentBuild.result == 'SUCCESS') {
155+
message = ":sparkles: ${message}"
156+
} else if (currentBuild.result == 'UNSTABLE') {
157+
message = ":warning: ${message}"
158+
} else {
159+
message = ":fire: ${message}"
160+
}
161+
echo message
162+
//pipeutils.trySlackSend(message: message)
163+
}
164+
}
165+
}

0 commit comments

Comments
 (0)