Index: Jenkinsfile
===================================================================
--- Jenkinsfile	(revision 0fd5003908c4297f687f00a4ca12a6dceebb85ac)
+++ Jenkinsfile	(revision 5b8413b40560cc34aa233230cdcec8c8a69aa5c2)
@@ -6,16 +6,13 @@
 node ('master'){
 
+	// Globals
+	BuildDir  = pwd tmp: true
+	SrcDir    = pwd tmp: false
+	Settings  = null
+	StageName = ''
+
+	// Local variables
 	def err = null
 	def log_needed = false
-
-	Settings = null
-
-	stage_name 	   = ''
-
-	gitRefOldValue = ''
-	gitRefNewValue = ''
-
-	builddir = pwd tmp: true
-	srcdir   = pwd tmp: false
 
 	currentBuild.result = "SUCCESS"
@@ -61,5 +58,5 @@
 
 		//Store the result of the build log
-		currentBuild.result = "${stage_name} FAILURE".trim()
+		currentBuild.result = "${StageName} FAILURE".trim()
 	}
 
@@ -77,4 +74,188 @@
 			throw err
 		}
+	}
+}
+
+//===========================================================================================================
+// Main compilation routines
+//===========================================================================================================
+def clean() {
+	build_stage('Cleanup') {
+		// clean the build by wipping the build directory
+		dir(BuildDir) {
+			deleteDir()
+		}
+
+		//Clean all temporary files to make sure no artifacts of the previous build remain
+		sh 'git clean -fdx'
+
+		//Reset the git repo so no local changes persist
+		sh 'git reset --hard'
+	}
+}
+
+//Compilation script is done here but environnement set-up and error handling is done in main loop
+def checkout() {
+	build_stage('Checkout') {
+		//checkout the source code and clean the repo
+		checkout scm
+	}
+}
+
+def build() {
+	build_stage('Build') {
+		// Build outside of the src tree to ease cleaning
+		dir (BuildDir) {
+			//Configure the conpilation (Output is not relevant)
+			//Use the current directory as the installation target so nothing escapes the sandbox
+			//Also specify the compiler by hand
+			targets=""
+			if( Settings.RunAllTests ) {
+				targets="--with-target-hosts='host:debug,host:nodebug'"
+			} else {
+				targets="--with-target-hosts='host:debug'"
+			}
+
+			sh "${SrcDir}/configure CXX=${Settings.Compiler.cpp_cc} ${Settings.Architecture.flags} ${targets} --with-backend-compiler=${Settings.Compiler.cfa_cc} --quiet"
+
+			//Compile the project
+			sh 'make -j 8 --no-print-directory'
+		}
+	}
+}
+
+def test() {
+	build_stage('Test') {
+
+		dir (BuildDir) {
+			//Run the tests from the tests directory
+			if ( Settings.RunAllTests ) {
+				sh 'make --no-print-directory -C tests all-tests debug=yes'
+				sh 'make --no-print-directory -C tests all-tests debug=no '
+			}
+			else {
+				sh 'make --no-print-directory -C tests'
+			}
+		}
+	}
+}
+
+def benchmark() {
+	build_stage('Benchmark') {
+
+		if( !Settings.RunBenchmark ) return
+
+		dir (BuildDir) {
+			//Append bench results
+			sh "make --no-print-directory -C benchmark jenkins githash=${gitRefNewValue} arch=${Settings.Architecture} | tee ${SrcDir}/bench.json"
+		}
+	}
+}
+
+def build_doc() {
+	build_stage('Documentation') {
+
+		if( !Settings.BuildDocumentation ) return
+
+		dir ('doc/user') {
+			make_doc()
+		}
+
+		dir ('doc/refrat') {
+			make_doc()
+		}
+	}
+}
+
+def publish() {
+	build_stage('Publish') {
+
+		if( !Settings.Publish ) return
+
+		//Then publish the results
+		sh 'curl --silent --show-error -H \'Content-Type: application/json\' --data @bench.json https://cforall.uwaterloo.ca:8082/jenkins/publish > /dev/null || true'
+	}
+}
+
+//===========================================================================================================
+//Routine responsible of sending the email notification once the build is completed
+//===========================================================================================================
+def gitBranchUpdate(String gitRefOldValue, String gitRefNewValue) {
+	def update = ""
+	sh "git rev-list ${gitRefOldValue}..${gitRefNewValue} > GIT_LOG";
+	readFile('GIT_LOG').eachLine { rev ->
+		sh "git cat-file -t ${rev} > GIT_TYPE"
+		def type = readFile('GIT_TYPE')
+
+		update += "       via  ${rev} (${type})\n"
+	}
+	def rev = gitRefOldValue
+	sh "git cat-file -t ${rev} > GIT_TYPE"
+	def type = readFile('GIT_TYPE')
+
+	update += "      from  ${rev} (${type})\n"
+	return update
+
+	def output=readFile('result').trim()
+	echo "output=$output";
+}
+
+//Standard build email notification
+def email(String status, boolean log, boolean bIsSandbox) {
+	//Since tokenizer doesn't work, figure stuff out from the environnement variables and command line
+	//Configurations for email format
+	def project_name = (env.JOB_NAME =~ /(.+)\/.+/)[0][1].toLowerCase()
+
+	def gitLog = 'Error retrieving git logs'
+	def gitDiff = 'Error retrieving git diff'
+	def gitUpdate = 'Error retrieving update'
+
+	try {
+		final scmVars = checkout(scm)
+
+		gitUpdate = gitBranchUpdate(scmVars.GIT_PREVIOUS_COMMIT, scmVars.GIT_COMMIT)
+
+		sh "git rev-list --format=short ${scmVars.GIT_PREVIOUS_COMMIT}...${scmVars.GIT_COMMIT} > ${BuildDir}/GIT_LOG"
+		gitLog = readFile("${BuildDir}/GIT_LOG")
+
+		sh "git diff --stat ${scmVars.GIT_COMMIT} ${scmVars.GIT_PREVIOUS_COMMIT} > ${BuildDir}/GIT_DIFF"
+		gitDiff = readFile("${BuildDir}/GIT_DIFF")
+	}
+	catch (Exception error) {
+		echo error.toString()
+		echo error.getMessage()
+	}
+
+	def email_subject = "[${project_name} git][BUILD# ${env.BUILD_NUMBER} - ${status}] - branch ${env.BRANCH_NAME}"
+	def email_body = """This is an automated email from the Jenkins build machine. It was
+generated because of a git hooks/post-receive script following
+a ref change was pushed to the repository containing
+the project "UNNAMED PROJECT".
+
+The branch ${env.BRANCH_NAME} has been updated.
+${gitUpdate}
+
+Check console output at ${env.BUILD_URL} to view the results.
+
+- Status --------------------------------------------------------------
+
+BUILD# ${env.BUILD_NUMBER} - ${status}
+
+- Log -----------------------------------------------------------------
+${gitLog}
+-----------------------------------------------------------------------
+Summary of changes:
+${gitDiff}
+"""
+
+	def email_to = "cforall@lists.uwaterloo.ca"
+
+	if( !bIsSandbox ) {
+		//send email notification
+		emailext body: email_body, subject: email_subject, to: email_to, attachLog: log
+	} else {
+		echo "Would send email to: ${email_to}"
+		echo "With title: ${email_subject}"
+		echo "Content: \n${email_body}"
 	}
 }
@@ -224,6 +405,7 @@
 
 def build_stage(String name, Closure block ) {
-	stage_name = name
+	StageName = name
 	stage(name, block)
+	echo " -------- ${StageName} -------- "
 }
 
@@ -247,186 +429,2 @@
 	}
 }
-
-//===========================================================================================================
-// Main compilation routines
-//===========================================================================================================
-def clean() {
-	build_stage('Cleanup') {
-		// clean the build by wipping the build directory
-		dir(builddir) {
-			deleteDir()
-		}
-
-		//Clean all temporary files to make sure no artifacts of the previous build remain
-		sh 'git clean -fdqx'
-
-		//Reset the git repo so no local changes persist
-		sh 'git reset --hard'
-	}
-}
-
-//Compilation script is done here but environnement set-up and error handling is done in main loop
-def checkout() {
-	build_stage('Checkout') {
-		//checkout the source code and clean the repo
-		checkout scm
-	}
-}
-
-def build() {
-	build_stage('Build') {
-		// Build outside of the src tree to ease cleaning
-		dir (builddir) {
-			//Configure the conpilation (Output is not relevant)
-			//Use the current directory as the installation target so nothing escapes the sandbox
-			//Also specify the compiler by hand
-			targets=""
-			if( Settings.RunAllTests ) {
-				targets="--with-target-hosts='host:debug,host:nodebug'"
-			} else {
-				targets="--with-target-hosts='host:debug'"
-			}
-
-			sh "${srcdir}/configure CXX=${Settings.Compiler.cpp_cc} ${Settings.Architecture.flags} ${targets} --with-backend-compiler=${Settings.Compiler.cfa_cc} --quiet"
-
-			//Compile the project
-			sh 'make -j 8 --no-print-directory'
-		}
-	}
-}
-
-def test() {
-	build_stage('Test') {
-
-		dir (builddir) {
-			//Run the tests from the tests directory
-			if ( Settings.RunAllTests ) {
-				sh 'make --no-print-directory -C tests all-tests debug=yes'
-				sh 'make --no-print-directory -C tests all-tests debug=no '
-			}
-			else {
-				sh 'make --no-print-directory -C tests'
-			}
-		}
-	}
-}
-
-def benchmark() {
-	build_stage('Benchmark') {
-
-		if( !Settings.RunBenchmark ) return
-
-		dir (builddir) {
-			//Append bench results
-			sh "make --no-print-directory -C benchmark jenkins githash=${gitRefNewValue} arch=${Settings.Architecture} | tee ${srcdir}/bench.json"
-		}
-	}
-}
-
-def build_doc() {
-	build_stage('Documentation') {
-
-		if( !Settings.BuildDocumentation ) return
-
-		dir ('doc/user') {
-			make_doc()
-		}
-
-		dir ('doc/refrat') {
-			make_doc()
-		}
-	}
-}
-
-def publish() {
-	build_stage('Publish') {
-
-		if( !Settings.Publish ) return
-
-		//Then publish the results
-		sh 'curl --silent --show-error -H \'Content-Type: application/json\' --data @bench.json https://cforall.uwaterloo.ca:8082/jenkins/publish > /dev/null || true'
-	}
-}
-
-//===========================================================================================================
-//Routine responsible of sending the email notification once the build is completed
-//===========================================================================================================
-def gitBranchUpdate(String gitRefOldValue, String gitRefNewValue) {
-	def update = ""
-	sh "git rev-list ${gitRefOldValue}..${gitRefNewValue} > GIT_LOG";
-	readFile('GIT_LOG').eachLine { rev ->
-		sh "git cat-file -t ${rev} > GIT_TYPE"
-		def type = readFile('GIT_TYPE')
-
-		update += "       via  ${rev} (${type})\n"
-	}
-	def rev = gitRefOldValue
-	sh "git cat-file -t ${rev} > GIT_TYPE"
-	def type = readFile('GIT_TYPE')
-
-	update += "      from  ${rev} (${type})\n"
-	return update
-
-	def output=readFile('result').trim()
-	echo "output=$output";
-}
-
-//Standard build email notification
-def email(String status, boolean log, boolean bIsSandbox) {
-	//Since tokenizer doesn't work, figure stuff out from the environnement variables and command line
-	//Configurations for email format
-	def project_name = (env.JOB_NAME =~ /(.+)\/.+/)[0][1].toLowerCase()
-
-	def gitLog = 'Error retrieving git logs'
-	def gitDiff = 'Error retrieving git diff'
-	def gitUpdate = 'Error retrieving update'
-
-	try {
-		final scmVars = checkout(scm)
-
-		gitUpdate = gitBranchUpdate(scmVars.GIT_PREVIOUS_COMMIT, scmVars.GIT_COMMIT)
-
-		sh "git rev-list --format=short ${scmVars.GIT_PREVIOUS_COMMIT}...${scmVars.GIT_COMMIT} > GIT_LOG"
-		gitLog = readFile('GIT_LOG')
-
-		sh "git diff --stat ${scmVars.GIT_COMMIT} ${scmVars.GIT_PREVIOUS_COMMIT} > GIT_DIFF"
-		gitDiff = readFile('GIT_DIFF')
-	}
-	catch (Exception error) {
-		echo error.toString()
-		echo error.getMessage()
-	}
-
-	def email_subject = "[${project_name} git][BUILD# ${env.BUILD_NUMBER} - ${status}] - branch ${env.BRANCH_NAME}"
-	def email_body = """This is an automated email from the Jenkins build machine. It was
-generated because of a git hooks/post-receive script following
-a ref change was pushed to the repository containing
-the project "UNNAMED PROJECT".
-
-The branch ${env.BRANCH_NAME} has been updated.
-${gitUpdate}
-
-Check console output at ${env.BUILD_URL} to view the results.
-
-- Status --------------------------------------------------------------
-
-BUILD# ${env.BUILD_NUMBER} - ${status}
-
-- Log -----------------------------------------------------------------
-${gitLog}
------------------------------------------------------------------------
-Summary of changes:
-${gitDiff}
-"""
-
-	def email_to = "cforall@lists.uwaterloo.ca"
-
-	if( !bIsSandbox ) {
-		//send email notification
-		emailext body: email_body, subject: email_subject, to: email_to, attachLog: log
-	} else {
-		echo "Would send email to: ${email_to}"
-		echo "With title: ${email_subject}"
-		echo "Content: \n${email_body}"
-	}
-}
