engine: Create openstack release jobs
[infra/cicd.git] / jjb / cloud-infra / delete-heat-stack.sh
index 2bd6c732a10675b8a1ba947b78b728d2279506fb..efec47b77b0af7f076304a79e25d4c9dec599618 100644 (file)
@@ -29,6 +29,7 @@ if [[ $DEPLOY_TYPE != "cloud" ]]; then
   exit 0
 fi
 
+# do not delete the stack if not explicitly set to delete
 if [[ "$DELETE_STACK" != "yes" ]]; then
   echo "-------------------------------------------------------------------------"
   echo "Info: Stack will not be deleted upon the completion of the job!"
@@ -36,6 +37,14 @@ if [[ "$DELETE_STACK" != "yes" ]]; then
   exit 0
 fi
 
+# k8s and onap scenario have stacks so exit for others
+if [[ ! "$DEPLOY_SCENARIO" =~ ^k8-.*|^onap-.* ]]; then
+  echo "-------------------------------------------------------------------------"
+  echo "Info: Nothing to delete!"
+  echo "-------------------------------------------------------------------------"
+  exit 0
+fi
+
 echo
 echo
 echo "-------------------------------------------------------------------------"
@@ -51,11 +60,12 @@ set +u
 source $WORKSPACE/.venv/bin/activate
 set -u
 pip install -q openstacksdk python-openstackclient python-heatclient
-echo "Info: Deleting stack $STACK_NAME"
+echo "Info: Deleting stack $STACK_NAME and keypair $KEYPAIR_NAME"
 echo "-------------------------------------------------------------------------"
 source /tmp/openrc && /bin/rm -f /tmp/openrc
 openstack stack delete $STACK_NAME --wait --yes
+openstack keypair delete $KEYPAIR_NAME
 echo "-------------------------------------------------------------------------"
-echo "Info: Stack $STACK_NAME has been deleted!"
+echo "Info: Stack $STACK_NAME and keypair $KEYPAIR_NAME have been deleted!"
 
 # vim: set ts=2 sw=2 expandtab: