Build nested report.

This commit is contained in:
Manuele Simi 2020-03-11 11:22:06 -04:00
parent a9a68135ea
commit b05eb2f1b7
1 changed files with 37 additions and 41 deletions

78
Jenkinsfile vendored
View File

@ -46,25 +46,12 @@ pipeline {
def downstreamdeps = [:] def downstreamdeps = [:]
report['downstream_modules'] = [:] report['downstream_modules'] = [:]
report['downstream_projects'] = [] report['downstream_projects'] = []
projects2artifacts[inputProject].each { a -> report['downstream_modules']['L1'] = [:]
report['downstream_modules'][a] = [:] projects2artifacts[inputProject].each { a -> report = analyzeDependency(modules2deps, artifacts2projects, report, a, 1)}
report['downstream_modules'][a]['dependencies'] = [] println report
report['downstream_modules'][a]['projects'] = [] printReport(report)
}
projects2artifacts[inputProject].each { a ->
report['downstream_modules'][a]['dependencies'].addAll(findDownstreamDependencies(modules2deps, a))
println "${a} is used by ${report['downstream_modules'][a]['dependencies']}"
}
// then we look for the projects that build the downstream dependencies }
report['downstream_modules'].each { module, deps ->
deps['dependencies'].each { d ->
report['downstream_modules'][module]['projects'] << artifacts2projects[d]
report['downstream_projects'] << artifacts2projects[d]
}
}
}
printReport(report)
} }
} }
} }
@ -76,33 +63,43 @@ def findDownstreamDependencies(modules2deps, artifact) {
downdeps downdeps
} }
def findProject(projects2artifacts, artifact) { def analyzeDependency(modules2deps, artifacts2projects, report, artifact,deep) {
println "Looking for project that builds ${artifact}" def level = "L${deep}"
def name = "" report['downstream_modules'][level][artifact] = [ 'dependencies':[], 'projects':[] ]
projects2artifacts.each { k,v -> if (v.contains("${artifact}")) name = k } report['downstream_modules'][level][artifact]['dependencies'].addAll(findDownstreamDependencies(modules2deps, artifact))
name println "${artifact} is used by ${report['downstream_modules'][level][artifact]['dependencies']}"
// then we look for the projects that build the downstream dependencies
report['downstream_modules'][level][artifact]['dependencies'].each { d ->
report['downstream_modules'][level][artifact]['projects'] << artifacts2projects[d]
report['downstream_projects'] << artifacts2projects[d]
}
report
} }
def printReport(report) { def printReport(report) {
def text = '' def text = ''
def indent = '' def indent = '\t'
text += "Dependency Report for ${report['project']} (jenkins project)" text += "Dependency Report for ${report['project']} (jenkins project)"
text += "\n\n" text += "\n\n"
text += "Project Modules\n" text += "Project Modules\n"
indent += '\t' report['downstream_modules'].each { deep, artifacts ->
report['downstream_modules'].each { module, deps -> artifacts.each { name, data ->
text += "${indent}Module Name: ${module}\n" text += "${indent}Module Name: ${name}\n"
text += "${indent}\tDownstream Modules for ${module}\n" text += "${indent}Dependency Level: ${deep}\n"
deps['dependencies'].each { d -> text += "${indent}\tDownstream Modules for ${name}\n"
text += "${indent}\t\t${d}" data['dependencies'].each {d ->
text += "\n" text += "${indent}\t\t${d}"
} text += "\n"
text += "${indent}\tDownstream Projects for ${module}\n" }
deps['projects'].each { p -> text += "${indent}\tDownstream Projects for ${name}\n"
text += "${indent}\t\t${p}" data['projects'].each { p ->
text += "\n" text += "${indent}\t\t${p}"
} text += "\n"
} }
}
}
text += "\n\n" text += "\n\n"
text += "All Downstream Projects\n" text += "All Downstream Projects\n"
report['downstream_projects'].each { p -> report['downstream_projects'].each { p ->
@ -111,11 +108,10 @@ def printReport(report) {
} }
println text println text
} }
/*
def printJob(job) { def printJob(job) {
println("fullname ${job.fullName}") println("fullname ${job.fullName}")
println("name ${job.name}") println("name ${job.name}")
println("display name ${job.displayName}") println("display name ${job.displayName}")
job.getAllJobs().each {j -> println ("dep: ${j.name}")} job.getAllJobs().each {j -> println ("dep: ${j.name}")}
} }
*/