1

I am able to schedule the release using Rest API call . Is there any way to Queue it to run Multiple times.THe code i tried is given below.

$timinglist=@(1:30,2:30,3:30)

foreach($time in $timinglist)
 {
    $PATtoken= 'PAT'
    Write-Host "Initialize Autnetication COntext" -ForegroundColor DarkBlue
    $token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($PATtoken)"))
    $header=@{authorization= "Basic $token" }

    $defurl = "https://vsrm.dev.azure.com/Organization/Project/_apis/release/definitions/13?api-version=5.1" 


   $definition = Invoke-RestMethod -Uri $defurl -Method Get -Headers $header
   $hour=$time.Split(":")[0]
   $minute=$time.Split(":")[1]

   $hash = @(
   @{ 
      triggerType="schedule";
      schedule = @{"daysToRelease"="31";"timeZoneId"="India Standard Time";"startHours"=$hour;"startMinutes"=$minute}
   })
   $definition.triggers = $hash     

   $json = @($definition) | ConvertTo-Json -Depth 99 

   $updatedef = Invoke-RestMethod  -Uri $defurl  -Method Put -Body $json -ContentType "application/json" -Headers $header
   Write-Host ($updatedef.triggers | ConvertTo-Json -Depth 99)
}

My objective is to queue a release at 1:30 2:30 and 3:30 . But with the above code it is running only at 3:30 and other two are not happening.

Lorenzo Isidori
  • 1,809
  • 2
  • 20
  • 31
mystack
  • 4,910
  • 10
  • 44
  • 75

1 Answers1

1

You are overriding the triggers property every time you send the request. So the last value wins over the old ones.

triggers property is an array of BuildTrigger, you don't need to execute 3 request, just one! This is the triggers documentation.

EDIT:

I am not a powershell wizard but you should create an array of BuildTrigger object like this:

$hash = @(
   @{ 
      triggerType="schedule";
      schedule = @{"daysToRelease"="31";"timeZoneId"="India Standard Time";"startHours"=$hour1;"startMinutes"=$minute1}
   },
   @{ 
      triggerType="schedule";
      schedule = @{"daysToRelease"="31";"timeZoneId"="India Standard Time";"startHours"=$hour2;"startMinutes"=$minute2}
   },
   @{ 
      triggerType="schedule";
      schedule = @{"daysToRelease"="31";"timeZoneId"="India Standard Time";"startHours"=$hour3;"startMinutes"=$minute3}
   }
   )
Lorenzo Isidori
  • 1,809
  • 2
  • 20
  • 31
  • But how to specify that array in the above powershell script – mystack Nov 27 '19 at 11:49
  • 1
    This is another question, but I tried to answer as well as I can. I edited the answer adding the array creation. – Lorenzo Isidori Nov 27 '19 at 11:56
  • Added a new question please check whether you also came through it https://stackoverflow.com/questions/59087121/schedule-a-azure-devops-release-in-multiple-timing-by-passing-different-variable – mystack Nov 28 '19 at 12:04