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") {
|
||||
steps {
|
||||
script {
|
||||
nebula.runInNewVM([
|
||||
nebula.runScriptInNewVM([
|
||||
vmTemplate: params.vmTemplate,
|
||||
script: """
|
||||
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 userCredentialsId = args.get('userCredentialsId', 'kipp-credentials')
|
||||
|
@ -141,7 +149,6 @@ def runInNewVM(Map args) {
|
|||
def vmTemplate = args.get('vmTemplate', '')
|
||||
def terminateOnExit = args.get('terminateOnExit', true)
|
||||
def shell = args.get("shell", "/bin/sh")
|
||||
def script = args.get('script', '')
|
||||
|
||||
// On récupère les identifiants de connexion SSH pour la VM
|
||||
withCredentials([
|
||||
|
@ -162,6 +169,7 @@ def runInNewVM(Map args) {
|
|||
sleep(5)
|
||||
}
|
||||
|
||||
def remoteShell = { script ->
|
||||
// On créait un script temporaire à exécuter sur la machine distante
|
||||
def now = System.currentTimeMillis()
|
||||
def tempScriptFile = "script_${env.BUILD_ID}_${now}.sh"
|
||||
|
@ -169,13 +177,16 @@ def runInNewVM(Map args) {
|
|||
#!${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}'
|
||||
"""
|
||||
}
|
||||
|
||||
body(remoteShell)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue