Created
February 9, 2022 20:57
-
-
Save abhi2495/19082f4f1550864bef2846bf8adac620 to your computer and use it in GitHub Desktop.
Shell Script to delete a bunch of blackduck versions for a given project id
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env bash | |
blackduckHostName="${1}" | |
blackduckApiKey="${2}" | |
blackduckProjectId="${3}" | |
BEARER_TOKEN_RESPONSE=$(curl -X POST -H "Content-Length: 0" -H "Authorization: token $blackduckApiKey" "$blackduckHostName/api/tokens/authenticate") | |
BEARER_TOKEN=$(echo $BEARER_TOKEN_RESPONSE | jq -r '.bearerToken') | |
PROJECT_VERSIONS_LIST_RESPONSE=$(curl -X GET -H "Authorization: Bearer $BEARER_TOKEN" "$blackduckHostName/api/projects/$blackduckProjectId/versions?limit=100") | |
PROJECT_VERSION_ENDPOINTS=($(echo $PROJECT_VERSIONS_LIST_RESPONSE | jq -r '.items[] | select(.versionName != "develop" and .versionName != "release") | ._meta.href')) | |
echo "Array size: " ${#PROJECT_VERSION_ENDPOINTS[@]} | |
for endpoint in "${PROJECT_VERSION_ENDPOINTS[@]}"; do | |
# echo "Calling the following project version endpoint to delete:-$endpoint." | |
if [ $endpoint == "null" ]; then | |
echo "Project version not found for current project. Skipping delete." | |
else | |
# echo "Deleting project version" | |
curl -X DELETE -H "Authorization: Bearer $BEARER_TOKEN" $endpoint | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment