New-TFSBuildDefinition.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
# Author: Miodrag Milic <miodrag.milic@gmail.com>
# Last Change: 26-Apr-2016.

<#
.SYNOPSIS
    Create/import build definition
.EXAMPLE
    New-BuildDefinition -JsonFile BuildXYZ.json
 
    Create a new build definition using the data in the JSON file 'BuildXYZ.json'
#>

function New-TFSBuildDefinition {
    [CmdletBinding()]
    param (
        #File that contains json description of the build
        [string] $JsonFile
    )
    check_credential

    if (!(Test-Path $JsonFile)) {throw "File doesn't exist: $JsonFile" }

    $uri = "$proj_uri/_apis/build/definitions?api-version=" + $global:tfs.api_version
    Write-Verbose "URI: $uri"

    $body = gc $JsonFile -Raw -ea Stop
    $params = @{ Uri = $uri; Method = 'Post'; Body = $body; ContentType = 'application/json' }
    invoke_rest $params
}