Maven modules which no longer exist in a reactor project appear in the Jenkins build report as "didn't run"

If, for some reason, Delete All Disabled Modules is not available, then you can run this Groovy script in Manage Jenkins -> Script Console (https://<JENKINS_URL>/script). Based upon a script I found on the Jenkins Jira and improved with feedback here on Stack Overflow.

import jenkins.model.Jenkins
import hudson.maven.MavenModuleSet
import hudson.model.Result

Jenkins.instance
    .getAllItems(Job.class)
    .findAll({ job -> job instanceof MavenModuleSet })
    .each {
  job ->
    build = job.getLastBuild()
    if (build && build.getResult() == Result.SUCCESS) {
      println("==> Processing job " + job.name)
      build.getModuleBuilds().each {
        module, build ->
          if (build.isEmpty()) {
            //module.delete()
            println("  --> Deleted module " + module.name)
          }
      }
    } else {
      println("Warning: Skipped job " + job.name + " because its last build failed.")
    }
}

return null

How to use:

  1. Run the script first without any edits (it's safe, really!).
  2. Go through the list of changes to check for unwanted deletes.
  3. Uncomment module.delete().
  4. Run the (edited) script again.

Side effect: any archived builds that still had that module in the past, will no longer have the deleted module. In my use case this was acceptable.


Have you tried the action Delete All Disabled Modules available between Configure and Modules on the project page ?


Here is a script that will walk over all maven jobs and delete all modules that didn't run on the last successful build.

import jenkins.model.Jenkins
import hudson.maven.MavenModuleSet
import hudson.model.Result

Jenkins.instance.items.findAll({job -> job instanceof MavenModuleSet}).each {
  job ->
    build = job.getLastBuild()
    if(build && build.getResult() == Result.SUCCESS) {
      println("==> Processing job " + job.name)
      build.getModuleBuilds().each {
        module, build ->
          if(build.isEmpty()) {
            //module.delete()
            println("    --> Deleted module " + module.name)
          }
      }
    } else {
      println("Warning: Skipped job " + job.name + " because its last build failed.")
    }
}

return null

How to use:

  • Run it without edits
  • Go through the list of changes to check for unwanted deletes
  • Uncomment module.delete() and run it again

Tags:

Maven

Jenkins