Skip to content

Instantly share code, notes, and snippets.

@phaneesh
Created July 29, 2019 06:37
Show Gist options
  • Save phaneesh/80ea58a37b5fe1b597e4d5d426926561 to your computer and use it in GitHub Desktop.
Save phaneesh/80ea58a37b5fe1b597e4d5d426926561 to your computer and use it in GitHub Desktop.
Get Branch invalid/non-standard configuration from Jenkins
import hudson.model.*
import hudson.maven.MavenModuleSet
import hudson.tasks.*
import hudson.plugins.git.GitSCM
//List valid branches that can be built
def validBranches = ["develop","master"]
Hudson.instance.items.each {
if(it.getScm() instanceof GitSCM) {
Set branchNames = []
it.getScm().getBranches().each { b ->
if(!validBranches.contains(b.getName().replaceAll("\\*","").replaceAll("/", ""))) {
branchNames.add(b.getName().replaceAll("\\*","").replaceAll("/", ""))
}
if(!branchNames.isEmpty()) {
println(it.name + " - " +branchNames)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment