add ccsdk-sli-northbound
[infra/cicd.git] / jjb / infra / update-jenkins-slave.sh
index 9473aae00d7e794bcda484c6946217c41a9287ac..1b1a7c98fd998b2e9a49e869c74c7fb45546f78f 100644 (file)
@@ -3,6 +3,20 @@ set -o errexit
 set -o nounset
 set -o pipefail
 
+DPKG_LOCK="/var/lib/dpkg/lock-frontend"
+# Wait for other apt process to finish by checking the dpkg lock file.
+try=0
+while sudo lsof ${DPKG_LOCK}  > /dev/null 2>&1 ; do
+  echo "DPKG file locked: ${DPKG_LOCK}."
+  echo "   Waiting for another pkg instalaltion process to finish ..."
+  sleep 10
+  if [[ ${try} -gt 60 ]] ; then
+    echo "ERROR: Max number of re-tries reached, exiting..."
+    exit 1
+  fi
+  try=$((try + 1))
+done
+
 sudo apt install -y -q=3 python3-minimal python3-pip virtualenv
 
 # workaround for https://github.com/pypa/virtualenv/issues/1029
@@ -29,10 +43,14 @@ echo "----------------------------------------------------"
 echo "Info: Create backup of existing image"
 cd "$WORKSPACE"
 BACKUP_ZONE_ID=$(openstack image list --property name=${IMAGE} -f value -c ID)
-openstack image set --name "${IMAGE}-backup-$GIT_COMMIT" "$BACKUP_ZONE_ID"
+if [ -z ${BACKUP_ZONE_ID} ] ; then
+   echo "Warning: No previous image found to backup"
+else
+   openstack image set --name "${IMAGE}-backup-$GIT_COMMIT" "$BACKUP_ZONE_ID"
+fi
 echo "----------------------------------------------------"
 echo "Info: Updating the CI slave image"
 cd "infra/jenkins/slave-setup/${TARGET}/"
 packer validate *-ubuntu*.json
 packer build *-ubuntu*.json
-echo "----------------------------------------------------"
\ No newline at end of file
+echo "----------------------------------------------------"