Search code examples
azurepowershellazure-devopsazure-rest-api

Why can't i delete iteration from the board?


I use a powershell script to call the azure rest api and add new iterations and delete the three basic iteration.

For the api it work, if i get the list of iterations Iteration 1 to 3 are deleted, however if i go to the GUI there are still here :enter image description here

Did i miss something ?

Code

function deleteIteration {
    [CmdletBinding()] param ( 
        [Parameter( Mandatory )] [string]    $organization,
        [Parameter( Mandatory )] [string]    $project,
        [Parameter( Mandatory )] [string]    $iteration,
        [Parameter( Mandatory )] [hashtable] $header
    )

    try {

        [string] $team        = getMainTeamName -organization $organization -project $project
        [string] $iterationId = getIterationId -organization $organization -project $project -iteration $iteration -team $team -header $header
        [string] $uri         = "$url/{0}/{1}/{2}/_apis/work/teamsettings/iterations/{3}?{4}" -f $organization, $project, $team, $iterationId, $apiVersion
        [Object] $query       = Invoke-RestMethod -Uri $uri -Method Delete -Headers $header

        Write-Host "- Iteration $iteration has been deleted !"

    } catch {
        Write-Host "##[error] An error occurred while deleting Iteration $name at $uri."
        Get-Error
        throw
    }
}

Solution

  • From your screenshot, you need to delete the iteration in the Project Settings -> Project Configuration -> Itertaions (Project Level).

    For example:

    enter image description here

    When you use the Rest API:Iterations - Delete, it will delete the iteration at Team level(Project Settings -> Team Configuration -> Itertaions).

    For example:

    enter image description here

    It will not delete the iteration at the Project Level.

    To solve this issue, you need change to use the Rest API: Classification Nodes - Delete

    DELETE https://dev.azure.com/{organization}/{project}/_apis/wit/classificationnodes/{structureGroup}/{path}?api-version=5.1
    

    structureGroup: iterations

    path: Iteration name(e.g. Iteration 1, Iteration 2,Iteration 3)

    For example:

    https://dev.azure.com/{organization}/{project}/_apis/wit/classificationnodes/iterations/Iteration 1?api-version=5.1
    

    Then it will delete the iteration at project level.