通过 Azure DevOps 更新构建定义的 defaultBranch API
Update defaultBranch of build definition via Azure DevOps API
我需要通过 Azure API
更新构建定义的 defaultBranch
。
问题是我不知道创建工作请求需要发送的最小 pf 参数列表。
我尝试从浏览器导出实际请求并仅修改此字段 - 状态代码为 200
但没有任何更改。我不想传递所有文件我只想修改 defaultBranch
.
在link你提供了Request Body section, you can see there what you need to pass. I like to get the definition first (with GetAPI),改成我想要的,然后执行更新。
在 PowerShell 中:
$pat = "YOUR-PAT"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,"$pat")))
$headers = @{Authorization=("Basic {0}" -f $base64AuthInfo)}
$url = "https://dev.azure.com/{organization}/{project}/_apis/build/definitions/{definitionId}?api-version=5.1"
$build = Invoke-RestMethod -Uri $url -Method Get -ContentType application/json -Headers $headers
$newDefaultBranch = "test-branch"
$build.repository.defaultBranch = $newDefaultBranch
$json = $build | ConvertTo-Json -Depth 10
$response = Invoke-RestMethod -Uri $url -Method Put -ContentType application/json -Headers $headers -Body $json
我需要通过 Azure API
更新构建定义的 defaultBranch
。
问题是我不知道创建工作请求需要发送的最小 pf 参数列表。
我尝试从浏览器导出实际请求并仅修改此字段 - 状态代码为 200
但没有任何更改。我不想传递所有文件我只想修改 defaultBranch
.
在link你提供了Request Body section, you can see there what you need to pass. I like to get the definition first (with GetAPI),改成我想要的,然后执行更新。
在 PowerShell 中:
$pat = "YOUR-PAT"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,"$pat")))
$headers = @{Authorization=("Basic {0}" -f $base64AuthInfo)}
$url = "https://dev.azure.com/{organization}/{project}/_apis/build/definitions/{definitionId}?api-version=5.1"
$build = Invoke-RestMethod -Uri $url -Method Get -ContentType application/json -Headers $headers
$newDefaultBranch = "test-branch"
$build.repository.defaultBranch = $newDefaultBranch
$json = $build | ConvertTo-Json -Depth 10
$response = Invoke-RestMethod -Uri $url -Method Put -ContentType application/json -Headers $headers -Body $json