Skip to content

Commit

Permalink
jobs: Add a bump-jenkins job
Browse files Browse the repository at this point in the history
bump-jenkins job added to periodically update the jenkins plugins to latest version

Co-authored-by: Michael Armijo <[email protected]>
Ref: coreos#562
  • Loading branch information
aaradhak and marmijo committed Oct 28, 2023
1 parent aa70ee8 commit 32fe533
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 9 deletions.
18 changes: 9 additions & 9 deletions jenkins/controller/plugins.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
# [1] https://github.com/openshift/jenkins/blob/master/2/contrib/openshift/bundle-plugins.txt
# [2] https://github.com/openshift/jenkins/blob/master/2/contrib/openshift/base-plugins.txt
# [3] https://github.com/openshift/jenkins#plugin-installation-for-centos7-v410
basic-branch-build-strategies:1.3.2
generic-webhook-trigger:1.84.2
github-oauth:0.39
kubernetes-credentials-provider:1.199.v4a_1d1f5d074f
pipeline-github:2.8-138.d766e30bb08b
slack:625.va_eeb_b_168ffb_0
timestamper:1.20
splunk-devops-extend:1.9.9
splunk-devops:1.9.9
basic-branch-build-strategies:81.v05e333931c7d
generic-webhook-trigger:1.87.0
github-oauth:588.vf696a_350572a_
kubernetes-credentials-provider:1.234.vf3013b_35f5b_a
pipeline-github:2.8-155.8eab375ac9f8
slack:684.v833089650554
timestamper:1.26
splunk-devops-extend:1.10.1
splunk-devops:1.10.1
antisamy-markup-formatter:162.v0e6ec0fcfcf6

# The below list are plugins that are also in base-plugins.txt but for
Expand Down
122 changes: 122 additions & 0 deletions jobs/bump-jenkins.Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import groovy.json.*
node {
checkout scm
// these are script global vars
pipeutils = load("utils.groovy")
pipecfg = pipeutils.load_pipecfg()
}

properties([
pipelineTriggers([
// check once a month
pollSCM('H H 1 * *')
]),
buildDiscarder(logRotator(
numToKeepStr: '100',
artifactNumToKeepStr: '100'
)),
durabilityHint('PERFORMANCE_OPTIMIZED')
])


def getPluginLatestURL(pluginName) {
def pluginsUpdate
node {
pluginsUpdate = shwrapCapture("curl -Ls -o /dev/null -w '%{url_effective}' https://updates.jenkins.io/download/plugins/${pluginName}/latest/${pluginName}.hpi")
}
return pluginsUpdate
}

def getPluginLatestVersion(pluginsUpdate) {
// Extract the plugin version from the URL
def versionPattern = /\/([^\/]+)\/([^\/]+)\/([^\/]+)\.hpi/
def matcher = (pluginsUpdate =~ versionPattern)
def pluginVersion

if (matcher.find()) {
def groupId = matcher.group(1)
pluginVersion = matcher.group(2)
} else {
println "Unable to extract plugin version from the URL."
}
return pluginVersion
}

lock(resource: "bump-jenkins") {
node{
try {
shwrap("""
git config --global user.name "CoreOS Bot"
git config --global user.email "[email protected]"
""")

def pluginslist
def pluginsToUpdate = [:]
def haveChanges=false
def branch = params.STREAM
def repo = "coreos/fedora-coreos-pipeline"

stage("Read plugins.txt") {
shwrapCapture("""
if [[ -d fedora-coreos-pipeline ]]; then
rm -rf fedora-coreos-pipeline
fi
git clone --branch jp https://github.com/aaradhak/fedora-coreos-pipeline.git
""")
def plugins_lockfile = "jenkins/controller/plugins.txt"
pluginslist = shwrapCapture("cat $plugins_lockfile | grep -v ^#").split('\n')
}

stage("Check for plugin updates") {
def pluginsUpdate
pluginslist.each { plugin ->
def parts = plugin.split(':')
if (parts.size() == 2) {
def pluginName = parts[0]
def currentVersion = parts[1]
pluginsUpdate = getPluginLatestURL(pluginName)
def latestVersion = getPluginLatestVersion(pluginsUpdate)
if (latestVersion.toString() != currentVersion.toString()) {
haveChanges = true
pluginsToUpdate["${pluginName}"] = [currentVersion, latestVersion]
println("Plugin: ${pluginName} current version is ${currentVersion}, it will be updated to latest version: ${latestVersion}")
shwrap("""
sed -i 's/${pluginName}:${currentVersion}/${pluginName}:${latestVersion}/g' jenkins/controller/plugins.txt
""")
}
else {
println("The latest version of ${pluginName} is already installed: ${currentVersion}")
}
}
else {
println("ERROR: unexpected")
}
}
}

/*stage("Push") {
if (haveChanges){
def message = "bump jenkins plugin version"
shwrap("git -C add jenkins/controller/plugins.txt")
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'")
withCredentials([usernamePassword(credentialsId: botCreds,
usernameVariable: 'GHUSER',
passwordVariable: 'GHTOKEN')]) {
}
}
} */

/*stage ("Create a Pull Request"){
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
}*/

} catch (e) {
currentBuild.result = 'FAILURE'
throw e
} finally {
if (currentBuild.result != 'SUCCESS') {
pipeutils.trySlackSend(message: "bump-lockfile #${env.BUILD_NUMBER} <${env.BUILD_URL}|:jenkins:> <${env.RUN_DISPLAY_URL}|:ocean:> [${params.STREAM}]")
}
}
}
}

0 comments on commit 32fe533

Please sign in to comment.