值不能为空。参数名称:build.Definition
Value cannot be null. Parameter name: build.Definition
我正在尝试使用 azure devops REST API 对构建进行排队,但一直 运行 出错。我传递了 API 所需的所有强制值,但仍然得到值不能为空错误。
已经浏览了文档,但找不到任何示例代码。我尝试使用 API 文档创建 powershell 脚本,但努力 运行 它。
Param(
[string]$vstsAccount = "xxxxx",
[string]$projectName = "yyyyy",
[string]$definitionId = "1",
[string]$keepForever = "true",
[string]$personalAccessToken = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
[string]$accountname = "example",
[String]$adminemail = "example@example.com",
[String]$adminpassword = "example"
)
# Base64-encodes the Personal Access Token (PAT)
$headers = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($personalAccessToken)")) }
# Construct the REST URL
$uri = "https://dev.azure.com/$vstsAccount/$projectName/_apis/build/builds?api-version=5.0"
Write-Host "Uri :" $uri
$params =
@"
{
"definition": $definitionId,
"description": "Create Release from PowerShell Script",
"artifacts": [],
"isDraft": false,
"reason": "New tenant email Trigger",
"manualEnvironments": null,
"environmentsMetadata": null,
"properties": null,
"variables": {
"accountname": {
"value": "$accountname",
"allowOverride": true
},
"adminemail": {
"value": "$adminemail",
"allowOverride": true
},
"adminpassword": {
"value": "$adminpassword",
"allowOverride": true
}
}
}
"@
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 !!!"
}
希望得到一些执行此操作的建议。我还将 3 个变量传递给构建,这些变量将在 azure devops 构建管道中用作管道变量。
你必须像这样传递参数:
{
"parameters": "{\"ReleaseNumber\": \"1.0.50\", \"AnotherParameter\": \"a value\"}",
"definition": {
"id": 2
}
}
看看这个 post 了解更多信息
我正在尝试使用 azure devops REST API 对构建进行排队,但一直 运行 出错。我传递了 API 所需的所有强制值,但仍然得到值不能为空错误。
已经浏览了文档,但找不到任何示例代码。我尝试使用 API 文档创建 powershell 脚本,但努力 运行 它。
Param(
[string]$vstsAccount = "xxxxx",
[string]$projectName = "yyyyy",
[string]$definitionId = "1",
[string]$keepForever = "true",
[string]$personalAccessToken = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
[string]$accountname = "example",
[String]$adminemail = "example@example.com",
[String]$adminpassword = "example"
)
# Base64-encodes the Personal Access Token (PAT)
$headers = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($personalAccessToken)")) }
# Construct the REST URL
$uri = "https://dev.azure.com/$vstsAccount/$projectName/_apis/build/builds?api-version=5.0"
Write-Host "Uri :" $uri
$params =
@"
{
"definition": $definitionId,
"description": "Create Release from PowerShell Script",
"artifacts": [],
"isDraft": false,
"reason": "New tenant email Trigger",
"manualEnvironments": null,
"environmentsMetadata": null,
"properties": null,
"variables": {
"accountname": {
"value": "$accountname",
"allowOverride": true
},
"adminemail": {
"value": "$adminemail",
"allowOverride": true
},
"adminpassword": {
"value": "$adminpassword",
"allowOverride": true
}
}
}
"@
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 !!!"
}
希望得到一些执行此操作的建议。我还将 3 个变量传递给构建,这些变量将在 azure devops 构建管道中用作管道变量。
你必须像这样传递参数:
{
"parameters": "{\"ReleaseNumber\": \"1.0.50\", \"AnotherParameter\": \"a value\"}",
"definition": {
"id": 2
}
}
看看这个 post 了解更多信息