How to delete gitlab CI jobs pipelines logs/builds and history
Mass deletion script fixed for the lazy, delete X pipelines from the oldest (Linux systems).
Note: need jq.
#!/bin/bash
set -e
TOKEN="__SET_YOUR_PERSONAL_ACCESS_TOKEN__"
# Visible under name of project page.
PROJECT_ID="__SET_NUMERIC_PROJECT_ID__"
# Set your gitlab instance url.
GITLAB_INSTANCE="https://gitlab.com/api/v4/projects"
# How many to delete from the oldest, 100 is the maximum, above will just remove 100.
PER_PAGE=100
for PIPELINE in $(curl --header "PRIVATE-TOKEN: $TOKEN" "$GITLAB_INSTANCE/$PROJECT_ID/pipelines?per_page=$PER_PAGE&sort=asc" | jq '.[].id') ; do
echo "Deleting pipeline $PIPELINE"
curl --header "PRIVATE-TOKEN: $TOKEN" --request "DELETE" "$GITLAB_INSTANCE/$PROJECT_ID/pipelines/$PIPELINE"
done
UPDATE
As of Gitlab Release 12.6, deleting a pipeline is now an option in the GUI for owners:
- Click the pipeline you want to remove in the pipelines list
- Hit the red Delete button in the upper right of the pipeline details page.
As of Gitlab Release 11.6, deleting a pipeline is now an option, for maintainers only, via the API.
You need:
- An API token
- The
id
of the project - The
pipeline_id
of the pipeline you wish to remove.
Example using curl from the docs for project id: 1
and pipeline_id: 4
:
curl --header "PRIVATE-TOKEN: <your_access_token>" --request "DELETE" "https://gitlab.example.com/api/v4/projects/1/pipelines/46"
Documentation is here