2019-01-24 17:39:18 +01:00
|
|
|
def buildPackageWithCPKG(
|
|
|
|
String packageProfile = "debian",
|
|
|
|
String packageArch = "",
|
2019-02-05 12:32:12 +01:00
|
|
|
String packageBranch = "",
|
2019-01-24 17:39:18 +01:00
|
|
|
String baseImage = "",
|
|
|
|
String destDir = "./packages",
|
2019-02-20 15:30:20 +01:00
|
|
|
Boolean forceRebuild = false
|
2019-01-24 17:39:18 +01:00
|
|
|
) {
|
|
|
|
|
2019-02-20 15:30:20 +01:00
|
|
|
def builds = []
|
|
|
|
|
2019-01-24 17:39:18 +01:00
|
|
|
// Retrieve commit tags
|
|
|
|
def commitTags = sh(script: 'git describe --exact-match --abbrev=0', returnStdout: true).split(' ')
|
|
|
|
if (commitTags.length == 0) {
|
|
|
|
error 'No build build tags on last commit'
|
|
|
|
}
|
|
|
|
|
|
|
|
// For each tags
|
|
|
|
for (tag in commitTags) {
|
|
|
|
|
|
|
|
// Split tag to retrieve context informations
|
|
|
|
def tagParts = tag.split('/')
|
|
|
|
def packageEnv = tagParts[1]
|
|
|
|
def packageDistrib = tagParts[2]
|
|
|
|
def packageVersion = tagParts[3]
|
|
|
|
|
|
|
|
// Create .tamarinrc file
|
|
|
|
def tamarinrc = """
|
|
|
|
project_version=${packageVersion}
|
|
|
|
no_version_suffix=${ packageEnv == 'stable' || packageEnv == 'staging' ? 'yes' : 'no' }
|
|
|
|
""".stripIndent()
|
|
|
|
writeFile file: '.tamarinrc', text: tamarinrc
|
|
|
|
|
2019-02-20 15:30:20 +01:00
|
|
|
sh "rm -rf ${destDir}/*"
|
|
|
|
|
2019-01-24 17:39:18 +01:00
|
|
|
stage("Build ${packageEnv} package (version ${packageVersion}) for ${packageDistrib}") {
|
2019-02-20 15:30:20 +01:00
|
|
|
def result = [:]
|
|
|
|
result.put('tag', tag)
|
|
|
|
result.put('env', packageEnv)
|
|
|
|
result.put('version', packageVersion)
|
|
|
|
result.put('distrib', packageDistrib)
|
|
|
|
def packages = buildPackage(packageProfile, packageArch, baseImage, destDir, forceRebuild)
|
|
|
|
result.put('packages', packages)
|
|
|
|
builds << result
|
2019-01-24 17:39:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-02-20 15:30:20 +01:00
|
|
|
return builds
|
|
|
|
|
2019-01-24 17:39:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
def buildPackage(
|
|
|
|
String packageProfile = "debian",
|
|
|
|
String packageArch = "",
|
2019-02-05 12:32:12 +01:00
|
|
|
String baseImage = "",
|
2019-01-24 17:39:18 +01:00
|
|
|
String destDir = "./packages",
|
|
|
|
Boolean forceRebuild = false
|
|
|
|
) {
|
|
|
|
|
2019-02-20 15:30:20 +01:00
|
|
|
def tamarinImage
|
|
|
|
def packages = []
|
2019-01-24 17:39:18 +01:00
|
|
|
|
|
|
|
stage("Create Tamarin environment") {
|
|
|
|
tamarinImage = buildDockerImage()
|
|
|
|
}
|
|
|
|
|
|
|
|
stage("Run Tamarin") {
|
|
|
|
def dockerArgs = """
|
|
|
|
-v /var/run/docker.sock:/var/run/docker.sock
|
|
|
|
${forceRebuild ? '-e TAMARIN_FORCE_REBUILD=1' : ''}
|
|
|
|
${packageArch ? '-e TAMARIN_PACKAGE_ARCH='+packageArch : ''}
|
|
|
|
${baseImage ? '-e TAMARIN_BASE_IMAGE='+baseImage : ''}
|
|
|
|
${packageProfile ? '-e TAMARIN_PROFILE='+packageProfile : ''}
|
|
|
|
-e TAMARIN_DEST_DIR=${destDir}
|
|
|
|
""".stripIndent()
|
|
|
|
|
|
|
|
tamarinImage.inside(dockerArgs) {
|
|
|
|
sh 'run-tamarin'
|
|
|
|
}
|
2019-02-20 15:30:20 +01:00
|
|
|
|
|
|
|
packages = sh(script: "find '${destDir}' -name '*.deb' -type f", returnStdout: true)
|
2019-03-12 16:20:51 +01:00
|
|
|
.split('\n')
|
2019-02-20 15:30:20 +01:00
|
|
|
.collect { return it.trim() }
|
|
|
|
.findAll { it != '' }
|
2019-01-24 17:39:18 +01:00
|
|
|
}
|
2019-02-20 15:30:20 +01:00
|
|
|
|
|
|
|
return packages
|
2019-01-24 17:39:18 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
def buildDockerImage() {
|
|
|
|
dir ('.tamarin') {
|
|
|
|
def dockerfile = libraryResource 'com/cadoles/tamarin/Dockerfile'
|
|
|
|
writeFile file:'Dockerfile', text:dockerfile
|
|
|
|
|
|
|
|
def runTamarinScript = libraryResource 'com/cadoles/tamarin/run-tamarin.sh'
|
|
|
|
writeFile file:'run-tamarin.sh', text:runTamarinScript
|
|
|
|
|
2019-02-05 11:54:29 +01:00
|
|
|
def safeJobName = URLDecoder.decode(env.JOB_NAME).toLowerCase().replace('/', '-').replace(' ', '-')
|
2019-01-24 17:39:18 +01:00
|
|
|
def imageTag = "${safeJobName}-${env.BUILD_ID}"
|
|
|
|
return docker.build("tamarin:${imageTag}", ".")
|
|
|
|
}
|
|
|
|
}
|