How to undelete a deleted release definition?

We (Garima Srivastava) have recently added a feature in the product with which you can undelete a release definitions yourself using our rest APIs. This undelete can be done within 4 weeks of deletion and after which the definition is deleted permanently. Here is a sample power-shell script which uses our rest APIs to find the deleted definitions and then undeletes one of them.

param (
[string] $token
## Construct a basic auth head using PAT
function BasicAuthHeader()
$ba = (":{0}" -f $authtoken)
$ba = [System.Text.Encoding]::UTF8.GetBytes($ba)
$ba = [System.Convert]::ToBase64String($ba)
$h = @{Authorization=("Basic{0}" -f $ba);ContentType="application/json"}
return $h

# Fill in your account name/project name/definition name
$accountName = "aseemb"
$projectName = "dockerConf"
$definitionNameToRecover = "New Release Definition"

# Find the Id of release definition that got deleted
$deletedReleaseDefinitionsUri = "https://$$projectName/_apis/Release/definitions?api-version=4.0-preview.3&isDeleted=true&searchText=$definitionNameToRecover"
$h = BasicAuthHeader $token
$deletedDefinitions = Invoke-RestMethod -Uri $deletedReleaseDefinitionsUri -Headers $h -ContentType “application/json" -Method Get
$deletedDefinitionJSON = $deletedDefinitions | ConvertTo-Json -Depth 100
write-host "Found the deleted definitions : $deletedDefinitions"
$deletedReleaseDefinitionId = $deletedDefinitions.Value[0].id
write-host "Found the deleted id : $deletedReleaseDefinitionId "

# Recover the deleted release definition
$undeleteReason = '{ "Comment" : "Deleted by mistake" }'
$undeleteReleaseDefinitionUri = "https://$$projectName/_apis/Release/definitions/$deletedReleaseDefinitionId`?api-version=4.0-preview.3"
$undeletedDefinition = Invoke-RestMethod -Uri $undeleteReleaseDefinitionUri -Headers $h -ContentType “application/json" -Method Patch -Body $undeleteReason
$name = $
write-host "$name recovered successfully"

Please try it out and do let us know in case it does not work for you !!

Note: - This functionality will not be exposed in the UI at-least for next 6 months or so as we are rewriting the RM landing pages UI.

Comments (0)

Skip to main content