X-Git-Url: https://gerrit.nordix.org/gitweb?a=blobdiff_plain;f=jjb%2Finfra%2Fupdate-jenkins-slave.sh;h=1fe6202090eff9d2d54767e8eb6de0763d7b47ef;hb=5cf65a445216d41d604e4e108393604ca12336b7;hp=9473aae00d7e794bcda484c6946217c41a9287ac;hpb=4a53085dc39a73709a189a77f0b6350f302a4943;p=infra%2Fcicd.git diff --git a/jjb/infra/update-jenkins-slave.sh b/jjb/infra/update-jenkins-slave.sh index 9473aae0..1fe62020 100644 --- a/jjb/infra/update-jenkins-slave.sh +++ b/jjb/infra/update-jenkins-slave.sh @@ -3,7 +3,21 @@ set -o errexit set -o nounset set -o pipefail -sudo apt install -y -q=3 python3-minimal python3-pip virtualenv +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.8-minimal python3-pip virtualenv # workaround for https://github.com/pypa/virtualenv/issues/1029 export PS1=${PS1:-} @@ -11,7 +25,7 @@ export PS1=${PS1:-} cd "$WORKSPACE" echo "----------------------------------------------------" echo "Info: Create virtualenv to update Jenkins slaves" -virtualenv -p python3 --quiet --no-site-packages .venv +virtualenv -p python3.8 --quiet --no-site-packages .venv source .venv/bin/activate pip install python-openstackclient echo "----------------------------------------------------" @@ -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 "----------------------------------------------------"