Compare commits
1 Commits
hooks
...
redesign-t
Author | SHA1 | Date | |
---|---|---|---|
c73ddac0fd |
@ -1,4 +1,4 @@
|
|||||||
@Library("cadoles") _
|
@Library("cadoles@redesign-tamarin") _
|
||||||
|
|
||||||
pipeline {
|
pipeline {
|
||||||
|
|
||||||
@ -109,6 +109,7 @@ 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)
|
||||||
@ -119,19 +120,24 @@ pipeline {
|
|||||||
|
|
||||||
// Pour chaque paquets construits...
|
// Pour chaque paquets construits...
|
||||||
r.packages.each { p ->
|
r.packages.each { p ->
|
||||||
def packageFullName = new File(p).getName()
|
def packageName = new File(p).getName()
|
||||||
def packageRepository = r.distrib.split('-')[1] + '-' + r.env
|
|
||||||
def packageNameParts = packageFullName.split('_')
|
|
||||||
def packageName = packageNameParts[0]
|
|
||||||
def packageVersion = packageNameParts[1]
|
|
||||||
|
|
||||||
stage("Test package '${packageName}' installation") {
|
stage("Test package '${packageName}' installation") {
|
||||||
build job: 'Test de paquet Debian', wait: false, parameters: [
|
try {
|
||||||
[$class: 'StringParameterValue', name: 'packageName', value: packageName],
|
// On démarre une nouvelle VM et on lance l'installation du paquet publié
|
||||||
[$class: 'StringParameterValue', name: 'packageVersion', value: packageVersion],
|
testPackageInstallation(vmTemplate, r.distrib, r.env, packageName)
|
||||||
[$class: 'StringParameterValue', name: 'packageRepository', value: packageRepository],
|
} catch(e) {
|
||||||
[$class: 'StringParameterValue', name: 'vmTemplate', value: vmTemplate]
|
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}
|
||||||
|
""".stripIndent(),
|
||||||
|
rawMessage: true
|
||||||
|
)
|
||||||
|
error("Installation du paquet `${packageName}` échouée.")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -161,3 +167,20 @@ 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]}
|
||||||
|
"""
|
||||||
|
])
|
||||||
|
}
|
@ -1,87 +0,0 @@
|
|||||||
@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
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
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.")
|
|
||||||
}
|
|
||||||
}
|
|
@ -4,7 +4,6 @@ import groovy.util.XmlSlurper
|
|||||||
import groovy.util.slurpersupport.GPathResult
|
import groovy.util.slurpersupport.GPathResult
|
||||||
import groovy.util.slurpersupport.NodeChild
|
import groovy.util.slurpersupport.NodeChild
|
||||||
import groovy.xml.XmlUtil
|
import groovy.xml.XmlUtil
|
||||||
import org.jenkinsci.plugins.workflow.steps.FlowInterruptedException
|
|
||||||
|
|
||||||
class Client {
|
class Client {
|
||||||
|
|
||||||
@ -133,15 +132,7 @@ def initWithCredentials(String urlCredentialsId, String userCredentialsId, Closu
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def runScriptInNewVM(Map args) {
|
def runInNewVM(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')
|
||||||
@ -149,7 +140,7 @@ def runInNewVM(Map args, Closure body) {
|
|||||||
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 connectionTimeout = args.get('connectionTimeout', 10)
|
def script = args.get('script', '')
|
||||||
|
|
||||||
// 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([
|
||||||
@ -158,21 +149,19 @@ def runInNewVM(Map args, Closure body) {
|
|||||||
initWithCredentials(urlCredentialsId, userCredentialsId) { client ->
|
initWithCredentials(urlCredentialsId, userCredentialsId) { client ->
|
||||||
client.withNewVM(vmTemplate, terminateOnExit) { host ->
|
client.withNewVM(vmTemplate, terminateOnExit) { host ->
|
||||||
|
|
||||||
def sshArgs = "-i '${VM_SSH_KEY}' -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
|
def sshArgs = "-i ${VM_SSH_KEY} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
|
||||||
|
|
||||||
// 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..."
|
||||||
timeout(connectionTimeout) {
|
waitUntil {
|
||||||
while(true) {
|
try {
|
||||||
def status = sh script: "nc -zv ${host} 22", returnStatus: true
|
sh "ssh -q ${sshArgs} -o ConnectTimeout=1 root@${host} exit"
|
||||||
if (status == 0) {
|
return true
|
||||||
break;
|
} catch (e) {
|
||||||
}
|
return false
|
||||||
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"
|
||||||
@ -180,16 +169,13 @@ def runInNewVM(Map args, Closure body) {
|
|||||||
#!${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('\n')
|
.split(' ')
|
||||||
.collect { return it.trim() }
|
.collect { return it.trim() }
|
||||||
.findAll { it != '' }
|
.findAll { it != '' }
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ def publish(
|
|||||||
echo "Publishing packages to '${packagesEnv}/${packagesBranch}'"
|
echo "Publishing packages to '${packagesEnv}/${packagesBranch}'"
|
||||||
sh "ssh -i '${VULCAIN_SSH_KEY}' -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null '${VULCAIN_SSH_USER}@${vulcainHost}' mkdir -p '/home/${VULCAIN_SSH_USER}/packages/${packagesEnv}/${packagesBranch}'"
|
sh "ssh -i '${VULCAIN_SSH_KEY}' -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null '${VULCAIN_SSH_USER}@${vulcainHost}' mkdir -p '/home/${VULCAIN_SSH_USER}/packages/${packagesEnv}/${packagesBranch}'"
|
||||||
packages.each {
|
packages.each {
|
||||||
sh "scp -C -i '${VULCAIN_SSH_KEY}' -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null '${it}' '${VULCAIN_SSH_USER}@${vulcainHost}:/home/${VULCAIN_SSH_USER}/packages/${packagesEnv}/${packagesBranch}/'"
|
sh "scp -i '${VULCAIN_SSH_KEY}' -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null '${it}' '${VULCAIN_SSH_USER}@${vulcainHost}:/home/${VULCAIN_SSH_USER}/packages/${packagesEnv}/${packagesBranch}/'"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user