Skip to content

Instantly share code, notes, and snippets.

@bizouarn
Last active October 9, 2024 20:47
Show Gist options
  • Save bizouarn/57ea932e51a7a246959fdc6558970a77 to your computer and use it in GitHub Desktop.
Save bizouarn/57ea932e51a7a246959fdc6558970a77 to your computer and use it in GitHub Desktop.
Script bash pour supprimer tous les pipelines gitlab pour un projet antérieur a une date donnée
#!/bin/bash
##################################################################
# Configuration des variables
GITLABURL="https://gitlab.com"
ACCESSTOKEN="glpat-XXXXXXXXXXX" # Token d'accès API
DELETEBEFORE="2020-01-01" # Date limite pour la suppression
PROJECTID="00000" # ID du projet
##################################################################
# Fonction pour récupérer les ID des pipelines à supprimer
get_pipeline_ids() {
curl --header "PRIVATE-TOKEN: $ACCESSTOKEN" "$GITLABURL/api/v4/projects/$PROJECTID/pipelines?per_page=100&order_by=updated_at&sort=desc&updated_before=${DELETEBEFORE}T23:01:00.000Z" 2> /dev/null | jq -r '.[] | .id'
}
COUNTER=1
# Boucle principale pour supprimer les pipelines
while true; do
pipeline_array=( $(get_pipeline_ids) )
[[ ${#pipeline_array[@]} -eq 0 ]] && break # Sortir si aucun pipeline à supprimer
echo -e "---\nTask $COUNTER: Project ID:$PROJECTID has ${#pipeline_array[@]} pipelines to delete."
for pipelineid in "${pipeline_array[@]}"; do
echo "Deleting pipeline ID: ${pipelineid}"
curl --header "PRIVATE-TOKEN: $ACCESSTOKEN" --request "DELETE" "$GITLABURL/api/v4/projects/$PROJECTID/pipelines/$pipelineid" # Décommenter pour activer la suppression
done
COUNTER=$((COUNTER + 1))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment