#!/bin/bash -exu

function main() {
  local raw_deployments
  set +x
  raw_deployments=$(curl -sk https://${BOSH_USER}:${BOSH_PASSWORD}@${BOSH_DIRECTOR}:25555/deployments)
  set -x

  local deployments
  deployments=$(echo "${raw_deployments}" | jq 'map(select(.name | contains('\"${DEPLOYMENTS_WITH_WORD}\"')))' | jq .[].name)

  if [ -n "${deployments}" ]
  then
    echo "${deployments}" | xargs -n 1 -P 5  bosh -t "${BOSH_DIRECTOR}" -n delete deployment
  fi

  echo "cleaning up orphaned disks and releases"
  bosh -t "${BOSH_DIRECTOR}" cleanup
}

main

#!/bin/bash -exu

function main() {
  local raw_deployments
  set +x
  raw_deployments=$(curl -sk https://${BOSH_USER}:${BOSH_PASSWORD}@${BOSH_DIRECTOR}:25555/deployments)
  set -x

  local deployments
  deployments=$(echo "${raw_deployments}" | jq 'map(select(.name | contains('\"${DEPLOYMENTS_WITH_WORD}\"')))' | jq .[].name)

  if [ -n "${deployments}" ]
  then
    echo "${deployments}" | xargs -n 1 -P 5  bosh -t "${BOSH_DIRECTOR}" -n delete deployment --force
  fi

  echo "cleaning up orphaned disks and releases"
  bosh -t "${BOSH_DIRECTOR}" cleanup
}

main

Add force flag to delete deployments
Add force flag to delete deployments

Signed-off-by: Angela Chin <09c3fe443cd90255b3ab6945ab331bb5cdf11ccb@pivotal.io>
