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,6 +169,7 @@ 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 +177,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)
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue