VOL-4795 - Researching community pod faiure.

.gitignore
----------
   o Add exclusions so npm-groovy-lint can be used.

vars/getVolthaCode.groovy
-------------------------
   o Added an iam() method to self-identfy the scirpt.
   o Wrap call() logic in a try/catch block so problems are always visible.
   o groovy-lint - declare local vars to shorten long lines.
   o Add whitespace and separation for readability.

Include more sources to trigger a jenkins build.

Change-Id: I50be0be0dbd69da55d6aad5c48bc6ef832056afc
diff --git a/vars/getVolthaCode.groovy b/vars/getVolthaCode.groovy
index d763429..d7cb445 100644
--- a/vars/getVolthaCode.groovy
+++ b/vars/getVolthaCode.groovy
@@ -1,109 +1,168 @@
+#!/usr/bin/env groovy
+// -----------------------------------------------------------------------
+// -----------------------------------------------------------------------
+
+// -----------------------------------------------------------------------
+// -----------------------------------------------------------------------
+def getIam(String func)
+{
+    String src = 'vars/getVolthaCode.groovy'
+    String iam = [src, func].join('::')
+    return iam
+}
+
 // TODO the 3 stages are very similar, most of the code can be shared
 
-def call(Map config) {
+def wrapped(Map config)
+{
+    def defaultConfig = [
+	branch: "master",
+	gerritProject: "",
+	gerritRefspec: "",
+	volthaSystemTestsChange: "",
+	volthaHelmChartsChange: "",
+    ]
+    
+    def cfg = defaultConfig + config
 
-  def defaultConfig = [
-    branch: "master",
-    gerritProject: "",
-    gerritRefspec: "",
-    volthaSystemTestsChange: "",
-    volthaHelmChartsChange: "",
-  ]
+    println "Downloading VOLTHA code with the following parameters: ${cfg}."
 
-  if (!config) {
-      config = [:]
-  }
+    stage('Download Patch')
+    {
+	frequent_repos = [
+	    '',
+	    'voltha-system-tests',
+	    'voltha-helm-charts',
+	]
 
-  def cfg = defaultConfig + config
+	// We are always downloading those repos, if the patch under test is in one of those
+	// just checkout the patch, no need to clone it again
+	if ( !(cfg.gerritProject in frequent_repos))
+	{
+	    repo_project = "https://gerrit.opencord.org/${cfg.gerritProject}"
+		
+	    checkout([
+		$class: 'GitSCM',
+		userRemoteConfigs: [[ url:repo_project ]],
+		branches: [[ name: "${cfg.branch}", ]],
+		extensions: [
+		    [$class: 'WipeWorkspace'],
+		    [$class: 'RelativeTargetDirectory', relativeTargetDir: "${cfg.gerritProject}"],
+		    [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
+		],
+	    ])
 
-  println "Downloading VOLTHA code with the following parameters: ${cfg}."
-
-  stage('Download Patch') {
-    // We are always downloading those repos, if the patch under test is in one of those
-    // just checkout the patch, no need to clone it again
-    if (cfg.gerritProject != 'voltha-system-tests' &&
-      cfg.gerritProject != 'voltha-helm-charts' &&
-      cfg.gerritProject != '') {
-      checkout([
-        $class: 'GitSCM',
-        userRemoteConfigs: [[
-          url: "https://gerrit.opencord.org/${cfg.gerritProject}",
-        ]],
-        branches: [[ name: "${cfg.branch}", ]],
-        extensions: [
-          [$class: 'WipeWorkspace'],
-          [$class: 'RelativeTargetDirectory', relativeTargetDir: "${cfg.gerritProject}"],
-          [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
-        ],
-      ])
-      sh """
+	    sh """
         pushd $WORKSPACE/${cfg.gerritProject}
+        git fetch "$repo_project" ${cfg.gerritRefspec} && git checkout FETCH_HEAD
+
+        echo "Currently on commit: \n"
+        git log -1 --oneline
+        popd
+      """
+	}
+    }
+
+    stage('Clone voltha-system-tests')
+    {	
+	repo_vst = 'https://gerrit.opencord.org/voltha-system-tests'
+
+	checkout([
+	    $class: 'GitSCM',
+	    userRemoteConfigs: [[ url:repo_url ]],
+	    branches: [[ name: "${cfg.branch}", ]],
+	    extensions: [
+		[$class: 'WipeWorkspace'],
+		[$class: 'RelativeTargetDirectory', relativeTargetDir: "voltha-system-tests"],
+		[$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
+	    ],
+	])
+
+	if (cfg.volthaSystemTestsChange != '' && cfg.gerritProject != 'voltha-system-tests')
+	{
+	    sh """
+        cd "$WORKSPACE/voltha-system-tests"
+        git fetch "${repo_vst}" ${cfg.volthaSystemTestsChange} && git checkout FETCH_HEAD
+      """
+	}
+	else if (cfg.gerritProject == 'voltha-system-tests') {
+	    sh """
+        pushd "$WORKSPACE/${cfg.gerritProject}"
         git fetch https://gerrit.opencord.org/${cfg.gerritProject} ${cfg.gerritRefspec} && git checkout FETCH_HEAD
 
         echo "Currently on commit: \n"
         git log -1 --oneline
         popd
       """
+	}
     }
-  }
-  stage('Clone voltha-system-tests') {
-    checkout([
-      $class: 'GitSCM',
-      userRemoteConfigs: [[
-        url: "https://gerrit.opencord.org/voltha-system-tests",
-      ]],
-      branches: [[ name: "${cfg.branch}", ]],
-      extensions: [
-        [$class: 'WipeWorkspace'],
-        [$class: 'RelativeTargetDirectory', relativeTargetDir: "voltha-system-tests"],
-        [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
-      ],
-    ])
-    if (cfg.volthaSystemTestsChange != '' && cfg.gerritProject != 'voltha-system-tests') {
-      sh """
-        cd $WORKSPACE/voltha-system-tests
-        git fetch https://gerrit.opencord.org/voltha-system-tests ${cfg.volthaSystemTestsChange} && git checkout FETCH_HEAD
+
+    stage('Clone voltha-helm-charts')
+    {
+	repo_vhc = 'https://gerrit.opencord.org/voltha-helm-charts'
+
+	checkout([
+	    $class: 'GitSCM',
+	    userRemoteConfigs: [[ url:repo_vhc ]],
+	    branches: [[ name: "${cfg.branch}", ]],
+	    extensions: [
+		[$class: 'WipeWorkspace'],
+		[$class: 'RelativeTargetDirectory', relativeTargetDir: "voltha-helm-charts"],
+		[$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
+	    ],
+	])
+
+	if (cfg.volthaHelmChartsChange != '' && cfg.gerritProject != 'voltha-helm-charts') {
+	    sh """
+        cd "$WORKSPACE/voltha-helm-charts"
+        git fetch "$repo_vhc" ${cfg.volthaHelmChartsChange} && git checkout FETCH_HEAD
       """
-    }
-    else if (cfg.gerritProject == 'voltha-system-tests') {
-      sh """
-        pushd $WORKSPACE/${cfg.gerritProject}
-        git fetch https://gerrit.opencord.org/${cfg.gerritProject} ${cfg.gerritRefspec} && git checkout FETCH_HEAD
+	}
+	else if (cfg.gerritProject == 'voltha-helm-charts') {
+	    sh """
+        pushd "$WORKSPACE/${cfg.gerritProject}"
+        git fetch "https://gerrit.opencord.org/${cfg.gerritProject}" ${cfg.gerritRefspec} && git checkout FETCH_HEAD
 
         echo "Currently on commit: \n"
         git log -1 --oneline
         popd
       """
+	}
     }
-  }
-  stage('Clone voltha-helm-charts') {
-    checkout([
-      $class: 'GitSCM',
-      userRemoteConfigs: [[
-        url: "https://gerrit.opencord.org/voltha-helm-charts",
-      ]],
-      branches: [[ name: "${cfg.branch}", ]],
-      extensions: [
-        [$class: 'WipeWorkspace'],
-        [$class: 'RelativeTargetDirectory', relativeTargetDir: "voltha-helm-charts"],
-        [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
-      ],
-    ])
-    if (cfg.volthaHelmChartsChange != '' && cfg.gerritProject != 'voltha-helm-charts') {
-      sh """
-        cd $WORKSPACE/voltha-helm-charts
-        git fetch https://gerrit.opencord.org/voltha-helm-charts ${cfg.volthaHelmChartsChange} && git checkout FETCH_HEAD
-      """
-    }
-    else if (cfg.gerritProject == 'voltha-helm-charts') {
-      sh """
-        pushd $WORKSPACE/${cfg.gerritProject}
-        git fetch https://gerrit.opencord.org/${cfg.gerritProject} ${cfg.gerritRefspec} && git checkout FETCH_HEAD
+}
 
-        echo "Currently on commit: \n"
-        git log -1 --oneline
-        popd
-      """
+// -----------------------------------------------------------------------
+// -----------------------------------------------------------------------
+def call(Map config)
+{
+    String iam = getIam('main')
+    Boolean debug = false
+
+    if (debug)
+    {
+	println("** ${iam}: ENTER")
     }
-  }
+
+    if (!config) {
+        config = [:]
+    }
+
+    try
+    {
+	wrapped(config)
+    }
+    catch (Exception err)
+    {
+	println("** ${iam}: EXCEPTION ${err}")
+	throw err
+    }
+    finally
+    {
+	if (debug)
+	{
+	    println("** ${iam}: LEAVE")
+	}
+    }
+
+    return
 }