Jenkins/vars/debian.groovy

88 lines
2.6 KiB
Groovy
Raw Normal View History

2020-03-19 17:00:36 +01:00
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 asPattern = params.containsKey("asPattern") ? params.asPattern : true
2020-03-19 17:00:36 +01:00
def message = "Waiting for package '${packageName}'"
if (expectedVersion != null) {
2020-05-06 10:22:42 +02:00
message += " with version '${expectedVersion}'"
2020-03-19 17:00:36 +01:00
}
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
}
2020-03-19 17:00:36 +01:00
def versionFound = packages.find {
def matches = asPattern ? it['version'] =~ expectedVersion : it['version'] == expectedVersion
println("Comparing expected version '${expectedVersion}' to '${it['version']}': ${matches}")
return matches
2020-03-19 17:00:36 +01:00
}
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(ignoreSslErrors: true, url: "${baseURL}/dists/${distrib}/${component}/${type}-${arch}/Packages")
2020-03-19 17:00:36 +01:00
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']}"
}
2020-03-19 17:00:36 +01:00
return packages
}