sonarqubesonarqube-web

SonarQube - Is it possible to delete multiple project analyses?


V9.9.3 - Enterprise Edition

I'm trying to delete multiple Project analyses by passing multiple keys in a single call to /api/project_analyses/delete, but it seems like only one analysis is getting deleted per call

The documentation seems a bit unclear, is there no way to delete multiple project analyses with a single SonarQube Web API call or am I doing something wrong?

Thanks!


Solution

  • You can't delete multiple project analyzes at once, but you can make a little script to do your work:

    like this:

    import requests
    
    sonar_url = "http://your-sonar-server/api/ce/"  # Replace with your server URL
    auth = ("username", "your_api_token")  # Replace with your credentials
    
    project_keys = ["project1", "project2", "project3"]  # List of projects to delete
    
    for project_key in project_keys:
        endpoint = f"projects/{project_key}/analyses"
        response = requests.delete(sonar_url + endpoint, auth=auth)
    
        if response.status_code == 204:
            print(f"Analysis for {project_key} deleted successfully.")
        else:
            print(f"Failed to delete analysis for {project_key}: {response.text}")