2020-03-10 18:40:40 +01:00
|
|
|
|
|
|
|
def counts = 0
|
2020-03-10 21:16:09 +01:00
|
|
|
def projects2artifacts = [:]
|
|
|
|
def modules2deps = [:]
|
|
|
|
def inputProject = 'storagehub-client-library'
|
2020-03-10 18:40:40 +01:00
|
|
|
|
|
|
|
pipeline {
|
|
|
|
agent {
|
|
|
|
label 'CD'
|
|
|
|
}
|
|
|
|
stages {
|
|
|
|
stage('walking projects') {
|
|
|
|
steps {
|
|
|
|
script {
|
|
|
|
Jenkins.getInstance().getAllItems(TopLevelItem.class).each { p ->
|
|
|
|
projects2artifacts[p.name] = []
|
|
|
|
p.getAllJobs().each { j -> projects2artifacts[p.name] << j.name }
|
|
|
|
}
|
|
|
|
println "FOUND ${projects2artifacts.size()} projects"
|
|
|
|
projects2artifacts.each { k,v -> println ("PROJECT ${k} BUILDS ${v}") }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stage('walking maven modules') {
|
|
|
|
steps {
|
|
|
|
script {
|
|
|
|
// get all the maven modules and their dependencies
|
|
|
|
Jenkins.getInstance().getAllItems(hudson.maven.MavenModule.class).each { m ->
|
|
|
|
modules2deps[m.name] = []
|
2020-03-10 19:01:00 +01:00
|
|
|
m.getDependencies().each { d -> modules2deps[m.name] << "${d.groupId}:${d.artifactId}" }
|
2020-03-10 18:40:40 +01:00
|
|
|
}
|
|
|
|
println "FOUND ${modules2deps.size()} modules"
|
2020-03-10 21:16:09 +01:00
|
|
|
//modules2deps.each { k,v -> println ("MODULE ${k} DEPENDS on ${v}") }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stage('find downstream projects') {
|
|
|
|
steps {
|
|
|
|
script {
|
|
|
|
println "PROJECT ${inputProject} BUILDS ${projects2artifacts[inputProject]} artifacts"
|
|
|
|
// first, let's find out what components depends on the project's artifacts
|
|
|
|
def downstreamdeps = [:]
|
|
|
|
projects2artifacts[inputProject].each { a ->
|
|
|
|
downstreamdeps[a] = []
|
|
|
|
downstreamdeps[a] << findDownstreamDependencies(modules2deps, a)
|
|
|
|
println "${a} is used by ${downstreamdeps[a]}"
|
|
|
|
|
|
|
|
}
|
|
|
|
// then we look for the projects that build the downstream dependencies
|
|
|
|
//downstreamdeps.each { k, v ->
|
|
|
|
// println "${k} is build by ${findProject()}"
|
|
|
|
//}
|
2020-03-10 18:40:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-03-10 21:16:09 +01:00
|
|
|
def findDownstreamDependencies(modules2deps, artifact) {
|
|
|
|
def downdeps = []
|
|
|
|
println "Looking for users of ${artifact}"
|
|
|
|
modules2deps.each { k,v -> if (v.contains("${artifact}")) downdeps << k }
|
|
|
|
downdeps
|
|
|
|
}
|
|
|
|
|
|
|
|
def findProject(projects2artifacts, artifact) {
|
|
|
|
println "Looking for project that builds ${artifact}"
|
|
|
|
projects2artifacts.find { k,v -> v.contains("${artifact}")}.first.key
|
|
|
|
}
|
|
|
|
|
2020-03-10 18:40:40 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
def printJob(job) {
|
|
|
|
println("fullname ${job.fullName}")
|
|
|
|
println("name ${job.name}")
|
|
|
|
println("display name ${job.displayName}")
|
|
|
|
job.getAllJobs().each {j -> println ("dep: ${j.name}")}
|
|
|
|
}
|
|
|
|
*/
|