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/static.jpl b/jenkins/static.jpl
index a7fe36d..4341b4c 100644
--- a/jenkins/static.jpl
+++ b/jenkins/static.jpl
@@ -17,6 +17,16 @@
     params += string(name: 'GERRIT_PATCHSET_REVISION', value: env.GERRIT_PATCHSET_REVISION ?: '')
     params += string(name: 'MBEDTLS_VERSION', value: env.MBEDTLS_VERSION)
     params += string(name: 'CODE_REPO', value: env.CODE_REPO)
+    params += string(name: 'CI_SCRIPTS_BRANCH', value: env.CI_SCRIPTS_BRANCH)
+    params += string(name: 'MCUBOOT_REFSPEC', value: env.MCUBOOT_REFSPEC)
+    params += string(name: 'MCUBOOT_URL', value: env.MCUBOOT_URL)
+    params += string(name: 'MBEDTLS_VERSION', value: env.MBEDTLS_VERSION)
+    params += string(name: 'MCUBOOT_URL', value: env.MBEDTLS_URL)
+    params += string(name: 'TFM_TESTS_REFSPEC', value: env.TFM_TESTS_REFSPEC)
+    params += string(name: 'TFM_TESTS_URL', value: env.TFM_TESTS_URL)
+    params += string(name: 'PSA_ARCH_TESTS_VERSION', value: env.PSA_ARCH_TESTS_VERSION)
+    params += string(name: 'PSA_ARCH_TESTS_URL', value: env.PSA_ARCH_TESTS_URL)
+    params += string(name: 'SHARE_FOLDER', value: env.SHARE_FOLDER)
     build(job: job_name, parameters: params)
   }
 }
@@ -24,6 +34,16 @@
 def status = 1
 
 timestamps {
+  node("docker-amd64-tf-m-bionic") {
+    stage("Init") {
+      cleanWs()
+      dir("tf-m-ci-scripts") {
+        checkout([$class: 'GitSCM', branches: [[name: '$CI_SCRIPTS_BRANCH']], userRemoteConfigs: [[credentialsId: 'GIT_SSH_KEY', url: '$CI_SCRIPTS_REPO']]])
+        // Clone TF-M repositories so share folder can be reused by downstream jobs
+        sh "./clone.sh"
+      }
+    }
+  }
   stage("Static Checks") {
     def checks = [:]
     checks["cppcheck"] = trigger("tf-m-cppcheck")