Schedule a Azure devops release in multiple timings

北战南征 提交于 2019-12-08 04:43:34

问题


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.


回答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}
   }
   )


来源:https://stackoverflow.com/questions/59068766/schedule-a-azure-devops-release-in-multiple-timings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!