Skip to content

Commit 73ce554

Browse files
aaradhakmarmijo
andcommitted
jobs: Add a bump-jenkins job
bump-jenkins job added to periodically update the jenkins plugins to latest version Co-authored-by: Michael Armijo <[email protected]> Ref: coreos#562
1 parent aa70ee8 commit 73ce554

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed

jobs/bump-jenkins.Jenkinsfile

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
import groovy.json.*
2+
node {
3+
checkout scm
4+
// these are script global vars
5+
pipeutils = load("utils.groovy")
6+
pipecfg = pipeutils.load_pipecfg()
7+
}
8+
9+
properties([
10+
pipelineTriggers([
11+
// check once a month
12+
pollSCM('H H 1 * *')
13+
]),
14+
buildDiscarder(logRotator(
15+
numToKeepStr: '100',
16+
artifactNumToKeepStr: '100'
17+
)),
18+
durabilityHint('PERFORMANCE_OPTIMIZED')
19+
])
20+
21+
22+
def getPluginLatestURL(pluginName) {
23+
def pluginsUpdate
24+
node {
25+
pluginsUpdate = shwrapCapture("curl -Ls -o /dev/null -w '%{url_effective}' https://updates.jenkins.io/download/plugins/${pluginName}/latest/${pluginName}.hpi")
26+
}
27+
return pluginsUpdate
28+
}
29+
30+
def getPluginLatestVersion(pluginsUpdate) {
31+
// Extract the plugin version from the URL
32+
def versionPattern = /\/([^\/]+)\/([^\/]+)\/([^\/]+)\.hpi/
33+
def matcher = (pluginsUpdate =~ versionPattern)
34+
def pluginVersion
35+
36+
if (matcher.find()) {
37+
def groupId = matcher.group(1)
38+
pluginVersion = matcher.group(2)
39+
} else {
40+
println "Unable to extract plugin version from the URL."
41+
}
42+
return pluginVersion
43+
}
44+
45+
lock(resource: "bump-jenkins") {
46+
node{
47+
try {
48+
shwrap("""
49+
git config --global user.name "CoreOS Bot"
50+
git config --global user.email "[email protected]"
51+
""")
52+
53+
def pluginslist
54+
def pluginsToUpdate = [:]
55+
def haveChanges=false
56+
def branch = params.STREAM
57+
def repo = "coreos/fedora-coreos-pipeline"
58+
59+
stage("Read plugins.txt") {
60+
shwrapCapture("""
61+
if [[ -d fedora-coreos-pipeline ]]; then
62+
rm -rf fedora-coreos-pipeline
63+
fi
64+
git clone --branch jp https://github.com/aaradhak/fedora-coreos-pipeline.git
65+
""")
66+
def plugins_lockfile = "jenkins/controller/plugins.txt"
67+
pluginslist = shwrapCapture("cat $plugins_lockfile | grep -v ^#").split('\n')
68+
}
69+
70+
stage("Check for plugin updates") {
71+
def pluginsUpdate
72+
pluginslist.each { plugin ->
73+
def parts = plugin.split(':')
74+
if (parts.size() == 2) {
75+
def pluginName = parts[0]
76+
def currentVersion = parts[1]
77+
pluginsUpdate = getPluginLatestURL(pluginName)
78+
def latestVersion = getPluginLatestVersion(pluginsUpdate)
79+
if (latestVersion.toString() != currentVersion.toString()) {
80+
haveChanges = true
81+
pluginsToUpdate["${pluginName}"] = [currentVersion, latestVersion]
82+
println("Plugin: ${pluginName} current version is ${currentVersion}, it will be updated to latest version: ${latestVersion}")
83+
shwrap("""
84+
sed -i 's/${pluginName}:${currentVersion}/${pluginName}:${latestVersion}/g' jenkins/controller/plugins.txt
85+
""")
86+
}
87+
else {
88+
println("The latest version of ${pluginName} is already installed: ${currentVersion}")
89+
}
90+
}
91+
else {
92+
println("ERROR: unexpected")
93+
}
94+
}
95+
}
96+
97+
/*stage("Push") {
98+
if (haveChanges){
99+
def message = "bump jenkins plugin version"
100+
shwrap("git -C add jenkins/controller/plugins.txt")
101+
shwrap("git -C commit -m '${message}' -m 'Job URL: ${env.BUILD_URL}' -m 'Job definition: https://github.com/coreos/fedora-coreos-pipeline/blob/main/jobs/bump-jenkins.Jenkinsfile'")
102+
withCredentials([usernamePassword(credentialsId: botCreds,
103+
usernameVariable: 'GHUSER',
104+
passwordVariable: 'GHTOKEN')]) {
105+
}
106+
}
107+
} */
108+
109+
/*stage ("Create a Pull Request"){
110+
curl -H "Authorization: token ${coreosbot_token}" -X POST -d '{"title": "Stream metadata for ${params.STREAM} release ${params.VERSION}","head": "${pr_branch}","base": "master"}' https://api.github.com/repos/coreos/fedora-coreos-streams/pulls
111+
}*/
112+
113+
} catch (e) {
114+
currentBuild.result = 'FAILURE'
115+
throw e
116+
} finally {
117+
if (currentBuild.result != 'SUCCESS') {
118+
pipeutils.trySlackSend(message: "bump-lockfile #${env.BUILD_NUMBER} <${env.BUILD_URL}|:jenkins:> <${env.RUN_DISPLAY_URL}|:ocean:> [${params.STREAM}]")
119+
}
120+
}
121+
}
122+
}

0 commit comments

Comments
 (0)