通过REST API对Azure DevOps Pipeline构建进行排队时,是否可以更改“ [用户]的手动构建”文本?

时间:2019-04-22 19:41:08

标签: azure azure-devops azure-pipelines

当我使用the REST API在Azure DevOps Pipelines中对构建进行排队时,该构建在构建列表中显示为Manual build for [user],其中[user]是与令牌绑定在一起的用户的名称发出的API请求。可以用自定义文字(例如Build for PR#1234或类似文字)替换吗?

编辑: 这是Web UI构建列表的屏幕快照,其中包含我要更改的Manual build for [user]文本:

screenshot of Azure DevOps Pipelines web UI

1 个答案:

答案 0 :(得分:1)

您可以这样更改描述文字:

Param(
   [string]$vstsAccount = "software",
   [string]$projectName = "project",
   [string]$definitionId = "895",
   [string]$keepForever = "true",
   [string]$personalAccessToken  = "xxxxxx"
)

# Base64-encodes the Personal Access Token (PAT)
$headers = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($personalAccessToken)")) }

# Construct the REST URL
$uri = "https://vsrm.dev.azure.com/$vstsAccount/$projectName/_apis/release/releases?api-version=5.0-preview.8"

Write-Host "Uri :" $uri

$params = 
@"
{
    "definitionId": $definitionId,
    "description": "Create Release from PowerShell Script",
    "artifacts": [],
    "isDraft": false,
    "reason": "VSTS Trigger",
    "manualEnvironments": null,
    "environmentsMetadata": null, 
    "properties": null, 
    "variables": null
}
"@

Write-Host "Request Body :" $params

# Invoke the REST call and capture the results
$result = Invoke-RestMethod -Uri $uri -Method POST -Body $params -Headers $headers -ContentType "application/json" -Verbose -Debug

Write-Host "Result :" $result

# This call should only provide a single result
if ($result.count -eq 0)
{
    Write-host "Unable to locate Release Definition Id $definitionId"
}
else
{
    Write-host "Successfully triggered the VSTS release job !!!"
}