4

I'm trying to queue a build using the REST API with on-premises TFS 2015.2 using PowerShell.

$body @{ id = 1 }

Invoke-RestMethod -Method Post -Credential "myusername" -ContentType application/json -Uri "https://{tfsurl}/DefaultCollection/Fabrikam-Fiber-Git/_apis/build/builds?api-version=2.0" -Body (ConvertTo-Json $body)

It throws an error that it needs the definition which needs to be in the JSON. PowerShell doesn't like this, so am I missing a simple syntax error?

$body = @{
"definition": {
    "id":1
 }
}

I saw this post: How to trigger a build in TFS 2015 using REST API but I don't think it helps much with the PowerShell side of it.

Community
  • 1
  • 1
m00nbeam360.0
  • 1,342
  • 1
  • 13
  • 26

1 Answers1

6

This will give you the JSON you need:

$body = @{ definition = @{id = 1} }
JamesQMurphy
  • 4,214
  • 1
  • 36
  • 41