2019-02-20 15:30:20 +01:00
|
|
|
@Library("cadoles") _
|
|
|
|
|
|
|
|
pipeline {
|
|
|
|
|
|
|
|
agent {
|
|
|
|
label 'common'
|
|
|
|
}
|
|
|
|
|
|
|
|
environment {
|
|
|
|
projectDir = "${env.project_name}_${env.BUILD_ID}"
|
|
|
|
}
|
|
|
|
|
|
|
|
stages {
|
|
|
|
|
|
|
|
stage("Clone repository") {
|
|
|
|
steps {
|
|
|
|
checkout scm:
|
|
|
|
[
|
|
|
|
$class: 'GitSCM',
|
2020-03-04 16:55:46 +01:00
|
|
|
userRemoteConfigs: [[url: env.repository_url, credentialsId: 'jenkins-forge-ssh']],
|
2019-02-20 15:30:20 +01:00
|
|
|
branches: [[name: env.ref]],
|
|
|
|
extensions: [
|
|
|
|
[$class: 'RelativeTargetDirectory', relativeTargetDir: env.projectDir ],
|
|
|
|
[$class: 'CloneOption', noTags: false, shallow: false, depth: 0, reference: ''],
|
|
|
|
[$class: 'WipeWorkspace' ]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
changelog: false,
|
|
|
|
poll: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stage("Ensure packaging branch") {
|
|
|
|
steps {
|
|
|
|
script {
|
|
|
|
dir(env.projectDir) {
|
|
|
|
sh 'git checkout "${packageBranch}"'
|
|
|
|
def commitOrRef = env.commit ? env.commit : env.ref
|
|
|
|
def branchesWithCommitOrRef = sh(script: "git branch --contains '${commitOrRef}'", returnStdout: true).split(' ')
|
|
|
|
if (branchesWithCommitOrRef.findAll{env.packageBranch.contains(it)}.any{true}) {
|
|
|
|
currentBuild.result = 'ABORTED'
|
|
|
|
error("La référence `${env.ref}` ne fait pas partie de la branche `${env.packageBranch}` !")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stage("Checkout ref") {
|
|
|
|
steps {
|
|
|
|
dir(env.projectDir) {
|
|
|
|
sh """
|
|
|
|
git checkout ${env.ref}
|
|
|
|
"""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stage("Build package") {
|
|
|
|
steps {
|
|
|
|
script {
|
|
|
|
dir(env.projectDir) {
|
|
|
|
|
|
|
|
// On construit les paquets à partir des informations
|
|
|
|
// de contexte provenant de CPKG et du webhook
|
|
|
|
def result = tamarin.buildPackageWithCPKG(
|
|
|
|
env.packageProfile ? env.packageProfile : "debian",
|
|
|
|
env.packageArch ? env.packageArch : "",
|
|
|
|
env.packageBranch ? env.packageBranch : "",
|
|
|
|
env.baseImage ? env.baseImage : ""
|
|
|
|
)
|
|
|
|
|
|
|
|
// On publie chacun des paquets construits
|
|
|
|
result.each { r ->
|
|
|
|
vulcain.publish(
|
|
|
|
r.packages,
|
|
|
|
r.env,
|
|
|
|
env.packageBranch
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// On liste l'ensemble des paquets construits
|
|
|
|
def publishedPackages = result.collect { r ->
|
|
|
|
return r.packages.collect { p ->
|
|
|
|
def file = new File(p)
|
|
|
|
return "- Paquet `${file.getName()}`, Dépôt `${r.env}`, Distribution `${r.distrib}`"
|
|
|
|
}
|
|
|
|
}.transpose().collectMany { it }
|
|
|
|
|
|
|
|
// On notifie le canal Rocket.Chat de la publication des paquets
|
|
|
|
rocketSend (
|
|
|
|
avatar: 'https://jenkins.cadol.es/static/b5f67753/images/headshot.png',
|
|
|
|
message: """
|
|
|
|
Les paquets suivants ont été publiés pour le projet ${env.project_name}:
|
|
|
|
|
|
|
|
${publishedPackages.join('\n')}
|
|
|
|
|
|
|
|
[Visualiser le job](${env.RUN_DISPLAY_URL})
|
|
|
|
|
|
|
|
@${env.sender_login}
|
|
|
|
""".stripIndent(),
|
2020-03-04 16:55:46 +01:00
|
|
|
rawMessage: true,
|
|
|
|
attachments: lolops.getRandomDeliveryAttachment()
|
2019-02-20 15:30:20 +01:00
|
|
|
)
|
|
|
|
|
2020-03-04 16:55:46 +01:00
|
|
|
if (env.testPackageInstall != 'yes') {
|
2019-02-20 15:30:20 +01:00
|
|
|
println "Test d'intallation des paquets désactivé."
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pour chaque construction de paquets...
|
|
|
|
result.each { r ->
|
|
|
|
// On essaye de trouver un template de VM compatible
|
|
|
|
// avec la distribution cible de la construction
|
|
|
|
def vmTemplate = findMatchingVMTemplate(r.distrib)
|
|
|
|
if (vmTemplate == null) {
|
|
|
|
println "Aucun template de VM n'a été trouvé correspondant à la distribution `${r.distrib}`."
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pour chaque paquets construits...
|
|
|
|
r.packages.each { p ->
|
2019-03-01 15:16:42 +01:00
|
|
|
def packageFullName = new File(p).getName()
|
|
|
|
def packageRepository = r.distrib.split('-')[1] + '-' + r.env
|
|
|
|
def packageNameParts = packageFullName.split('_')
|
|
|
|
def packageName = packageNameParts[0]
|
|
|
|
def packageVersion = packageNameParts[1]
|
|
|
|
|
2019-02-20 15:30:20 +01:00
|
|
|
stage("Test package '${packageName}' installation") {
|
2019-03-01 15:16:42 +01:00
|
|
|
build job: 'Test de paquet Debian', wait: false, parameters: [
|
|
|
|
[$class: 'StringParameterValue', name: 'packageName', value: packageName],
|
|
|
|
[$class: 'StringParameterValue', name: 'packageVersion', value: packageVersion],
|
|
|
|
[$class: 'StringParameterValue', name: 'packageRepository', value: packageRepository],
|
|
|
|
[$class: 'StringParameterValue', name: 'vmTemplate', value: vmTemplate]
|
|
|
|
]
|
2019-02-20 15:30:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
post {
|
|
|
|
always {
|
|
|
|
sh "rm -rf '${env.projectDir}'"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cette fonction fait un simple "mapping"
|
|
|
|
// entre les distributions cibles des paquets et
|
|
|
|
// les templates de VM disponibles sur l'OpenNebula
|
|
|
|
def findMatchingVMTemplate(String distrib) {
|
|
|
|
def vmTemplatesMap = [
|
|
|
|
'eole-2.7.0': 'eolebase-2.7.0-cadoles',
|
|
|
|
'eole-2.6.2': 'eolebase-2.6.2-cadoles'
|
|
|
|
]
|
|
|
|
return vmTemplatesMap.get(distrib, null)
|
|
|
|
}
|