Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
97aa9b61dd | |||
ec523ddfb4 | |||
78c8a9e74e | |||
4cb30fa836 | |||
3b6e1e0f72 |
@ -109,7 +109,6 @@ pipeline {
|
|||||||
|
|
||||||
// Pour chaque construction de paquets...
|
// Pour chaque construction de paquets...
|
||||||
result.each { r ->
|
result.each { r ->
|
||||||
|
|
||||||
// On essaye de trouver un template de VM compatible
|
// On essaye de trouver un template de VM compatible
|
||||||
// avec la distribution cible de la construction
|
// avec la distribution cible de la construction
|
||||||
def vmTemplate = findMatchingVMTemplate(r.distrib)
|
def vmTemplate = findMatchingVMTemplate(r.distrib)
|
||||||
@ -120,24 +119,19 @@ pipeline {
|
|||||||
|
|
||||||
// Pour chaque paquets construits...
|
// Pour chaque paquets construits...
|
||||||
r.packages.each { p ->
|
r.packages.each { p ->
|
||||||
def packageName = new File(p).getName()
|
def packageFullName = new File(p).getName()
|
||||||
stage("Test package '${packageName}' installation") {
|
def packageRepository = r.distrib.split('-')[1] + '-' + r.env
|
||||||
try {
|
def packageNameParts = packageFullName.split('_')
|
||||||
// On démarre une nouvelle VM et on lance l'installation du paquet publié
|
def packageName = packageNameParts[0]
|
||||||
testPackageInstallation(vmTemplate, r.distrib, r.env, packageName)
|
def packageVersion = packageNameParts[1]
|
||||||
} catch(e) {
|
|
||||||
currentBuild.result = 'UNSTABLE'
|
|
||||||
rocketSend (
|
|
||||||
avatar: 'https://jenkins.cadol.es/static/b5f67753/images/headshot.png',
|
|
||||||
message: """
|
|
||||||
[Installation du paquet `${packageName}` échouée sur `${vmTemplate}`](${env.RUN_DISPLAY_URL})
|
|
||||||
|
|
||||||
@${env.sender_login}
|
stage("Test package '${packageName}' installation") {
|
||||||
""".stripIndent(),
|
build job: 'Test de paquet Debian', wait: false, parameters: [
|
||||||
rawMessage: true
|
[$class: 'StringParameterValue', name: 'packageName', value: packageName],
|
||||||
)
|
[$class: 'StringParameterValue', name: 'packageVersion', value: packageVersion],
|
||||||
error("Installation du paquet `${packageName}` échouée.")
|
[$class: 'StringParameterValue', name: 'packageRepository', value: packageRepository],
|
||||||
}
|
[$class: 'StringParameterValue', name: 'vmTemplate', value: vmTemplate]
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -167,20 +161,3 @@ def findMatchingVMTemplate(String distrib) {
|
|||||||
]
|
]
|
||||||
return vmTemplatesMap.get(distrib, null)
|
return vmTemplatesMap.get(distrib, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cette fonction démarre une nouvelle VM, configure les dépôts tiers pour ajouter
|
|
||||||
// celui de Cadoles correspondant à la cible du paquet et tente d'installer celui ci.
|
|
||||||
def testPackageInstallation(String vmTemplate, String distrib, String env, String packageName) {
|
|
||||||
def version = distrib.split('-')[1]
|
|
||||||
def packageNameParts = packageName.split('_')
|
|
||||||
nebula.runInNewVM([
|
|
||||||
vmTemplate: vmTemplate,
|
|
||||||
script: """
|
|
||||||
set -xeo pipefail
|
|
||||||
wget -qO - https://vulcain.cadoles.com/cadoles.gpg | apt-key add -
|
|
||||||
echo 'deb https://vulcain.cadoles.com ${version}-${env} main' > /etc/apt/sources.list.d/${version}-${env}.list
|
|
||||||
apt-get update -y
|
|
||||||
apt-get install -y ${packageNameParts[0]}=${packageNameParts[1]}
|
|
||||||
"""
|
|
||||||
])
|
|
||||||
}
|
|
87
pipelines/debian-test-package.jenkinsfile
Normal file
87
pipelines/debian-test-package.jenkinsfile
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
@Library("cadoles") _
|
||||||
|
|
||||||
|
pipeline {
|
||||||
|
|
||||||
|
agent {
|
||||||
|
label 'common'
|
||||||
|
}
|
||||||
|
|
||||||
|
parameters {
|
||||||
|
string(
|
||||||
|
name: 'packageName',
|
||||||
|
description: 'Nom du paquet à installer'
|
||||||
|
)
|
||||||
|
string(
|
||||||
|
name: 'packageVersion',
|
||||||
|
defaultValue: '',
|
||||||
|
description: 'Version du paquet à installer'
|
||||||
|
)
|
||||||
|
string(
|
||||||
|
name: 'packageRepository',
|
||||||
|
description: 'Dépôt de paquets à utiliser sur Vulcain'
|
||||||
|
)
|
||||||
|
string(
|
||||||
|
name: 'vmTemplate',
|
||||||
|
description: 'Template OpenNebula de la VM à utiliser pour le test d\'installation'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
stages {
|
||||||
|
|
||||||
|
stage("Check parameters") {
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
if (!params.packageName?.trim()) {
|
||||||
|
error("Le nom du paquet n'est pas défini !")
|
||||||
|
}
|
||||||
|
if (!params.vmTemplate?.trim()) {
|
||||||
|
error("Le template de VM n'est pas défini !")
|
||||||
|
}
|
||||||
|
if (!params.packageRepository?.trim()) {
|
||||||
|
error("Le dépôt de paquets n'est pas défini !")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage("Test package installation") {
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
nebula.runScriptInNewVM([
|
||||||
|
vmTemplate: params.vmTemplate,
|
||||||
|
script: """
|
||||||
|
set -xeo pipefail
|
||||||
|
wget -qO - https://vulcain.cadoles.com/cadoles.gpg | apt-key add -
|
||||||
|
echo 'deb https://vulcain.cadoles.com ${params.packageRepository} main' > /etc/apt/sources.list.d/${params.packageRepository}.list
|
||||||
|
apt-get update -y
|
||||||
|
apt-get install -y ${params.packageName}${ params.packageVersion?.trim() ? '=' + params.packageVersion?.trim() : ''}
|
||||||
|
"""
|
||||||
|
])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
post {
|
||||||
|
failure {
|
||||||
|
wrap([$class: 'BuildUser']) {
|
||||||
|
rocketSend (
|
||||||
|
avatar: 'https://jenkins.cadol.es/static/b5f67753/images/headshot.png',
|
||||||
|
message: """
|
||||||
|
Le test d'installation du paquet `${params.packageName}` a échoué:
|
||||||
|
|
||||||
|
- Version `${params.packageVersion}`
|
||||||
|
- Dépôt `${params.packageRepository}`
|
||||||
|
- Template de la VM `${params.vmTemplate}`
|
||||||
|
|
||||||
|
[Voir le job](${env.RUN_DISPLAY_URL})
|
||||||
|
|
||||||
|
@${env.BUILD_USER_ID ? env.BUILD_USER_ID : 'here'}
|
||||||
|
""".stripIndent(),
|
||||||
|
rawMessage: true
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
15
vars/hook.groovy
Normal file
15
vars/hook.groovy
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
def call(String name) {
|
||||||
|
def rootDir = pwd()
|
||||||
|
def filepath = "${rootDir}/.jenkins/${name}.groovy"
|
||||||
|
def exists = fileExists(filepath)
|
||||||
|
if (!exists) {
|
||||||
|
println("No hook '${filepath}' script. Skipping.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
def hook = load(filepath)
|
||||||
|
if(hook.metaClass.respondsTo(hook, 'exec')) {
|
||||||
|
hook.exec()
|
||||||
|
} else {
|
||||||
|
error("Hook script '${filepath}' exists but does not expose an exec() function.")
|
||||||
|
}
|
||||||
|
}
|
@ -133,7 +133,15 @@ def initWithCredentials(String urlCredentialsId, String userCredentialsId, Closu
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def runInNewVM(Map args) {
|
def runScriptInNewVM(Map args) {
|
||||||
|
def script = args.get("script", "")
|
||||||
|
runInNewVM(args) { shell ->
|
||||||
|
shell(script)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def runInNewVM(Map args, Closure body) {
|
||||||
|
|
||||||
def urlCredentialsId = args.get('urlCredentialsId', 'opennebula-dev-url')
|
def urlCredentialsId = args.get('urlCredentialsId', 'opennebula-dev-url')
|
||||||
def userCredentialsId = args.get('userCredentialsId', 'kipp-credentials')
|
def userCredentialsId = args.get('userCredentialsId', 'kipp-credentials')
|
||||||
@ -141,7 +149,7 @@ def runInNewVM(Map args) {
|
|||||||
def vmTemplate = args.get('vmTemplate', '')
|
def vmTemplate = args.get('vmTemplate', '')
|
||||||
def terminateOnExit = args.get('terminateOnExit', true)
|
def terminateOnExit = args.get('terminateOnExit', true)
|
||||||
def shell = args.get("shell", "/bin/sh")
|
def shell = args.get("shell", "/bin/sh")
|
||||||
def script = args.get('script', '')
|
def connectionTimeout = args.get('connectionTimeout', 10)
|
||||||
|
|
||||||
// On récupère les identifiants de connexion SSH pour la VM
|
// On récupère les identifiants de connexion SSH pour la VM
|
||||||
withCredentials([
|
withCredentials([
|
||||||
@ -154,6 +162,7 @@ def runInNewVM(Map args) {
|
|||||||
|
|
||||||
// On attend que la connexion SSH soit disponible
|
// On attend que la connexion SSH soit disponible
|
||||||
println "En attente de l'accès SSH sur la machine ${host}..."
|
println "En attente de l'accès SSH sur la machine ${host}..."
|
||||||
|
timeout(connectionTimeout) {
|
||||||
while(true) {
|
while(true) {
|
||||||
def status = sh script: "nc -zv ${host} 22", returnStatus: true
|
def status = sh script: "nc -zv ${host} 22", returnStatus: true
|
||||||
if (status == 0) {
|
if (status == 0) {
|
||||||
@ -161,7 +170,9 @@ def runInNewVM(Map args) {
|
|||||||
}
|
}
|
||||||
sleep(5)
|
sleep(5)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def remoteShell = { script ->
|
||||||
// On créait un script temporaire à exécuter sur la machine distante
|
// On créait un script temporaire à exécuter sur la machine distante
|
||||||
def now = System.currentTimeMillis()
|
def now = System.currentTimeMillis()
|
||||||
def tempScriptFile = "script_${env.BUILD_ID}_${now}.sh"
|
def tempScriptFile = "script_${env.BUILD_ID}_${now}.sh"
|
||||||
@ -169,13 +180,16 @@ def runInNewVM(Map args) {
|
|||||||
#!${shell}
|
#!${shell}
|
||||||
${script.stripIndent()}
|
${script.stripIndent()}
|
||||||
""")
|
""")
|
||||||
|
|
||||||
// On transfère le script sur la machine distante et on l'exécute
|
// On transfère le script sur la machine distante et on l'exécute
|
||||||
sh """
|
sh """
|
||||||
scp ${sshArgs} '${tempScriptFile}' 'root@${host}:/tmp/${tempScriptFile}'
|
scp ${sshArgs} '${tempScriptFile}' 'root@${host}:/tmp/${tempScriptFile}'
|
||||||
ssh ${sshArgs} root@${host} 'chmod +x /tmp/${tempScriptFile}; /tmp/${tempScriptFile}'
|
ssh ${sshArgs} root@${host} 'chmod +x /tmp/${tempScriptFile}; /tmp/${tempScriptFile}'
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
body(remoteShell)
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -80,7 +80,7 @@ def buildPackage(
|
|||||||
}
|
}
|
||||||
|
|
||||||
packages = sh(script: "find '${destDir}' -name '*.deb' -type f", returnStdout: true)
|
packages = sh(script: "find '${destDir}' -name '*.deb' -type f", returnStdout: true)
|
||||||
.split(' ')
|
.split('\n')
|
||||||
.collect { return it.trim() }
|
.collect { return it.trim() }
|
||||||
.findAll { it != '' }
|
.findAll { it != '' }
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user