From acc8281b25da88d2ba942ce16bf425bc5fe63573 Mon Sep 17 00:00:00 2001 From: Dan Hawkins Date: Mon, 17 Sep 2018 13:45:37 +0100 Subject: [PATCH] Kill leftovers after a successful or failed build --- compile/eclipsebuild/eclipseds5build.gsh | 93 ++++++++++++++---------- 1 file changed, 55 insertions(+), 38 deletions(-) diff --git a/compile/eclipsebuild/eclipseds5build.gsh b/compile/eclipsebuild/eclipseds5build.gsh index 7de42dd..3444d25 100644 --- a/compile/eclipsebuild/eclipseds5build.gsh +++ b/compile/eclipsebuild/eclipseds5build.gsh @@ -1,5 +1,4 @@ - -def doKillLeftovers() { +def doDisplayLeftovers() { if (isUnix()) { sh """ # Killing any processes that may interfere with the next build @@ -7,11 +6,23 @@ def doKillLeftovers() { # Don't return an error if the processes don't exist USER=`whoami` ps aux | grep "eclipse" - # pkill -U "${USER}" -9 eclipse || true ps aux | grep "make" - # pkill -U "${USER}" -9 make || true ps aux | grep "arm-linux" - # pkill -U "${USER}" -9 ".*arm-linux.*" || true + """ + } +} + +def doKillLeftovers() { + if (isUnix()) { + doDisplayLeftovers() + sh """ + # Killing any processes that may interfere with the next build + # The build system must be setup to do more than one eclipse build concurrently + # Don't return an error if the processes don't exist + USER=`whoami` + pkill -U "${USER}" -9 eclipse || true + pkill -U "${USER}" -9 make || true + pkill -U "${USER}" -9 ".*arm-linux.*" || true """ } } @@ -106,45 +117,51 @@ def doImportProjects(ds5folder, toolchainfolder, ds5shellcommand, buildcommand, def doBuild(apps, ds5folder, toolchainfolder, ds5shellcommand, buildcommand, sourcefolder, exportfolder = "${WORKSPACE}/bin") { // The lock is being used because it was being found that the doKillLeftovers was affecting other builds lock(resource: "eclipsebuild_${env.NODE_NAME}") { - doKillLeftovers() - addToolchainPath(toolchainfolder) - doImportProjects(ds5folder, toolchainfolder, ds5shellcommand, buildcommand, sourcefolder) - for (appInfo in apps ) { - (build, cleanbuild, project, variants, exportpathlist) = appInfo - if (build) { - if (cleanbuild) { - buildtype = "-cleanBuild" + doDisplayLeftovers() + try { + addToolchainPath(toolchainfolder) + doImportProjects(ds5folder, toolchainfolder, ds5shellcommand, buildcommand, sourcefolder) + for (appInfo in apps ) { + (build, cleanbuild, project, variants, exportpathlist) = appInfo + if (build) { + if (cleanbuild) { + buildtype = "-cleanBuild" + } + else { + buildtype = "-build" + } + for (build_variant in variants) { + retry(maxprojectbuildretries) { // Eclipse occasionally raises exceptions (rather than the builds failing) + doRegisterToolchain(ds5folder, toolchainfolder) + echo "Build command: ${ds5shellcommand} \'${buildcommand} -no-indexer ${buildtype} \"${project}/${build_variant}\"\'" + if (isUnix()) { + sh """ + echo Start time: `date` + ${ds5shellcommand} \'${buildcommand} -no-indexer ${buildtype} \"${project}/${build_variant}\"\' + echo End time: `date` + """ + } + else { + bat """ + "%ds5shellcommand%" "%buildcommand%" -no-indexer ${buildtype} "${project}\\${build_variant}" + """ + } + doExport(exportfolder, exportpathlist, "", build_variant) + } + } } else { - buildtype = "-build" - } - for (build_variant in variants) { - retry(maxprojectbuildretries) { // Eclipse occasionally raises exceptions (rather than the builds failing) - doRegisterToolchain(ds5folder, toolchainfolder) - echo "Build command: ${ds5shellcommand} \'${buildcommand} -no-indexer ${buildtype} \"${project}/${build_variant}\"\'" - if (isUnix()) { - sh """ - echo Start time: `date` - ${ds5shellcommand} \'${buildcommand} -no-indexer ${buildtype} \"${project}/${build_variant}\"\' - echo End time: `date` - """ - } - else { - bat """ - "%ds5shellcommand%" "%buildcommand%" -no-indexer ${buildtype} "${project}\\${build_variant}" - """ - } - doExport(exportfolder, exportpathlist, "", build_variant) + // Only export if the project has no variants - signifying that there are files to export which have been prebuilt + if (!variants) { + doExport(exportfolder, exportpathlist, project) } } } - else { - // Only export if the project has no variants - signifying that there are files to export which have been prebuilt - if (!variants) { - doExport(exportfolder, exportpathlist, project) - } - } + } catch (Exception e) { + error "Build failed - Killing leftovers" + doKillLeftovers() } + doKillLeftovers() } }