Introduction
When managing JFrog Artifactory projects, it is sometimes necessary to unassign multiple repositories from a specific project. If the number of repositories is large, performing this action manually from the UI by clicking the delete option for each repository can be time-consuming and inefficient.
This KB article provides a script-based approach to unassign all repositories from a project quickly using JFrog REST API calls
Resolution
Since Unassign REST API allows unassigning a project from only one repository at a time, the following shell script automates the process for multiple repositories. The script retrieves the list of repositories assigned to the specified project and then iterates through the list and unassigns each repository from the project.
Steps:
Step 1: Create a file (e.g., unassign_repos.sh) and paste the following script:
#!/usr/bin/env bash
BASE_URL="https://<JFrog-URL>"
PROJECT_KEY="<project-key>" # Example: test
TOKEN="<Access_Token>" # Access token is required to execute the command
# Step 1: Get the list of repositories assigned to the project
repos=$(curl -s -H "Authorization: Bearer $TOKEN" \
"$BASE_URL/artifactory/api/repositories?project=$PROJECT_KEY" \
| jq -r '.[].key')
# Step 2: Unassign each repository
for repo in $repos; do
echo "Unassigning $repo..."
curl -s -o /dev/null -w "%{http_code}\n" \
-X DELETE "$BASE_URL/access/api/v1/projects/_/attach/repositories/$repo" \
-H "Authorization: Bearer $TOKEN"
done Step 2: Provide execute permissions to the file:
chmod +x unassign_repos.sh
Step 3: Run the script:
./unassign_repos.sh
The script will display HTTP status codes for each unassignment (e.g., 204 for success) as shown in the screenshot below.
Step 4: Once the script completes, we can verify in the JFrog UI that the repositories are no longer assigned to the project.