From 3e05c6acd85f2c40d5891080f5303839ee885bc6 Mon Sep 17 00:00:00 2001 From: Robert Brown Date: Thu, 9 Aug 2018 13:17:26 -0700 Subject: [PATCH 1/2] Clean working directory Prior to this commit failed builds would leave a dirty working directory. This commit fixes that by adding a try, finally block to make sure the directory is cleaned. --- Jenkinsfile | 72 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 31 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index f06d9479..037a169f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -19,47 +19,57 @@ node { node { checkout scm - image = docker.build("cmake-build:${env.BUILD_ID}") + try { + image = docker.build("cmake-build:${env.BUILD_ID}") - stage("Build ${platform}") { - image.inside { - sh "cd firmware && \ - rm -rf build_${platform} && \ - mkdir build_${platform} && \ - cd build_${platform} && \ - cmake -DVEHICLE=${platform} -DCMAKE_BUILD_TYPE=Release .. && \ - make" + stage("Build ${platform}") { + image.inside { + sh "cd firmware && \ + rm -rf build_${platform} && \ + mkdir build_${platform} && \ + cd build_${platform} && \ + cmake -DVEHICLE=${platform} -DCMAKE_BUILD_TYPE=Release .. && \ + make" - echo "${platform}: Build Complete!" + echo "${platform}: Build Complete!" + } } - } - stage("Test ${platform} unit tests") { - image.inside { - sh "cd firmware && \ - rm -rf build_${platform}_tests && \ - mkdir build_${platform}_tests && \ - cd build_${platform}_tests && \ - cmake -DVEHICLE=${platform} \ - -DTESTS=ON \ - -DPORT_SUFFIX=${EXECUTOR_NUMBER}${platform_idx} \ - -DCMAKE_BUILD_TYPE=Release \ - .. && \ - make run-unit-tests" - echo "${platform}: Unit Tests Complete!" + stage("Test ${platform} unit tests") { + image.inside { + sh "cd firmware && \ + rm -rf build_${platform}_tests && \ + mkdir build_${platform}_tests && \ + cd build_${platform}_tests && \ + cmake -DVEHICLE=${platform} \ + -DTESTS=ON \ + -DPORT_SUFFIX=${EXECUTOR_NUMBER}${platform_idx} \ + -DCMAKE_BUILD_TYPE=Release \ + .. && \ + make run-unit-tests" + echo "${platform}: Unit Tests Complete!" + } } - } - stage("Test ${platform} property-based tests") { - image.inside("--user root:root") { - sh "cd firmware/build_${platform}_tests && \ - make run-property-tests" - echo "${platform}: Property-Based Tests Complete!" + stage("Test ${platform} property-based tests") { + image.inside("--user root:root") { + sh "cd firmware/build_${platform}_tests && \ + make run-property-tests" + echo "${platform}: Property-Based Tests Complete!" + } } } + finally { + deleteDir() + } } } } - parallel builds + try { + parallel builds + } + finally { + deleteDir() + } } From b3bbab871e4320ae8541133fb6b2638442820a67 Mon Sep 17 00:00:00 2001 From: Robert Brown Date: Thu, 9 Aug 2018 13:19:20 -0700 Subject: [PATCH 2/2] Move checkout inside try block Prior to this commit the checkout call was outside the try block. This commit fixes that by moving the checkout into the try block incase it fails and the working directory still needs to be cleaned up. --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 037a169f..e05c7292 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -17,9 +17,9 @@ node { def platform = platforms[platform_idx] builds[platform] = { node { - checkout scm - try { + checkout scm + image = docker.build("cmake-build:${env.BUILD_ID}") stage("Build ${platform}") {