From 08b2d4f98339e404c72263c3bf662f06c6f97f3c Mon Sep 17 00:00:00 2001 From: Raphael Defosseux <raphael.defosseux@eurecom.fr> Date: Wed, 4 Jul 2018 15:02:33 +0200 Subject: [PATCH] CI: improve stability -- Added apt-get update before any apt-get command in shell script on VM Necessary if the cloud image is a bit out of sync -- Added VM memory parameter when creating VM Necessary for cppcheck build -- Aligned some scripts with develop branch Signed-off-by: Raphael Defosseux <raphael.defosseux@eurecom.fr> --- ci-scripts/Jenkinsfile-gitlab | 8 ++ ci-scripts/buildOnVM.sh | 8 +- ci-scripts/createVM.sh | 5 +- ci-scripts/doGitLabMerge.sh | 10 ++- tmp/ci-scripts/Jenkinsfile-gitlab | 143 ------------------------------ 5 files changed, 25 insertions(+), 149 deletions(-) delete mode 100644 tmp/ci-scripts/Jenkinsfile-gitlab diff --git a/ci-scripts/Jenkinsfile-gitlab b/ci-scripts/Jenkinsfile-gitlab index e638836bb0..233e5d1018 100644 --- a/ci-scripts/Jenkinsfile-gitlab +++ b/ci-scripts/Jenkinsfile-gitlab @@ -45,6 +45,14 @@ pipeline { } } } + post { + failure { + script { + def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): Merge Conflicts -- Cannot perform CI" + addGitLabMRComment comment: message + } + } + } } stage ("Start VM -- cppcheck") { diff --git a/ci-scripts/buildOnVM.sh b/ci-scripts/buildOnVM.sh index 8228b7241b..fb1e995f6b 100755 --- a/ci-scripts/buildOnVM.sh +++ b/ci-scripts/buildOnVM.sh @@ -69,6 +69,7 @@ VM_TEMPLATE=ci- JOB_NAME=XX BUILD_ID=XX VM_NAME=ci-enb-usrp +VM_MEMORY=2048 ARCHIVES_LOC=enb_usrp LOG_PATTERN=.Rel14.txt NB_PATTERN_FILES=4 @@ -130,6 +131,7 @@ case $key in ;; -v4) VM_NAME=ci-cppcheck + VM_MEMORY=8192 ARCHIVES_LOC=cppcheck LOG_PATTERN=cppcheck.xml NB_PATTERN_FILES=1 @@ -194,6 +196,7 @@ case $key in ;; cppcheck) VM_NAME=ci-cppcheck + VM_MEMORY=8192 ARCHIVES_LOC=cppcheck LOG_PATTERN=cppcheck.xml NB_PATTERN_FILES=1 @@ -281,7 +284,7 @@ then echo "############################################################" echo "Creating VM ($VM_NAME) on Ubuntu Cloud Image base" echo "############################################################" - uvt-kvm create $VM_NAME release=xenial --memory 2048 --cpu 4 --unsafe-caching --template ci-scripts/template-host.xml + uvt-kvm create $VM_NAME release=xenial --memory $VM_MEMORY --cpu 4 --unsafe-caching --template ci-scripts/template-host.xml fi echo "Waiting for VM to be started" @@ -307,7 +310,8 @@ then echo "sudo apt-get --yes install zip cppcheck >> zip-install.txt 2>&1" >> $VM_CMDS else echo "echo \"sudo apt-get --yes --quiet install zip subversion libboost-dev \"" >> $VM_CMDS - echo "sudo apt-get --yes install zip subversion libboost-dev > zip-install.txt 2>&1" >> $VM_CMDS + echo "sudo apt-get update > zip-install.txt 2>&1" >> $VM_CMDS + echo "sudo apt-get --yes install zip subversion libboost-dev >> zip-install.txt 2>&1" >> $VM_CMDS fi echo "mkdir tmp" >> $VM_CMDS echo "cd tmp" >> $VM_CMDS diff --git a/ci-scripts/createVM.sh b/ci-scripts/createVM.sh index 7cb5647308..d6b3a3981a 100755 --- a/ci-scripts/createVM.sh +++ b/ci-scripts/createVM.sh @@ -60,6 +60,7 @@ then fi VM_TEMPLATE=ci- +VM_MEMORY=2048 JOB_NAME=XX BUILD_ID=XX VM_NAME=ci-enb-usrp @@ -98,6 +99,7 @@ case $key in ;; -v4) VM_NAME=ci-cppcheck + VM_MEMORY=8192 shift ;; -v5) @@ -130,6 +132,7 @@ case $key in ;; cppcheck) VM_NAME=ci-cppcheck + VM_MEMORY=8192 ;; gnb-usrp) VM_NAME=ci-gnb-usrp @@ -176,7 +179,7 @@ echo "VM_NAME = $VM_NAME" echo "############################################################" echo "Creating VM ($VM_NAME) on Ubuntu Cloud Image base" echo "############################################################" -uvt-kvm create $VM_NAME release=xenial --memory 2048 --cpu 4 --unsafe-caching --template ci-scripts/template-host.xml +uvt-kvm create $VM_NAME release=xenial --memory $VM_MEMORY --cpu 4 --unsafe-caching --template ci-scripts/template-host.xml echo "Waiting for VM to be started" uvt-kvm wait $VM_NAME --insecure diff --git a/ci-scripts/doGitLabMerge.sh b/ci-scripts/doGitLabMerge.sh index cc6f38c810..dfe2f02b55 100755 --- a/ci-scripts/doGitLabMerge.sh +++ b/ci-scripts/doGitLabMerge.sh @@ -104,6 +104,10 @@ git checkout -f $SOURCE_COMMIT_ID git merge --ff $TARGET_COMMIT_ID -m "Temporary merge for CI" -exit 0 - - +STATUS=`git status | egrep -c "You have unmerged paths.|fix conflicts"` +if [ $STATUS -ne 0 ] +then + echo "There are merge conflicts.. Cannot perform further build tasks" + STATUS=-1 +fi +exit $STATUS diff --git a/tmp/ci-scripts/Jenkinsfile-gitlab b/tmp/ci-scripts/Jenkinsfile-gitlab deleted file mode 100644 index 64572e7cb3..0000000000 --- a/tmp/ci-scripts/Jenkinsfile-gitlab +++ /dev/null @@ -1,143 +0,0 @@ -// Comments - -pipeline { - agent { - label 'bellatrix' - } - options { - disableConcurrentBuilds() - timestamps() - gitLabConnection('OAI GitLab') - gitlabBuilds(builds: ["Build eNb-USRP", "Build basic-sim", "Build phy-sim", "Analysis with cppcheck"]) - } - - stages { - stage ("Verify Guidelines") { - steps { - echo "Git URL is ${GIT_URL}" - echo "GitLab Act is ${env.gitlabActionType}" - script { - if ("MERGE".equals(env.gitlabActionType)) { - // GitLab-Jenkins plugin integration is lacking to perform the merge by itself - // Doing it manually --> it may have merge conflicts - sh "./ci-scripts/doGitLabMerge.sh --src-branch ${env.gitlabSourceBranch} --src-commit ${env.gitlabMergeRequestLastCommit} --target-branch ${env.gitlabTargetBranch} --target-commit ${GIT_COMMIT}" - sh "zip -r -qq localZip.zip ." - - // Running astyle options on the list of modified files by the merge request - // For the moment, there is no fail criteria. Just a notification of number of files that do not follow - sh "./ci-scripts/checkCodingFormattingRules.sh --src-branch ${env.gitlabSourceBranch} --target-branch ${env.gitlabTargetBranch}" - def res=readFile('./oai_rules_result.txt').trim(); - if ("0".equals(res)) { - def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): All Changed files in Merge Request follow OAI Formatting Rules" - addGitLabMRComment comment: message - } else { - def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): Some Changed files in Merge Request DO NOT follow OAI Formatting Rules" - addGitLabMRComment comment: message - } - } else { - echo "Git Branch is ${GIT_BRANCH}" - echo "Git Commit is ${GIT_COMMIT}" - - sh "zip -r -qq localZip.zip ." - // Running astyle options on all C/H files in the repository - // For the moment, there is no fail criteria. Just a notification of number of files that do not follow - sh "./ci-scripts/checkCodingFormattingRules.sh" - } - } - } - } - - stage ("Variant Builds") { - parallel { - stage ("Analysis with cppcheck") { - steps { - gitlabCommitStatus(name: "Analysis with cppcheck") { - sh "./ci-scripts/buildOnVM.sh --workspace $WORKSPACE --variant cppcheck --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive" - } - } - } - stage ("Build eNb-USRP") { - steps { - gitlabCommitStatus(name: "Build eNb-USRP") { - sh "./ci-scripts/buildOnVM.sh --workspace $WORKSPACE --variant enb-usrp --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive" - } - } - } - stage ("Build basic simulator") { - steps { - gitlabCommitStatus(name: "Build basic-sim") { - sh "./ci-scripts/buildOnVM.sh --workspace $WORKSPACE --variant basic-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive" - } - } - } - stage ("Build physical simulators") { - steps { - gitlabCommitStatus(name: "Build phy-sim") { - sh "./ci-scripts/buildOnVM.sh --workspace $WORKSPACE --variant phy-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive" - } - } - } - } - post { - always { - script { - dir ('archives') { - sh "zip -r vm_build_logs.zip basic_sim enb_usrp phy_sim cppcheck" - } - if(fileExists('archives/vm_build_logs.zip')) { - archiveArtifacts artifacts: 'archives/vm_build_logs.zip' - } - if ("MERGE".equals(env.gitlabActionType)) { - sh "./ci-scripts/reportBuildLocally.sh --git-url ${GIT_URL} --job-name ${JOB_NAME} --build-id ${BUILD_ID} --trigger merge-request --src-branch ${env.gitlabSourceBranch} --src-commit ${env.gitlabMergeRequestLastCommit} --target-branch ${env.gitlabTargetBranch} --target-commit ${GIT_COMMIT}" - } else { - sh "./ci-scripts/reportBuildLocally.sh --git-url ${GIT_URL} --job-name ${JOB_NAME} --build-id ${BUILD_ID} --trigger push --branch ${GIT_BRANCH} --commit ${GIT_COMMIT}" - } - if(fileExists('build_results.html')) { - archiveArtifacts artifacts: 'build_results.html' - } - } - } - } - } - - stage ("Destroy all Virtual Machines") { - steps { - sh "./ci-scripts/destroyAllRunningVM.sh --job-name ${JOB_NAME} --build-id ${BUILD_ID}" - } - } - } - post { - always { - 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 { - script { - def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): passed (" + BUILD_URL + ")" - if ("MERGE".equals(env.gitlabActionType)) { - echo "This is a MERGE event" - addGitLabMRComment comment: message - def message2 = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): passed (" + BUILD_URL + ") -- MergeRequest #" + env.gitlabMergeRequestIid + " (" + env.gitlabMergeRequestTitle + ")" - slackSend channel: 'ci-enb', color: 'good', message: message2 - } else { - slackSend channel: 'ci-enb', color: 'good', message: message - } - } - } - failure { - script { - def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): failed (" + BUILD_URL + ")" - if ("MERGE".equals(env.gitlabActionType)) { - echo "This is a MERGE event" - addGitLabMRComment comment: message - def message2 = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): failed (" + BUILD_URL + ") -- MergeRequest #" + env.gitlabMergeRequestIid + " (" + env.gitlabMergeRequestTitle + ")" - slackSend channel: 'ci-enb', color: 'danger', message: message2 - } else { - slackSend channel: 'ci-enb', color: 'danger', message: message - } - } - } - } -} -- GitLab