Get-TFSBuildDefinitions.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Author: Miodrag Milic <miodrag.milic@gmail.com>
# Last Change: 26-Apr-2016.

<#
.SYNOPSIS
    Get the TFS build definitions
#>

function Get-TFSBuildDefinitions {
    [CmdletBinding()]
    param (
        #Filters to definitions whose names start with this value. Globs supported.
        [string]$Name
    )
    check_credential

    if ($Name) { $q_name = 'name=' + $Name + '&' }
    $uri = "$proj_uri/_apis/build/definitions?$($q_name)api-version=" + $global:tfs.api_version
    Write-Verbose "URI: $uri"

    $params = @{ Uri = $uri; Method = 'Get'}
    $r = invoke_rest $params

    $list = @()
    foreach ($r in $r.value) {
        $b = [pscustomobject]@{
            Raw      = $r
            Id       = $r.id
            Name     = $r.name
            Revision = $r.revision
            Author   = $r.authoredBy.displayname
            EditUrl  = "$proj_uri/_build#definitionId=" + $r.id + "&_a=simple-process"
        }
        $b.PSObject.TypeNames.Insert(0,'TFS.Definition')
        $list += $b
    }

    $list
}

sal defs Get-TFSBuildDefinitions