使用 Azure PowerShell 或 AZ 命令我想检查是否执行了 Azure DevOps 发布管道?有没有可用的脚本?
Using Azure PowerShell or AZ commands I want to check if a Azure DevOps Release Pipeline is executed or not? Is there any script available for it?
我想在不登录 Azure DevOps 项目的情况下使用 PowerShell 验证发布管道是否已执行。如何测试这个?是否也可以使用 PowerShell 获取 Release 的输出,就像它成功或失败一样?
您可以使用 az 命令:
使用 pat (Sign in with a Personal Access Token (PAT)) 登录您的组织:
az devops login --organization https://dev.azure.com/org_name
-
az pipelines release definition list --org https://dev.azure.com/org_name -p ProjectName --output table
ID Name CreatedBy Created On
---- ------------------------ ----------------- --------------------------------
2 New release pipeline (3) UserName 2019-09-26T15:42:59.613000+00:00
3 New release pipeline UserName 2019-10-08T07:48:21.457000+00:00
4 New release pipeline (1) UserName 2019-11-19T19:04:40.523000+00:00
5 New release pipeline (2) UserName 2020-07-23T14:13:08.953000+00:00
-
az pipelines release list --definition-id 5 --org https://dev.azure.com/org_name -p ProjectName --output table
ID Name Definition Name Created By Created On Status Description
---- --------- ------------------------ ----------- -------------------------- -------- -------------
177 Release-6 New release pipeline (2) UserName 2020-12-22 19:28:06.610000 active Triggered by
176 Release-5 New release pipeline (2) UserName 2020-12-21 18:29:51.930000 active Triggered by
175 Release-4 New release pipeline (2) UserName 2020-12-18 12:52:04.610000 active Triggered by
174 Release-3 New release pipeline (2) UserName 2020-11-11 02:02:32.653000 active Triggered by
-
az pipelines release show --id 177 --org https://dev.azure.com/org_name -p ProjectName --output table
ID Name Definition Name Created By Created On Status Description
---- --------- ------------------------ ----------------- -------------------------- -------- -------------
177 Release-6 New release pipeline (2) UserName 2020-12-22 19:28:06.610000 active Triggered by
此外,您可以使用 --output
参数来获得 json 格式的结果,然后您将获得更详细的信息。
I want to validate if a Release Pipeline is executed or not using PowerShell without logging into the Azure DevOps project.
如果您想使用 PowerShell 验证发布管道是否已执行,以下脚本可以实现。
- Create a PAT with full scopes, and then use this Rest API: Definitions - List 列出所有发布管道。请参阅以下脚本。
$url = "https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/definitions?api-version=6.0"
$connectionToken="PAT Here" #input your PAT
$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($connectionToken)"))
$pipelines = Invoke-RestMethod -Uri $url -Headers @{authorization = "Basic $base64AuthInfo"} -Method Get
Write-Host "Pipeline = $($pipelines | ConvertTo-Json -Depth 100)" #list all release pieplines
- 您可以从上述响应中找到目标 发布管道的定义 ID 。然后使用此 Rest API: Releases – List 获取此发布管道的所有版本。请参阅以下脚本。
$new_url = https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/releases?definitionId={definitionId}&api-version=6.0
$releases = Invoke-RestMethod -Uri $new_url -Headers @{authorization = "Basic $base64AuthInfo"} -Method Get
Write-Host "releases = $($releases | ConvertTo-Json -Depth 100)"
- 如果响应中没有发布,则不会执行发布管道。
我想在不登录 Azure DevOps 项目的情况下使用 PowerShell 验证发布管道是否已执行。如何测试这个?是否也可以使用 PowerShell 获取 Release 的输出,就像它成功或失败一样?
您可以使用 az 命令:
使用 pat (Sign in with a Personal Access Token (PAT)) 登录您的组织:
az devops login --organization https://dev.azure.com/org_name
-
az pipelines release definition list --org https://dev.azure.com/org_name -p ProjectName --output table ID Name CreatedBy Created On ---- ------------------------ ----------------- -------------------------------- 2 New release pipeline (3) UserName 2019-09-26T15:42:59.613000+00:00 3 New release pipeline UserName 2019-10-08T07:48:21.457000+00:00 4 New release pipeline (1) UserName 2019-11-19T19:04:40.523000+00:00 5 New release pipeline (2) UserName 2020-07-23T14:13:08.953000+00:00
-
az pipelines release list --definition-id 5 --org https://dev.azure.com/org_name -p ProjectName --output table ID Name Definition Name Created By Created On Status Description ---- --------- ------------------------ ----------- -------------------------- -------- ------------- 177 Release-6 New release pipeline (2) UserName 2020-12-22 19:28:06.610000 active Triggered by 176 Release-5 New release pipeline (2) UserName 2020-12-21 18:29:51.930000 active Triggered by 175 Release-4 New release pipeline (2) UserName 2020-12-18 12:52:04.610000 active Triggered by 174 Release-3 New release pipeline (2) UserName 2020-11-11 02:02:32.653000 active Triggered by
-
az pipelines release show --id 177 --org https://dev.azure.com/org_name -p ProjectName --output table ID Name Definition Name Created By Created On Status Description ---- --------- ------------------------ ----------------- -------------------------- -------- ------------- 177 Release-6 New release pipeline (2) UserName 2020-12-22 19:28:06.610000 active Triggered by
此外,您可以使用 --output
参数来获得 json 格式的结果,然后您将获得更详细的信息。
I want to validate if a Release Pipeline is executed or not using PowerShell without logging into the Azure DevOps project.
如果您想使用 PowerShell 验证发布管道是否已执行,以下脚本可以实现。
- Create a PAT with full scopes, and then use this Rest API: Definitions - List 列出所有发布管道。请参阅以下脚本。
$url = "https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/definitions?api-version=6.0"
$connectionToken="PAT Here" #input your PAT
$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($connectionToken)"))
$pipelines = Invoke-RestMethod -Uri $url -Headers @{authorization = "Basic $base64AuthInfo"} -Method Get
Write-Host "Pipeline = $($pipelines | ConvertTo-Json -Depth 100)" #list all release pieplines
- 您可以从上述响应中找到目标 发布管道的定义 ID 。然后使用此 Rest API: Releases – List 获取此发布管道的所有版本。请参阅以下脚本。
$new_url = https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/releases?definitionId={definitionId}&api-version=6.0
$releases = Invoke-RestMethod -Uri $new_url -Headers @{authorization = "Basic $base64AuthInfo"} -Method Get
Write-Host "releases = $($releases | ConvertTo-Json -Depth 100)"
- 如果响应中没有发布,则不会执行发布管道。