Jenkins: Introduce a global share repository mechanism

This is a full refactor of the way jobs fetch git data: with this
approach, only the top level job, the upstream job, would set a share
folder populated with all required repositories, including
trusted-firmware-m, tf-m-tests, tf-m-ci-scripts, mbed-tls, mcuboot and
psa-arch-tests, ultimately consumed by downtream jobs,
i.e. tf-m-build-config.

This would reduce considerably the CI build times, avoiding multiple
clones per job thus overloading the TF git servers.

Signed-off-by: Leonardo Sandoval <leonardo.sandoval@linaro.org>
Change-Id: Iec3f0cc345c5052d64f0ea6ca9da01e9149a7b8b
diff --git a/jenkins/build-config.jpl b/jenkins/build-config.jpl
index 4501e3b..fd22714 100644
--- a/jenkins/build-config.jpl
+++ b/jenkins/build-config.jpl
@@ -24,85 +24,11 @@
   node(nodeLabel) {
     stage("Init") {
       cleanWs()
-      dir("trusted-firmware-m") {
-        checkout(
-          poll: false,
-          scm: [
-            $class: 'GitSCM',
-            branches: [[name: '$GERRIT_BRANCH']],
-            extensions: [[$class: 'BuildChooserSetting', buildChooser: [$class: 'GerritTriggerBuildChooser']]],
-            userRemoteConfigs: [[
-              credentialsId: 'GIT_SSH_KEY',
-              refspec: '$GERRIT_REFSPEC', url: '$CODE_REPO'
-            ]]
-          ])
-        sh "git rev-parse --short HEAD"
-      }
       dir("tf-m-ci-scripts") {
         checkout([$class: 'GitSCM', branches: [[name: '$CI_SCRIPTS_BRANCH']], userRemoteConfigs: [[credentialsId: 'GIT_SSH_KEY', url: '$CI_SCRIPTS_REPO']]])
         sh "git rev-parse --short HEAD"
-      }
-      dir("mbedtls") {
-        checkout(
-          changelog: false,
-          poll: false,
-          scm: [
-            $class: 'GitSCM',
-            branches: [[name: 'FETCH_HEAD']],
-            userRemoteConfigs: [[
-              refspec: 'refs/tags/$MBEDTLS_VERSION',
-              url: params.MBEDTLS_URL
-            ]]
-          ]
-        )
-        sh "git rev-parse --short HEAD"
-      }
-      dir("mcuboot") {
-        checkout(
-          changelog: false,
-          poll: false,
-          scm: [
-            $class: 'GitSCM',
-            branches: [[name: 'FETCH_HEAD']],
-            userRemoteConfigs: [[
-              refspec: '$MCUBOOT_REFSPEC',
-              url: params.MCUBOOT_URL
-            ]]
-          ]
-        )
-        sh "git rev-parse --short HEAD"
-      }
-      dir("tf-m-tests") {
-        checkout(
-          changelog: false,
-          poll: false,
-          scm: [
-            $class: 'GitSCM',
-            branches: [[name: 'FETCH_HEAD']],
-            userRemoteConfigs: [[
-              refspec: '$TFM_TESTS_REFSPEC',
-              url: params.TFM_TESTS_URL
-            ]]
-          ]
-        )
-        sh "git rev-parse --short HEAD"
-      }
-      if (env.PSA_API_SUITE != "") {
-        dir("psa-arch-tests") {
-          checkout(
-            changelog: false,
-            poll: false,
-            scm: [
-              $class: 'GitSCM',
-              branches: [[name: 'FETCH_HEAD']],
-              userRemoteConfigs: [[
-                refspec: '$PSA_ARCH_TESTS_VERSION',
-                url: params.PSA_ARCH_TESTS_URL
-              ]]
-            ]
-          )
-          sh "git rev-parse --short HEAD"
-        }
+        // Clone TF-M repositories so share folder can be reused by downstream jobs
+        sh "./clone.sh"
       }
     }
     try {