From 348d9aaadeb22db97793b6c48834be92d23eadc8 Mon Sep 17 00:00:00 2001 From: Raphael Defosseux <raphael.defosseux@eurecom.fr> Date: Fri, 22 Jun 2018 16:01:08 +0200 Subject: [PATCH] CI: enhancements -- VM are kept alive to prepare for running tests -- Added destroy script to kill all VM after run -- VM names are now based on jobname and buildid Signed-off-by: Raphael Defosseux <raphael.defosseux@eurecom.fr> --- ci-scripts/Jenkinsfile-gitlab | 17 +++++-- ci-scripts/buildOnVM.sh | 29 ++++++++++- ci-scripts/destroyAllRunningVM.sh | 81 +++++++++++++++++++++++++++++++ 3 files changed, 121 insertions(+), 6 deletions(-) create mode 100644 ci-scripts/destroyAllRunningVM.sh diff --git a/ci-scripts/Jenkinsfile-gitlab b/ci-scripts/Jenkinsfile-gitlab index ad97588d9b3..f36bf9023f8 100644 --- a/ci-scripts/Jenkinsfile-gitlab +++ b/ci-scripts/Jenkinsfile-gitlab @@ -52,28 +52,28 @@ pipeline { stage ("Analysis with cppcheck") { steps { gitlabCommitStatus(name: "Analysis with cppcheck") { - sh "./ci-scripts/buildOnVM.sh --workspace $WORKSPACE --variant cppcheck" + sh "./ci-scripts/buildOnVM.sh --workspace $WORKSPACE --variant cppcheck --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep" } } } stage ("Build eNb-USRP") { steps { gitlabCommitStatus(name: "Build eNb-USRP") { - sh "./ci-scripts/buildOnVM.sh --workspace $WORKSPACE --variant enb-usrp" + sh "./ci-scripts/buildOnVM.sh --workspace $WORKSPACE --variant enb-usrp --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep" } } } stage ("Build basic simulator") { steps { gitlabCommitStatus(name: "Build basic-sim") { - sh "./ci-scripts/buildOnVM.sh --workspace $WORKSPACE --variant basic-sim" + sh "./ci-scripts/buildOnVM.sh --workspace $WORKSPACE --variant basic-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep" } } } stage ("Build physical simulators") { steps { gitlabCommitStatus(name: "Build phy-sim") { - sh "./ci-scripts/buildOnVM.sh --workspace $WORKSPACE --variant phy-sim" + sh "./ci-scripts/buildOnVM.sh --workspace $WORKSPACE --variant phy-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep" } } } @@ -99,11 +99,18 @@ pipeline { } } } + + stage ("Destroy all Virtual Machines") { + steps { + sh "./ci-scripts/destroyAllRunningVM.sh --job-name ${JOB_NAME} --build-id ${BUILD_ID}" + } + } } post { always { script { - echo "End of script" + // Stage destroy may not be run if error in previous stage + sh "./ci-scripts/destroyAllRunningVM.sh --job-name ${JOB_NAME} --build-id ${BUILD_ID}" } } success { diff --git a/ci-scripts/buildOnVM.sh b/ci-scripts/buildOnVM.sh index c5389c2b506..24f86121f6a 100755 --- a/ci-scripts/buildOnVM.sh +++ b/ci-scripts/buildOnVM.sh @@ -15,6 +15,12 @@ function usage { echo "" echo "Options:" echo "--------" + echo " --job-name #### OR -jn ####" + echo " Specify the name of the Jenkins job." + echo "" + echo " --build-id #### OR -id ####" + echo " Specify the build ID of the Jenkins job." + echo "" echo " --workspace #### OR -ws ####" echo " Specify the workspace." echo "" @@ -43,7 +49,7 @@ function variant_usage { echo "" } -if [ $# -lt 1 ] || [ $# -gt 5 ] +if [ $# -lt 1 ] || [ $# -gt 9 ] then echo "Syntax Error: not the correct number of arguments" echo "" @@ -51,6 +57,9 @@ then exit 1 fi +VM_TEMPLATE=ci- +JOB_NAME=XX +BUILD_ID=XX VM_NAME=ci-enb-usrp ARCHIVES_LOC=enb_usrp LOG_PATTERN=.Rel14.txt @@ -68,6 +77,16 @@ case $key in usage exit 0 ;; + -jn|--job-name) + JOB_NAME="$2" + shift + shift + ;; + -id|--build-id) + BUILD_ID="$2" + shift + shift + ;; -ws|--workspace) JENKINS_WKSP="$2" shift @@ -170,6 +189,14 @@ then exit 1 fi +if [ "$JOB_NAME" == "XX" ] || [ "$BUILD_ID" == "XX" ] +then + VM_TEMPLATE=ci- +else + VM_TEMPLATE=${JOB_NAME}-b${BUILD_ID}- +fi + +VM_NAME=`echo $VM_NAME | sed -e "s#ci-#$VM_TEMPLATE#"` VM_CMDS=${VM_NAME}_cmds.txt ARCHIVES_LOC=${JENKINS_WKSP}/archives/${ARCHIVES_LOC} diff --git a/ci-scripts/destroyAllRunningVM.sh b/ci-scripts/destroyAllRunningVM.sh new file mode 100644 index 00000000000..c9eb43b4ef2 --- /dev/null +++ b/ci-scripts/destroyAllRunningVM.sh @@ -0,0 +1,81 @@ +#!/bin/bash + +function usage { + echo "OAI VM Destroy script" + echo " Original Author: Raphael Defosseux" + echo "" + echo "Usage:" + echo "------" + echo " destroyAllRunningVM.sh [OPTIONS]" + echo "" + echo "Options:" + echo "--------" + echo " --job-name #### OR -jn ####" + echo " Specify the name of the Jenkins job." + echo "" + echo " --build-id #### OR -id ####" + echo " Specify the build ID of the Jenkins job." + echo "" + echo " --help OR -h" + echo " Print this help message." + echo "" +} + +if [ $# -gt 4 ] +then + echo "Syntax Error: not the correct number of arguments" + echo "" + usage + exit 1 +fi + +VM_TEMPLATE=ci- +JOB_NAME=XX +BUILD_ID=XX + +while [[ $# -gt 0 ]] +do +key="$1" +case $key in + -h|--help) + shift + usage + exit 0 + ;; + -jn|--job-name) + JOB_NAME="$2" + shift + shift + ;; + -id|--build-id) + BUILD_ID="$2" + shift + shift + ;; + *) + echo "Syntax Error: unknown option: $key" + echo "" + usage + exit 1 +esac +done + +if [ "$JOB_NAME" == "XX" ] || [ "$BUILD_ID" == "XX" ] +then + VM_TEMPLATE=ci- +else + VM_TEMPLATE=${JOB_NAME}-b${BUILD_ID}- +fi + +LIST_CI_VM=`uvt-kvm list | grep $VM_TEMPLATE` + +for CI_VM in $LIST_CI_VM +do + VM_IP_ADDR=`uvt-kvm ip $CI_VM` + echo "VM to destroy: $CI_VM -- IP $VM_IP_ADDR" + uvt-kvm destroy $CI_VM + ssh-keygen -R $VM_IP_ADDR +done + +exit 0 + -- GitLab