Skip to content

Commit 98a6925

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 98a6925

File tree

1 file changed

+155
-0
lines changed

1 file changed

+155
-0
lines changed

Diff for: jobs/bootimagebump.Jenkinsfile

+155
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
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+
${params.JIRA_ISSUES}
108+
109+
This change was generated using:
110+
111+
```
112+
plume cosa2stream --target ${RHCOS_METADATA_FILE} \\
113+
--distro ${params.DISTRO} --no-signatures --name ${params.STREAM} \\
114+
--url ${params.URL} \\
115+
x86_64=${params.BUILD_VERSION} \\
116+
aarch64=${params.BUILD_VERSION} \\
117+
s390x=${params.BUILD_VERSION} \\
118+
ppc64le=${params.BUILD_VERSION}
119+
```
120+
""".stripIndent().trim()
121+
shwrap ("""
122+
cd installer
123+
git add ${RHCOS_METADATA_FILE}
124+
git commit -m '${commit_message}'
125+
""")
126+
127+
withCredentials([usernamePassword(credentialsId: botCreds,
128+
usernameVariable: 'GHUSER',
129+
passwordVariable: 'GHTOKEN')]) {
130+
shwrap("""
131+
cd installer
132+
git push -f https://\${GHUSER}:\${GHTOKEN}@github.com/${releng_installer} ${PR_BRANCH}
133+
curl -H "Authorization: token ${GHTOKEN}" -X POST -d '{ "title": "${pr_title}", "head": "coreosbot-releng:${PR_BRANCH}", "base": "${RELEASE_BRANCH}" }' https://api.github.com/repos/openshift/installer/pulls --fail
134+
""")
135+
}
136+
//}
137+
currentBuild.result = 'SUCCESS'
138+
}
139+
} catch (e) {
140+
currentBuild.result = 'FAILURE'
141+
throw e
142+
} finally {
143+
def message = "[${params.STREAM}][bootimage-bump] #${env.BUILD_NUMBER} <${env.BUILD_URL}|:jenkins:> <${env.RUN_DISPLAY_URL}|:ocean:>"
144+
if (currentBuild.result == 'SUCCESS') {
145+
message = ":sparkles: ${message}"
146+
} else if (currentBuild.result == 'UNSTABLE') {
147+
message = ":warning: ${message}"
148+
} else {
149+
message = ":fire: ${message}"
150+
}
151+
echo message
152+
//pipeutils.trySlackSend(message: message)
153+
}
154+
}
155+
}

0 commit comments

Comments
 (0)