delete_branch_jobs.sh 814 B

1234567891011121314151617181920212223242526
  1. #!/usr/bin/env bash
  2. set -e
  3. if [ "$#" -ne 1 ]; then
  4. printf 'Usage: %s <branch> \n' "$(basename "$0")"
  5. exit 0;
  6. fi
  7. BRANCH="$1"
  8. if [ -z "${JENKINS_USERNAME}" ] || [ -z "${JENKINS_TOKEN}" ]; then
  9. echo "You must set JENKINS_USERNAME and JENKINS_TOKEN environment variables."
  10. exit 1;
  11. fi
  12. echo "Deleting Jenkins jobs..."
  13. curl -s https://elasticsearch-ci.elastic.co/api/json \
  14. | jq -r ".jobs | .[] | select(.name | startswith(\"elastic+elasticsearch+${BRANCH}\")) | .url" \
  15. | xargs -L 1 curl -u $JENKINS_USERNAME:$JENKINS_TOKEN -X DELETE
  16. echo "Deleting views..."
  17. curl -s https://elasticsearch-ci.elastic.co/api/json \
  18. | jq -r ".views | .[] | select(.name == \"Elasticsearch ${BRANCH}\") | .url" \
  19. | xargs -L 1 -I '{}' curl -u $JENKINS_USERNAME:$JENKINS_TOKEN -X POST "{}/doDelete"
  20. echo "Done."