From 953e3dfc0051dcdb800e4b5c3249629ca92f1fd3 Mon Sep 17 00:00:00 2001 From: Dan Hawkins Date: Mon, 17 Sep 2018 09:08:28 +0100 Subject: [PATCH] Stop builds killing each other on the same slave --- compile/eclipsebuild/eclipseds5build.gsh | 79 ++++++++++++------------ 1 file changed, 40 insertions(+), 39 deletions(-) diff --git a/compile/eclipsebuild/eclipseds5build.gsh b/compile/eclipsebuild/eclipseds5build.gsh index 731c6b4..4638179 100644 --- a/compile/eclipsebuild/eclipseds5build.gsh +++ b/compile/eclipsebuild/eclipseds5build.gsh @@ -4,15 +4,13 @@ def doKillLeftovers() { 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 - USER=`whoami` - pgrep -U "${USER}" "eclipse" || true - pgrep -U "${USER}" "eclipsews" || true - pgrep -U "${USER}" "make" || true - pgrep -U "${USER}" "arm-linux" || true # Don't return an error if the processes don't exist + USER=`whoami` + ps aux | grep "eclipse" pkill -U "${USER}" -9 eclipse || true - pkill -U "${USER}" -9 eclipsews || true + ps aux | grep "make" pkill -U "${USER}" -9 make || true + ps aux | grep "arm-linux" pkill -U "${USER}" -9 ".*arm-linux.*" || true """ } @@ -106,42 +104,45 @@ def doImportProjects(ds5folder, toolchainfolder, ds5shellcommand, buildcommand, // Build and export files def doBuild(apps, ds5folder, toolchainfolder, ds5shellcommand, buildcommand, sourcefolder, exportfolder = "${WORKSPACE}/bin") { - 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" - } - 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} ${buildtype} \"${project}/${build_variant}\"\'" - if (isUnix()) { - sh """ - echo Start time: `date` - ${ds5shellcommand} \'${buildcommand} ${buildtype} \"${project}/${build_variant}\"\' - echo End time: `date` - """ + // 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" + } + 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} ${buildtype} \"${project}/${build_variant}\"\'" + if (isUnix()) { + sh """ + echo Start time: `date` + ${ds5shellcommand} \'${buildcommand} ${buildtype} \"${project}/${build_variant}\"\' + echo End time: `date` + """ + } + else { + bat """ + "%ds5shellcommand%" "%buildcommand%" ${buildtype} "${project}\\${build_variant}" + """ + } + doExport(exportfolder, exportpathlist, "", build_variant) } - else { - bat """ - "%ds5shellcommand%" "%buildcommand%" ${buildtype} "${project}\\${build_variant}" - """ - } - doExport(exportfolder, exportpathlist, "", build_variant) } } - } - 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) + 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) + } } } }