Adding timeout to Jenkins TestON Pipelines

Change-Id: Ib4fd0dd842bc33eebd227a5ebecad640868291d1
diff --git a/TestON/JenkinsFile/CommonJenkinsFile.groovy b/TestON/JenkinsFile/CommonJenkinsFile.groovy
index 2edc09d..33ed5d1 100644
--- a/TestON/JenkinsFile/CommonJenkinsFile.groovy
+++ b/TestON/JenkinsFile/CommonJenkinsFile.groovy
@@ -27,6 +27,8 @@
 fileRelated = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsPathAndFiles.groovy' )
 SCPFfuncs = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/PerformanceFuncs.groovy' )
 
+INITIALIZATION_TIMEOUT_MINUTES = 10 // timeout init() function if it takes too long.
+
 category = null
 prop = null
 testsToRun = null
@@ -39,6 +41,8 @@
 testsOverride = null
 isGraphOnly = false
 isSCPF = false
+pipelineTimeout = null
+
 testsFromList = [:]
 graphPaths = [:]
 pipeline = [:]
@@ -46,10 +50,14 @@
 main()
 
 def main(){
-    init()
-    runTests()
-    generateGraphs()
-    sendToSlack()
+    timeout( time: INITIALIZATION_TIMEOUT_MINUTES, unit: "MINUTES" ){
+        init()
+    }
+    timeout( time: pipelineTimeout, unit: "MINUTES" ){
+        runTests()
+        generateGraphs()
+        sendToSlack()
+    }
 }
 
 def init(){
@@ -92,6 +100,7 @@
     nodeLabel = params.NodeLabel     // "BM", "VM", "Fabric-1.x", etc.
     testsOverride = params.TestsOverride // "FUNCflow, FUNCintent, [...]", overrides property file
     isGraphOnly = params.OnlyRefreshGraphs // true or false
+    pipelineTimeout = params.TimeOut.toInteger() // integer minutes until the entire pipeline times out. Usually passed from upstream master-trigger job.
 }
 
 def getProperties(){