I would like to add a schedule on a build definition taken from TFS REST API using PowerShell (add schedule to $buildDef variable on code example).
I get the build definition doing an API request but I'm not able to create a schedule for each week as trigger. I have used below Api for updating the trigger schedule.
$buildDef = Invoke-RestMethod -Method Get -UseDefaultCredentials -ContentType application/json -Uri $TfsBuildDefinitionUri
Any help would be appreciated as I am not able to get it done. Thanks!!
Finally I created / added an scheduled trigger to my build definition. When the build definition has not any trigger, the property (build object) or json array (build object convert to an array) doesn't exist. So, we've to add it. Here is the solution:
$triggerValue = @"
[
{
"schedules":[
{
"branchFilters":[
"+$/FilterName"
],
"timeZoneId":"W. Europe Standard Time",
"startHours":$startHoursNB,
"startMinutes":$startMinutesNB,
"daysToBuild":"all"
}
],
"triggerType":"schedule"
}
]
"@
$buildDef | add-member -Name "triggers" -value (Convertfrom-Json $triggerValue) -MemberType NoteProperty
Thanks also for help.