From 67c089cd563e497aaa663ad8cb734e23cdbaa3d5 Mon Sep 17 00:00:00 2001
From: Raphael Defosseux <raphael.defosseux@eurecom.fr>
Date: Wed, 26 Sep 2018 16:10:49 +0200
Subject: [PATCH] CI: adding support for lockeable resources

Signed-off-by: Raphael Defosseux <raphael.defosseux@eurecom.fr>
---
 ci-scripts/Jenkinsfile-tmp-ran | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/ci-scripts/Jenkinsfile-tmp-ran b/ci-scripts/Jenkinsfile-tmp-ran
index 4db4ec0b2d..1277e0d483 100644
--- a/ci-scripts/Jenkinsfile-tmp-ran
+++ b/ci-scripts/Jenkinsfile-tmp-ran
@@ -31,6 +31,9 @@ def testXMLFile = params.pythonTestXmlFile
 // Name of the test stage
 def testStageName = params.pipelineTestStageName
 
+// Name of the phone resource
+def ciSmartPhoneResource = params.smartphonesResource
+
 // Terminate Status
 def termUE = 0
 def termENB = 1
@@ -70,6 +73,7 @@ pipeline {
         string(name: 'pythonTestXmlFile', defaultValue: 'enb_usrpB210_band7_50PRB.xml', description: 'Location of the Test XML to be run')
         string(name: 'pipelineTestStageName', defaultValue: 'Test COTS-UE - OAI eNB - LTEBOX EPC', description: 'Naming of the Test Stage')
         booleanParam(name: 'pipelineZipsConsoleLog', defaultValue: 'True', description: 'If true, the pipeline script retrieves the job console log, zips it and archives it as artifact')
+        string(name: 'smartphonesResource', defaultValue: 'CI-Bench-1-Phones', description: 'Lockeable Resource to prevent multiple jobs to run simultaneously with the same resource')
 
         //eNB parameters
         string(name: 'eNB_IPAddress', defaultValue: '192.168.XX.XX', description: 'IP Address of eNB')
@@ -112,6 +116,9 @@ pipeline {
                         testStageName = 'Template Test Stage'
                     }
 
+                    if (params.smartphonesResource == null) {
+                        allParametersPresent = false
+                    }
                     if (params.eNB_IPAddress == null) {
                         allParametersPresent = false
                     }
@@ -178,6 +185,7 @@ pipeline {
             steps {
                 script {
                     dir ('ci-scripts') {
+                      lock (ciSmartPhoneResource) {
                         try {
                             echo "\u2705 \u001B[32m${testStageName}\u001B[0m"
                             withCredentials([
@@ -190,6 +198,7 @@ pipeline {
                         } catch (Exception e) {
                             currentBuild.result = 'FAILURE'
                         }
+                      }
                     }
                 }
             }
-- 
2.26.2