在 Azure Devops 经典发布管道中,如何通过一次单击部署所有管道或使用作业触发所有发布管道 (Linux agnt

In Azure Devops Classic Release Pipelines, How can I deploy all pipelines with a single click oruse a job to trigger all release pipelines (Linux agnt

我在 ADO 中有多个经典发布管道,我想一次全部部署。市场中有一个自定义任务,但它不适用于 Linux 代理。我没有使用阶段。我创建了文件夹,每个文件夹中有 10 个管道。基本上每个文件夹都有创建一个包含所有 Infra 的新环境的管道。任何帮助表示赞赏。 提前致谢

In Azure Devops Classic Release Pipelines, How can I deploy all pipelines with a single click oruse a job to trigger all release pipelines (Linux agnt

更新:

I want to use only classic. An where shall i put this script. Should i create a new pipeline and add powershell task or for every pipeline shall i add this powershell task. sorry I am new to this

您可以通过 REST API 添加一个 PowerShell 任务来为不同的版本定义创建多个版本。

POST https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/releases?api-version=5.0

用于创建发行版的示例 powershell 脚本如下:

#Define the variable and enter the release definition id that you want to trigger. For example, I want to manually trigger release pipelines 1 and 2 at once.

$ReleaseDefinitionID = 1,2

ForEach ($ID in $ReleaseDefinitionID)
{
Write-host "ID is" $ID

$token = "pat"   
$url = "https://vsrm.dev.azure.com/{organization}/{project}/_apis/Release/releases?api-version=5.0"
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))


$JSON = @"
{
  "definitionId": $ID
}
"@

$response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic $token"} -Method Post -ContentType application/json -body $JSON

}

您可以使用 REST API create release rest api 部署新版本。

POST https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/releases?api-version=5.1

请参阅以下 powershell 脚本中的示例:

请参阅步骤 here 获取个人访问令牌 (PAT)。

$url = "https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/releases?api-version=5.1"

$PAT= "Personal access token"

$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($PAT)"))

$body= '{
    "definitionId": 3
    }'

$result=Invoke-RestMethod -Uri $url -Headers @{Authorization = ("Basic {0}" -f $base64AuthInfo)} -Method post -ContentType "application/json" -Body $body

此外,为了触发所有发布管道,您可以尝试使用参数创建 YAML 管道,例如:

Main.yaml 文件:

jobs:
  - template: TriggerReleases.yaml
    parameters: 
      listOfEnvs:
        - "29" #The Id of the release definition Id list.
        - "28"  
        - "27"

TriggerReleases.yaml:

parameters:
  - name: listOfEnvs
    type: object
    default: []


jobs:
- ${{ each env in parameters.listOfEnvs }}:
    - job: Queue_${{ env }}_job1
      pool:
        vmImage: 'windows-latest'
      steps: |
        # scripts to invoke REST API to trigger release pipeline.

您可以查看文档 Solving the looping problem in Azure DevOps Pipelines 了解更多详情。