allow repository configuration

- for system test, allow using local repository
Change-Id: I7d8882ac501c58853fb9b4a1494b54708d1d2aec
Signed-off-by: Mike Marchetti <mmarchetti@sandvine.com>
diff --git a/jenkins/system/Jenkinsfile b/jenkins/system/Jenkinsfile
index d3688c4..c3dcc0a 100644
--- a/jenkins/system/Jenkinsfile
+++ b/jenkins/system/Jenkinsfile
@@ -1,7 +1,13 @@
 // input parameters:
 //   boolean: BUILD_FROM_SOURCE
+//   boolean: REPO_DISTRO
 //   boolean: COMMIT_ID
+//   boolean: UPSTREAM_SUFFIX
 //   string:  NODE
+//   string: RSYNC_DESTINATION
+//   string: REPO_BASE_URL
+//   string: REPO_KEY_NAME
+//   string: RELEASE
 
 node("${params.NODE}") {
 
@@ -11,6 +17,42 @@
         container_name = "${container_name_prefix}-${BUILD_NUMBER}"
     }
 
+    stage("Checkout") {
+        checkout scm
+    }
+
+    // Copy the artifacts from the upstream jobs
+    stage("Copy Artifacts") {
+        // cleanup any previous repo
+        sh 'rm -rf repo'
+
+        dir('repo') {
+            // grab all stable upstream builds based on the
+            // given target UPSTREAM_SUFFIX
+
+            def list = ["SO", "UI", "RO", "openvim", "osmclient"]
+            for (component in list) {
+                step ([$class: 'CopyArtifact',
+                       projectName: "${component}_${params.UPSTREAM_SUFFIX}"])
+                sh "dpkg-sig --sign builder -k dpkg1 pool/${component}/*"
+                // cleanup any prevously defined dists
+                sh "rm -rf dists"
+            }
+
+            // now create the distro
+            for (component in list) {
+                sh "mkdir -p dists/${params.REPO_DISTRO}/${component}/binary-amd64/"
+                sh "apt-ftparchive packages pool/${component} > dists/${params.REPO_DISTRO}/${component}/binary-amd64/Packages"
+                sh "gzip -9fk dists/${params.REPO_DISTRO}/${component}/binary-amd64/Packages"
+            }
+
+            // create and sign the release file
+            sh "apt-ftparchive release dists/${params.REPO_DISTRO} > dists/${params.REPO_DISTRO}/Release"
+            sh "gpg --yes -abs -u dpkg1 -o dists/${params.REPO_DISTRO}/Release.gpg dists/${params.REPO_DISTRO}/Release"
+            sh "rsync -avz . ${params.RSYNC_DESTINATION}/${params.RELEASE}"
+        }
+    }
+
     stage("Cleanup") {
         // check for previous containers and clean them up
         sh "jenkins/system/delete_old_containers.sh ${container_name_prefix}"
@@ -22,9 +64,22 @@
         {
             from_source = '--source'
         }
+ 
+        sh """
+            export OSM_USE_LOCAL_DEVOPS=true
+            jenkins/host/start_build system --build-container ${container_name} \
+                                            -b ${params.COMMIT_ID} \
+                                            -r ${params.REPO_DISTRO} \
+                                            -u ${params.REPO_BASE_URL} \
+                                            -k ${params.REPO_KEY_NAME} \
+                                            -R ${params.RELEASE} \
+                                            ${from_source}
+           """
+    }
 
-        sh "jenkins/host/start_build system --build-container ${container_name} -b ${params.COMMIT_ID} ${from_source}"
+    stage("Archive Artifacts") {
         sh "echo ${container_name} > build_version.txt"
-        archiveArtifacts artifacts: "build_version.txt"
+        sh "tar -zcvf repo.tar.gz repo"
+        archiveArtifacts artifacts: "build_version.txt, repo.tar.gz"
     }
 }
diff --git a/jenkins/system/start_build b/jenkins/system/start_build
index a50a5a8..7f259c7 100755
--- a/jenkins/system/start_build
+++ b/jenkins/system/start_build
@@ -57,7 +57,8 @@
 git clone https://osm.etsi.org/gerrit/osm/osmclient
 pip install osmclient/.
 
-devops/installers/install_osm.sh $*
+export OSM_USE_LOCAL_DEVOPS=true
+devops/installers/install_osm.sh --test $*
 RC=$?
 
 # workaround.  for upload packages, lxdbr0 needs to be promiscuous