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