@@ -1128,3 +1128,89 @@ https://issues.jenkins-ci.org[Jenkins issue tracker].
11281128
11291129Refer to link:CONTRIBUTING.adoc#contributing-to-the-git-plugin[contributing to the plugin] for contribution guidelines.
11301130Refer to link:Priorities.adoc#git-plugin-development-priorities[plugin development priorities] for the prioritized list of development topics.
1131+
1132+ [#Remove Git Plugin BuildsByBranch BuildData Script]
1133+ == Remove Git Plugin BuildsByBranch BuildData Script
1134+
1135+ This script is used to remove the static list of BuildsByBranch that is
1136+ uselessly stored for each build by the Git Plugin.
1137+
1138+ * This is a workaround for the problem described here:
1139+ https://issues.jenkins-ci.org/browse/JENKINS-19022
1140+ * Updated to handle Matrix Project types.
1141+ * Updated to better support SCM Polling
1142+ * Updated to handle Projects inside Folders.
1143+ * Updated to handle Pipeline job types (just call getJobNames() to find
1144+ everything)
1145+
1146+ [source,syntaxhighlighter-pre]
1147+ ----
1148+ import hudson.matrix.*
1149+ import hudson.model.*
1150+
1151+ hudsonInstance = hudson.model.Hudson.instance
1152+ jobNames = hudsonInstance.getJobNames()
1153+ allItems = []
1154+ for (name in jobNames) {
1155+ allItems += hudsonInstance.getItemByFullName(name)
1156+ }
1157+
1158+ // Iterate over all jobs and find the ones that have a hudson.plugins.git.util.BuildData
1159+ // as an action.
1160+ //
1161+ // We then clean it by removing the useless array action.buildsByBranchName
1162+ //
1163+
1164+ for (job in allItems) {
1165+ println("job: " + job.name);
1166+ def counter = 0;
1167+ for (build in job.getBuilds()) {
1168+ // It is possible for a build to have multiple BuildData actions
1169+ // since we can use the Mulitple SCM plugin.
1170+ def gitActions = build.getActions(hudson.plugins.git.util.BuildData.class)
1171+ if (gitActions != null) {
1172+ for (action in gitActions) {
1173+ action.buildsByBranchName = new HashMap<String, Build>();
1174+ hudson.plugins.git.Revision r = action.getLastBuiltRevision();
1175+ if (r != null) {
1176+ for (branch in r.getBranches()) {
1177+ action.buildsByBranchName.put(branch.getName(), action.lastBuild)
1178+ }
1179+ }
1180+ build.actions.remove(action)
1181+ build.actions.add(action)
1182+ build.save();
1183+ counter++;
1184+ }
1185+ }
1186+ if (job instanceof MatrixProject) {
1187+ def runcounter = 0;
1188+ for (run in build.getRuns()) {
1189+ gitActions = run.getActions(hudson.plugins.git.util.BuildData.class)
1190+ if (gitActions != null) {
1191+ for (action in gitActions) {
1192+ action.buildsByBranchName = new HashMap<String, Build>();
1193+ hudson.plugins.git.Revision r = action.getLastBuiltRevision();
1194+ if (r != null) {
1195+ for (branch in r.getBranches()) {
1196+ action.buildsByBranchName.put(branch.getName(), action.lastBuild)
1197+ }
1198+ }
1199+ run.actions.remove(action)
1200+ run.actions.add(action)
1201+ run.save();
1202+ runcounter++;
1203+ }
1204+ }
1205+ }
1206+ if (runcounter > 0) {
1207+ println(" -->> cleaned: " + runcounter + " runs");
1208+ }
1209+ }
1210+ }
1211+ if (counter > 0) {
1212+ println("-- cleaned: " + counter + " builds");
1213+ }
1214+ }
1215+ ----
1216+
0 commit comments