
//Configurations for email format
def email_subject_template = '[$PROJECT_NAME git] - branch $GIT_BRANCH - Build # $BUILD_NUMBER - $BUILD_STATUS!'
def email_body_template = '''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 $GIT_BRANCH has been updated
       via  $GIT_COMMIT (commit)
      from  $GIT_PREVIOUS_COMMIT (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

Check console output at $BUILD_URL to view the results.'''

node ('master'){
	stage 'Build'
	//clean the repo and checkout the source code
	checkout scm

	//Configurations for email format

	//Since tokenizer doesn't work, figure stuff out from the environnement variables and command line
	def project_name = (env.JOB_NAME =~ /(.+)\/.+/)[0][1]

	def email_subject = "[${project_name} git] - branch ${env.BRANCH_NAME} - Build # ${env.BUILD_NUMBER} - BUILD_STATUS!"
	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
	       via  GIT_COMMIT (commit)
	      from  GIT_PREVIOUS_COMMIT (commit)

	Those revisions listed above that are new to this repository have
	not appeared on any other notification email; so we list those
	revisions in full, below.

	Check console output at ${env.BUILD_URL} to view the results."""

	//configure the conpilation
	sh 'CC=gcc-4.9 CXX=g++-4.9 ./configure'

	//build
	sh 'make -j 8'

	//send email notification

	def email_subject = email_subject_template
	def email_body = email_body_template
	def email_to = 'tdelisle@uwaterloo.ca'

	emailext body: email_body, subject: email_subject, to: email_to, attachLog: true
 }
