Created
February 24, 2021 17:55
-
-
Save marcelaraujo/992a5de5207b806123507a914a6981db to your computer and use it in GitHub Desktop.
Extract Libraries from job executions
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
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