How to delete Bamboo projects and plans in bulk using REST API
プラットフォームについて: Server および Data Center のみ。この記事は、Server および Data Center プラットフォームのアトラシアン製品にのみ適用されます。
Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Fisheye および Crucible は除く
本記事で説明している手順は、現時点でのものとなります。そのため、一部のお客様で特定の状況下で動作したという報告がありますが、正式にサポートされているわけではなく、お客様の特定のシナリオで動作することを保証するものではありません。
本番環境での実施の前に一通り非本番環境で検証し、成功しなかった場合にはサポートされている代替案にフォール バックしてください。
要約
This article outlines the process to delete Bamboo projects and plans in bulk using REST API.
環境
This has been tested on Bamboo 8.0.9 but likely works with other versions as well.
ソリューション
To delete the Projects in bulk via REST API we need to execute the API call in a script. You can put the Project_Key is a file say PROJECT_KEY, then read the file line by line and call the API against each line:
#!/bin/bash
input="/<PATH>/PROJECT_KEY.txt"
username="admin"
password="****"
######################################
# Script to remove projects(empty ones) in bulk #
#####################################
while read -r line
do
echo "$line"
curl -k -u "$username:$password" -X DELETE --url https://<BAMBOO_URL>/bamboo/rest/api/latest/project/$line
done < "$input"
********************
Example contents of the file PROJECT_KEY.txt
cat PROJECT_KEY.txt
PROJ1
PROJ2
PROJ3
PROJ4
The below script is to remove plans in bulk via REST API. PLAN_KEY file should have the list of the planKeys, e.g PROJ-PLAN:
#!/bin/bash
input="/<PATH>/PROJ_KEY-PLAN_KEY.txt"
username="admin"
password="****"
######################################
# Script to remove plans in bulk #
#####################################
while read -r line
do
echo "$line"
curl -u "$username:$password" -X DELETE --url 'http://<BAMBOO_URL>/rest/api/latest/plan/$line'
done < "$input"
********************
Example contents of the file PROJ_KEY-PLAN_KEY.txt
cat PROJ_KEY-PLAN_KEY.txt
PROJ1-PLAN1
PROJ2-PLAN2
PROJ3-PLAN3
PROJ4-PLAN4
Please make sure you have a backup in place before you run the REST API to delete, this might be required in case of rollback.
Kindly make sure to test these REST APIs in a test environment before running them in production to eliminate any risk.