用于排队构建的Invoke-RestMethod的Body需要包含什么? [重复]

问题描述 投票:1回答:1

这个问题在这里已有答案:

我应该能够使用Rest API对构建进行排队

POST https://dev.azure.com/{organization}/{project}/_apis/build/builds?api-version=5.0-preview.5

Builds API

我只是无法弄清楚应该包含在请求体中的内容以及如何组装它。

我正在使用powershell并修改我用来查询DevOps的脚本,它运行得很好:

function Queue-Build
{
    param (
        [string] $BuildUri,
        [Hashtable] $Headers
    )

    # Can't figure out how to assemble body    
    $build = Invoke-RestMethod -Uri $BuildUri -Headers $Headers -Method Post -Body $body

    return $build
}

function Set-AuthHeaders
{
    [CmdletBinding()]
    param (
        [string] $UserName = "",
        [string] $AccessToken
    )

    $basicAuth = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $UserName,$AccessToken)))
    return @{ Authorization = "Basic $basicAuth" }
}

# Azure DevOps settings
$AccessToken = 'my_access_token'
$vstsProjectUri = 'https://org.visualstudio.com/project'
$vstsApiVersion = "5.0-preview.5"
$headers = Set-AuthHeaders -AccessToken $AccessToken

# Queue a new build
$buildDefinitionUri = "$vstsProjectUri/_apis/build/builds?api-version=$vstsApiVersion"
$buildQueueResult = Queue-Build -BuildUri $buildDefinitionUri -Headers $headers
$buildQueueResult
azure-devops azure-devops-rest-api
1个回答
-1
投票

放入体内最重要的是构建ID。

您可以通过以下方式在PowerShell中创建主体:

$BuildDefinitionId = 5345
$body = @{ definition = @{id = $BuildDefinitionId}}
$json = $body | ConvertTo-Json

现在在你的休息电话中,-Body $json将采取身体并将队列建立5345。

© www.soinside.com 2019 - 2024. All rights reserved.