forked from coreos/fedora-coreos-pipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
2 changed files
with
241 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
pick 875cef7 jobs: Add a bump-jenkins job | ||
f f02f1a4 Remove parameters from properties | ||
f 511a6d2 Remove cosa pod | ||
f e4f7c9f Remove cosa def | ||
f aa5e280 Added node | ||
f b030274 Removed comment lines | ||
f 1c863b1 Node in push | ||
f 2fbe545 node print | ||
f 24120e2 push stage print | ||
f 5ea12f6 Node push | ||
f 54c6bf8 Changes | ||
f 452028f Revert it back to two commits earlier | ||
f 8310722 sed command | ||
f 2c0d88c node sed | ||
f 434f2f9 Print test sed | ||
f 615b5f2 Missed " | ||
f 405d374 shwrapCapture | ||
f 14683fa shrwapCap tet | ||
f 004c7b5 Update basic branch build plugin version | ||
f b7965dd All plugins updated | ||
f 59452de encompanss node for the entire code | ||
f 323ee17 remove node | ||
f 5cff652 missing } | ||
f e7b9f94 Comment git push | ||
f 3a1ed21 PRINT STATEMENT | ||
f 31e1f8d add more print statements | ||
f 6d514f2 Print statements before node | ||
f d7639b9 print before stage | ||
f 75d265e Removed sed in stage modified | ||
f 34cb67e remove node | ||
f c309167 Reverted to the first commit | ||
f d100970 Cleaning the original code | ||
f 33bab27 params.stream | ||
f 73109c6 Reverted to original code with changes in paramenters | ||
f c8dd55e original code again | ||
f f37a591 comment the parameters out | ||
f c48380b Comment out push stage | ||
f 133ea77 Added parameters | ||
f edd925f Comment out modified plugins stage | ||
f 4f9b0e4 remove cosa pod and timeout | ||
f 5d1a128 Revert the cosa pod and timeout | ||
f a264eba Node for entire code | ||
f 0f59e66 revert node | ||
f f2dbafa Branch is main | ||
f d2c4f1e Branch is params.STREAM | ||
f a21ceb8 Comment out parameters | ||
f f9d060f Comment cosa pod | ||
f 69f318d Added node for shwrap | ||
f e67ffee Encompass entire try with node | ||
f 9f4c295 Remove git credentials | ||
f b614c7a Comment finally | ||
f 27b879d Clear the parameters and cosa pod commentts | ||
f 324558a Encompass the wholel code within node | ||
f 92c5fb4 Change node enclosure | ||
f 788b0f0 Cleaned node comments | ||
f dc915ce Use sed command to rewrite plugins.txt | ||
f 9d03c59 shwrapCapture of sed | ||
f d46f2bb writefile added | ||
f 619bf77 Print modtxt | ||
f 6642946 Add stage modify plugins | ||
f 61fa6f6 removed node in writeFile | ||
f 531ba8d Add sed back | ||
f d077e46 Added node to writefile | ||
f 97adf68 move the sed command from stage mod to stage update | ||
f 5c271de Test AT in writeFile | ||
f da1bb88 experimenting with modtxt in writefile | ||
f 408bd53 New stage with sed | ||
f 1cc706d Sh to shwrapcature | ||
f 6f3ca7e Revert to sh | ||
f d095bf6 Remove stage update | ||
f a575e0c Shwrap | ||
f 83f78f9 Removed } | ||
f 9025a3e COmment out stage push | ||
f 42d11e3 Remove edit plugins | ||
f 6a74ae3 Revert to params.STREAM | ||
f 82e3415 Add git push | ||
f 53ffda7 Typi in haveChanges | ||
f 51692ac remove stage edit and push and add sed in stage update | ||
f e27ebce Added modtxt | ||
f 557b93d Add stage pull req | ||
f 3fe4395 REmove */ | ||
f f88870d Comment create PR | ||
f 247b6cd print modtxt | ||
f ccad06b shwrapcapture to shwrap | ||
f 3cba6da Remove unwanted lines | ||
f 0165ec7 Remove print statements | ||
f 473c48a remove two more print statements | ||
f 1fb82ba Add finally | ||
|
||
# Rebase aa70ee8..1fb82ba onto aa70ee8 (88 commands) | ||
# | ||
# Commands: | ||
# p, pick <commit> = use commit | ||
# r, reword <commit> = use commit, but edit the commit message | ||
# e, edit <commit> = use commit, but stop for amending | ||
# s, squash <commit> = use commit, but meld into previous commit | ||
# f, fixup [-C | -c] <commit> = like "squash" but keep only the previous | ||
# commit's log message, unless -C is used, in which case | ||
# keep only this commit's message; -c is same as -C but | ||
# opens the editor | ||
# x, exec <command> = run command (the rest of the line) using shell | ||
# b, break = stop here (continue rebase later with 'git rebase --continue') | ||
# d, drop <commit> = remove commit | ||
# l, label <label> = label current HEAD with a name | ||
# t, reset <label> = reset HEAD to a label | ||
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>] | ||
# create a merge commit using the original merge commit's | ||
# message (or the oneline, if no original merge commit was | ||
# specified); use -c <commit> to reword the commit message | ||
# u, update-ref <ref> = track a placeholder for the <ref> to be updated | ||
# to this position in the new commits. The <ref> is | ||
# updated at the end of the rebase | ||
# | ||
# These lines can be re-ordered; they are executed from top to bottom. | ||
# | ||
# If you remove a line here THAT COMMIT WILL BE LOST. | ||
# | ||
# However, if you remove everything, the rebase will be aborted. | ||
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}]") | ||
} | ||
} | ||
} | ||
} |