Refactorisation de l'API pour les opérations sur OpenNebula
This commit is contained in:
parent
3b6e1e0f72
commit
4cb30fa836
|
@ -47,7 +47,7 @@ pipeline {
|
||||||
stage("Test package installation") {
|
stage("Test package installation") {
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
nebula.runInNewVM([
|
nebula.runScriptInNewVM([
|
||||||
vmTemplate: params.vmTemplate,
|
vmTemplate: params.vmTemplate,
|
||||||
script: """
|
script: """
|
||||||
set -xeo pipefail
|
set -xeo pipefail
|
||||||
|
|
|
@ -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,6 @@ 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', '')
|
|
||||||
|
|
||||||
// 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([
|
||||||
|
@ -162,20 +169,24 @@ def runInNewVM(Map args) {
|
||||||
sleep(5)
|
sleep(5)
|
||||||
}
|
}
|
||||||
|
|
||||||
// On créait un script temporaire à exécuter sur la machine distante
|
def remoteShell = { script ->
|
||||||
def now = System.currentTimeMillis()
|
// On créait un script temporaire à exécuter sur la machine distante
|
||||||
def tempScriptFile = "script_${env.BUILD_ID}_${now}.sh"
|
def now = System.currentTimeMillis()
|
||||||
writeFile(file: tempScriptFile, text: """
|
def tempScriptFile = "script_${env.BUILD_ID}_${now}.sh"
|
||||||
#!${shell}
|
writeFile(file: tempScriptFile, text: """
|
||||||
${script.stripIndent()}
|
#!${shell}
|
||||||
""")
|
${script.stripIndent()}
|
||||||
|
""")
|
||||||
|
// On transfère le script sur la machine distante et on l'exécute
|
||||||
|
sh """
|
||||||
|
scp ${sshArgs} '${tempScriptFile}' 'root@${host}:/tmp/${tempScriptFile}'
|
||||||
|
ssh ${sshArgs} root@${host} 'chmod +x /tmp/${tempScriptFile}; /tmp/${tempScriptFile}'
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
|
||||||
// On transfère le script sur la machine distante et on l'exécute
|
body(remoteShell)
|
||||||
sh """
|
|
||||||
scp ${sshArgs} '${tempScriptFile}' 'root@${host}:/tmp/${tempScriptFile}'
|
|
||||||
ssh ${sshArgs} root@${host} 'chmod +x /tmp/${tempScriptFile}; /tmp/${tempScriptFile}'
|
|
||||||
"""
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue