Schedule a Azure devops release in multiple timing

2020-05-01 08:37发布

问题:

I am able to schedule a release in multiple timing by using below script

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

       $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


   $hash = @(
           @{ 
            triggerType="schedule";
            schedule = @{"daysToRelease"="31";"timeZoneId"="India Standard Time";"startHours"=01;"startMinutes"=30}
  }),
  @{ 
            triggerType="schedule";
            schedule = @{"daysToRelease"="31";"timeZoneId"="India Standard Time";"startHours"=02;"startMinutes"=30}
  }),
  @{ 
            triggerType="schedule";
            schedule = @{"daysToRelease"="31";"timeZoneId"="India Standard Time";"startHours"=03;"startMinutes"=30}
  })
   $definition.triggers = $hash     
   $definition.variableGroups=@(10,11,12)
   $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)

I am able to pass the variable group as $definition.variableGroups=@(10,11,12) . SO here the Variable group 10,11 and 12 will get pass through each of the three releases.But i want to pass the only variable group 10 against release at 01:30 and Variable group 12 at 02:30 and 11 at 03:30. Is it possible

回答1:

You should use task groups, environments, and variable groups to accomplish this.

You define a task group that has the actions that you want to reuse.

You use that task groups in many different stages within a single release. Each release stage can be tied to a different task group. Then you just call the REST API to trigger a deployment of the correct stage.