Last active
June 26, 2019 09:19
-
-
Save jimklimov/48227cb3b9ccc8968efd5b814868baa5 to your computer and use it in GitHub Desktop.
List currently known Jenkins jobs along with their status and labels, if any
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
// List currently known Jenkins jobs along with their status and labels, if any. | |
// Primary use-case for us is to find enabled obsolete jobs, we have a few | |
// we don't want deleted just yet, and to avoid enabled jobs without an agent | |
// label assigned so they are not picked up by random unsuitable machines. | |
import hudson.model.Job | |
//getAllItems searches a global lookup table of items regardless of folder structure | |
Jenkins.instance.getAllItems(Job.class).each { Job job -> | |
String jobLabelString | |
String jobStatus | |
try { | |
jobStatus = (job.disabled ? "DISABLED" : "ENABLED" ) | |
} catch (Exception e) { | |
// e.g. pipeline generated jobs | |
jobStatus = "Status:N/A" | |
} | |
try { | |
jobLabelString = job.getAssignedLabelString() | |
} catch (Exception e) { | |
jobLabelString = "N/A" | |
} | |
//if ( jobLabelString == null || jobLabelString.equals("") || jobLabelString.equals("N/A") ) return | |
println jobStatus + ":\t'" + job.fullName + "' \tLABEL(S): '" + jobLabelString + "' \tCFGURL: " + job.getAbsoluteUrl() + "configure" | |
} | |
//null so no result shows up | |
null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment