Last active
July 19, 2022 11:22
-
-
Save jakub-bochenski/66bff585a330e19a7bd5a33694059a0d to your computer and use it in GitHub Desktop.
Groovy Postbuild script to print a diff of all affected job configurations
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
def build = manager.build | |
def println = { manager.listener.logger.println(it) } | |
def since = build.startTimeInMillis | |
println 'Since : '+new Date(since) | |
def jobs = build | |
.getActions(javaposse.jobdsl.plugin.actions.GeneratedJobsBuildAction) | |
.collectMany{ action -> action.modifiedObjects.collect{ it.jobName } } | |
.collect{ manager.hudson.itemMap[it] } | |
println 'Count : '+jobs.size() | |
def filtered = jobs | |
.collect { it.getAction(hudson.plugins.jobConfigHistory.JobConfigHistoryProjectAction) } | |
.findAll { action -> | |
since <= action.jobConfigs[0].parsedDate().time | |
} | |
println 'Filtered : '+filtered.size() | |
filtered.each { action -> | |
action.metaClass.getDiff = { String timestamp1, String timestamp2 -> | |
final configXml1 = getOldConfigXml(timestamp1); | |
final String[] configXml1Lines = configXml1.asString().split("\\n"); | |
final configXml2 = getOldConfigXml(timestamp2); | |
final String[] configXml2Lines = configXml2.asString().split("\\n"); | |
getDiffAsString(configXml1.getFile(), | |
configXml2.getFile(), configXml1Lines, configXml2Lines); | |
} | |
if (action?.jobConfigs.size() > 1) | |
println action.getDiff(action.jobConfigs[1].date, action.jobConfigs[0].date) | |
else println "No diff for ${action}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment