More fixes to fossa pipeline job

Change-Id: If18a75e8cee6f7c03241db374efbfc520de8c4c3
diff --git a/jjb/pipeline/fossa-verify.groovy b/jjb/pipeline/fossa-verify.groovy
index ebf7769..02662b9 100644
--- a/jjb/pipeline/fossa-verify.groovy
+++ b/jjb/pipeline/fossa-verify.groovy
@@ -40,16 +40,17 @@
 
     stage('Checkout') {
       steps {
-        checkout([
-          $class: 'GitSCM',
-          userRemoteConfigs: [[ url: "${params.gitUrl}", ]],
-          branches: [[ name: "${params.gitRef}", ]],
-          extensions: [
-            [$class: 'WipeWorkspace'],
-            [$class: 'RelativeTargetDirectory', relativeTargetDir: "${params.projectName}"],
-            [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
-          ],
-        ])
+        sh returnStdout: true, script: """
+          #!/usr/bin/env bash
+          set -eu -o pipefail
+
+          echo "Cloning repo: ${gitUrl}"
+          git clone "${gitUrl}"
+          pushd "$projectName"
+          echo "Checking out Gerrit patchset: ${GERRIT_REFSPEC}"
+          git fetch ${gitUrl} ${GERRIT_REFSPEC} && git checkout FETCH_HEAD
+          popd
+        """
 
         // Used later to set the branch/tag
         script {
@@ -67,6 +68,10 @@
         }
 
         sh returnStdout: true, script: """
+          #!/usr/bin/env bash
+          set -eu -o pipefail
+
+
           if [ -f "$projectName/package.json" ]
           then
             echo "Found '$projectName/package.json', assuming a Node.js project, running npm install"
@@ -81,14 +86,6 @@
             pushd "$test_path"
             dep ensure
             popd
-          elif [ -f "$projectName/go.mod" ]
-          then
-            echo "Found '$projectName/go.mod', assuming a golang project using go modules"
-            mkdir -p "\$GOPATH/src/github.com/opencord/"
-            mv "$WORKSPACE/$projectName" "$test_path"
-            pushd "$test_path"
-            make dep
-            popd
           fi
         """
       }
@@ -99,45 +96,50 @@
         // catch any errors that occur so that logs can be saved in the next stage
         // docs: https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#catcherror-catch-error-and-set-build-result-to-failure
         catchError {
+          withCredentials([string(credentialsId: 'fossa-api-key', variable: 'FOSSA_API_KEY')]) {
+            sh returnStdout: true, script: """
+              #!/usr/bin/env bash
+              set -eu -o pipefail
 
-          sh returnStdout: true, script: """
-            echo "Creating debug output directory"
-            mkdir -p "$WORKSPACE/debug"
+              echo "Creating debug output directory"
+              mkdir -p "$WORKSPACE/debug"
 
-            echo "Download/install fossa tool"
-            curl -H 'Cache-Control: no-cache' -O https://raw.githubusercontent.com/fossas/fossa-cli/master/install.sh
-            mkdir -p "$WORKSPACE/go/bin"
-            bash install.sh -b "$WORKSPACE/go/bin"
+              echo "Download/install fossa CLI tool"
+              curl -H 'Cache-Control: no-cache' -O https://raw.githubusercontent.com/fossas/fossa-cli/master/install.sh
+              mkdir -p "$WORKSPACE/go/bin"
+              bash install.sh -b "$WORKSPACE/go/bin"
 
-            echo "Fossa version:"
-            fossa -v
+              echo "Fossa version:"
+              fossa -v
 
-            echo "Testing project: $projectName located in $test_path"
-            pushd "$test_path"
+              echo "Testing project: $projectName located in $test_path"
+              pushd "$test_path"
 
-            echo "Fossa init"
-            fossa init --no-ansi --debug 2>"$WORKSPACE/debug/init_stderr.log"
+              echo "Run 'fossa init'"
+              fossa init --no-ansi --verbose
 
-            echo "Fossa analyze"
-            fossa analyze --no-ansi --debug \
-                          -T "$fossaProject"
-                          -t "$projectName" \
-                          -L "$GERRIT_CHANGE_URL" \
-                          -b "$git_tag_or_branch" \
-                          -r "$GERRIT_CHANGE_NUMBER.$GERRIT_PATCHSET_NUMBER" \
-                          2>"$WORKSPACE/debug/analyze_stderr.log"
+              echo "Contents of .fossa.yml generated by 'fossa init':"
+              cat .fossa.yml
 
-            echo "Fossa test results"
-            fossa test --no-ansi --debug \
-                          -T "$fossaProject"
-                          -t "$projectName" \
-                          -L "$GERRIT_CHANGE_URL" \
-                          -b "$git_tag_or_branch" \
-                          -r "$GERRIT_CHANGE_NUMBER.$GERRIT_PATCHSET_NUMBER" \
-                          2>"$WORKSPACE/debug/test_stderr.log"
+              echo "Run 'fossa analyze'"
+              fossa analyze --no-ansi --verbose \
+                            -T "$fossaTeam" \
+                            -t "$projectName" \
+                            -L "$GERRIT_CHANGE_URL" \
+                            -b "$git_tag_or_branch" \
+                            -r "$GERRIT_CHANGE_NUMBER/$GERRIT_PATCHSET_NUMBER"
 
-            popd
-          """
+              echo "Get FOSSA test results with 'fossa test'"
+              fossa test --no-ansi --verbose \
+                            -T "$fossaTeam" \
+                            -t "$projectName" \
+                            -L "$GERRIT_CHANGE_URL" \
+                            -b "$git_tag_or_branch" \
+                            -r "$GERRIT_CHANGE_NUMBER/$GERRIT_PATCHSET_NUMBER"
+
+              popd
+            """
+          }
         }
       }
     }