87 lines
2.4 KiB
Groovy
87 lines
2.4 KiB
Groovy
def waitForRepoPackage(String packageName, Map params = [:]) {
|
|
def expectedVersion = params.expectedVersion ? params.expectedVersion : null
|
|
def delay = params.delay ? params.delay : 30
|
|
def waitTimeout = params.timeout ? params.timeout : 2400
|
|
|
|
def message = "Waiting for package '${packageName}'"
|
|
if (expectedVersion != null) {
|
|
message += " with version '${expectedVersion}'"
|
|
}
|
|
message += '...'
|
|
println(message)
|
|
|
|
timeout(time: waitTimeout, unit: 'SECONDS') {
|
|
while(true) {
|
|
println("Retrieving packages list...")
|
|
def repo = listRepoPackages(params)
|
|
|
|
def packages = repo[packageName]
|
|
if (!packages) {
|
|
println("Package not found.")
|
|
sleep(time: delay, unit: 'SECONDS')
|
|
continue
|
|
}
|
|
|
|
if (expectedVersion == null) {
|
|
println("Package found !")
|
|
break
|
|
}
|
|
|
|
def versionFound = packages.find {
|
|
def matches = it['version'] =~ expectedVersion
|
|
println("Comparing expected version '${expectedVersion}' to '${it['version']}': ${matches}")
|
|
return matches
|
|
}
|
|
|
|
if (versionFound) {
|
|
println("Expected package version found !")
|
|
break
|
|
}
|
|
|
|
println("Package version not found.")
|
|
sleep(time: delay, unit: 'SECONDS')
|
|
}
|
|
}
|
|
}
|
|
|
|
def listRepoPackages(Map params = [:]) {
|
|
def baseURL = params.baseURL ? params.baseURL : 'https://vulcain.cadoles.com'
|
|
def distrib = params.distrib ? params.distrib : '2.7.0-dev'
|
|
def component = params.component ? params.component : 'main'
|
|
def type = params.type ? params.type : 'binary'
|
|
def arch = params.arch ? params.arch : 'amd64'
|
|
|
|
def response = httpRequest(url: "${baseURL}/dists/${distrib}/${component}/${type}-${arch}/Packages")
|
|
|
|
def packages = [:]
|
|
def lines = response.content.split('\n')
|
|
|
|
def currentPackage
|
|
lines.each {
|
|
def packageMatch = (it =~ /^Package: (.*)$/)
|
|
if (packageMatch.find()) {
|
|
def packageName = packageMatch.group(1)
|
|
|
|
if (!packages[packageName]) {
|
|
packages[packageName] = []
|
|
}
|
|
|
|
currentPackage = [:]
|
|
currentPackage['name'] = packageName
|
|
packages[packageName] += currentPackage
|
|
}
|
|
|
|
def versionMatch = (it =~ /^Version: (.*)$/)
|
|
if (versionMatch.find()) {
|
|
def version = versionMatch.group(1)
|
|
currentPackage['version'] = version
|
|
}
|
|
}
|
|
|
|
println "Found packages:"
|
|
packages.each{
|
|
println " - Package: ${it.key}, Version: ${it.value['version']}"
|
|
}
|
|
|
|
return packages
|
|
} |