Skip to content

Instantly share code, notes, and snippets.

@marcelaraujo
Created February 24, 2021 17:55
Show Gist options
  • Save marcelaraujo/992a5de5207b806123507a914a6981db to your computer and use it in GitHub Desktop.
Save marcelaraujo/992a5de5207b806123507a914a6981db to your computer and use it in GitHub Desktop.
Extract Libraries from job executions
import java.util.regex.Pattern
import java.util.regex.Matcher
import jenkins.branch.BranchSource
import org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject
Pattern p = Pattern.compile("Loading\\slibrary\\s(jenkins-(\\w+)-library(@.*)?)");
Jenkins.instance.getAllItems(WorkflowMultiBranchProject.class).each { it ->
if (it.fullName.contains("Maintenance")) {
return
}
//def source = it.getSourcesList().get(BranchSource.class).getSource()
//def owner = source.repoOwner
//def repository = source.repository
//println "${owner}/${repository}"
//println it.getAllJobs().dump()
def job = it.getAllJobs().find{ job -> job.asItem().name == "master" }
Run lastBuild = job?.getLastBuild();
if (lastBuild == null) {
println "${it.fullName} - this job has never been run"
//Job has never run
return
}
try {
def log = lastBuild.getLog()
//println log.length()
Matcher matcher = p.matcher(log);
while(matcher.find()) {
println matcher.group(1)
}
} catch(Exception e) {
println "Error on file read action: " + e.getMessage()
}
}
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment