Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Backup TFS 2013 release 3 build and release definitions
function Backup-TFSReleaseDefinitions
{
param([object]$tfsprojs,$tfsurl = 'mytfsinstance.com', $tfscollection = 'Defaultcollection', $apiversion = '3.0-preview',[string]$Path = 'c:\temp\tfsprojects')
$tfsInstance = "http://$($tfsurl):8080/tfs/$tfsCollection"
foreach($tfsproj in $tfsprojs.value)
{
$tfsProjName = $tfsproj.name
$tfsdev = "$tfsInstance/$tfsProjName"
$projectIds = Invoke-RestMethod -Method Get -UseDefaultCredentials -uri "$tfsdev/_apis/release/definitions?api-version=$apiversion" -ContentType application/json
foreach($projectid in $projectIds)
{
$relnumber = $projectid.value.id
foreach($rel in $relnumber)
{
$relDef = invoke-restmethod -method get -UseDefaultCredentials -uri "$tfsdev/_apis/release/definitions/$($rel)?api-version=$apiversion" -ContentType application/json
$exportPath = "$path/$tfsProjName"
if(-not (test-path $exportPath))
{
mkdir $exportPath
}
$jsonDoc = $reldef | convertto-json -Depth 100
$jsonDoc | out-file -FilePath "$exportPath\$($reldef.name).json"
}
}
}
}
<#
.Synopsis
Gets all the TFS projects for a given instance
.EXAMPLE
$tfsProjects = get-TFSProjects -tfsurl 'http://yourinstance.com:8080/tfs/Defaultcollection'
.OUTPUTS
Returns an object of projects found in tfs.
count value
----- -----
19 {@{id=f7039238-b489-45d1-b9d1-c4c9222497c3; name=Marketing; url=http://yourinstance.com:8080/tfs/DefaultCollection/_apis/projects/[guid]; state=wellFormed; revisi...
#>
function Get-TFSProjects
{
Param($tfsUrl,$apiversion = '3.0-preview')
Invoke-RestMethod -method get -UseDefaultCredentials -uri "$tfsurl/_apis/projects?api-version=$apiversion"
}
function Backup-TFSbuildDefinitions
{
param([object]$tfsprojs,$tfsurl = 'mytfsinstance.com', $tfscollection = 'Defaultcollection', $apiversion = '3.0-preview',[string]$Path = 'c:\temp\tfsbuilds')
#"$Uri/$DefaultCollection/$TeamProject/_apis/build/definitions?api-version=2.0&name=$buildName"
$tfsInstance = "http://$($tfsurl):8080/tfs/$tfsCollection"
foreach($tfsproj in $tfsprojs.value)
{
$tfsProjName = $tfsproj.name
$tfsdev = "$tfsInstance/$tfsProjName"
$projectIds = Invoke-RestMethod -Method Get -UseDefaultCredentials -uri "$tfsdev/_apis/build/definitions?api-version=$apiversion" -ContentType application/json
foreach($projectid in $projectIds)
{
$relnumber = $projectid.value.id
foreach($rel in $relnumber)
{
$relDef = invoke-restmethod -method get -UseDefaultCredentials -uri "$tfsdev/_apis/build/definitions/$($rel)?api-version=$apiversion" -ContentType application/json
$exportPath = "$path/$tfsProjName"
if(-not (test-path $exportPath))
{
mkdir $exportPath
}
$jsonDoc = $reldef | convertto-json -Depth 100
$jsonDoc | out-file -FilePath "$exportPath\$($reldef.name).json"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment