Lui*_*cia 3 rest powershell azure-devops
我在我的脚本中使用这个 aa 基础:
https://www.nwcadence.com/blog/vststfs-rest-api-the-basics-and-working-with-builds-and-releases
我的脚本如下
Param(
[string]$vstsAccount = "abc",
[string]$projectName = "abc",
[string]$user = "",
[string]$token = "xyz"
)
# Base64-encodes the Personal Access Token (PAT) appropriately
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
$verb = "POST"
$body = @"{
"definition": {
"id": 20
}
}"@
$uri = "https://$($vstsAccount).visualstudio.com/DefaultCollection/$($projectName)/_apis/build/builds?api-version=4.1"
$result = Invoke-RestMethod -Uri $uri -Method $verb -ContentType "application/json" -Body (ConvertTo-Json $body) -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
Run Code Online (Sandbox Code Playgroud)
但是我在上面的博客文章中使用的主体定义存在语法错误。
> o characters are allowed after a here-string header but before the end
> of the line. At C:\Users\abc\Documents\vstsqueuebuild.ps1:18 char:17
> + "definition": {
> + ~ Unexpected token ':' in expression or statement. At C:\Users\abc\Documents\vstsqueuebuild.ps1:19 char:14
> + "id": 20
> + ~ Unexpected token ':' in expression or statement. At C:\Users\anc\Documents\vstsqueuebuild.ps1:21 char:1
> + }"@
> + ~ Unexpected token '}' in expression or statement. At C:\Users\abc\Documents\vstsqueuebuild.ps1:24 char:9
> + $uri = "https://$($vstsAccount).visualstudio.com/DefaultCollection/$( ..
Run Code Online (Sandbox Code Playgroud)
box*_*dog 11
错误消息为您提供了线索:“在此处字符串标头之后但在结尾之前不允许使用任何字符”
更改代码,以便此处字符串开始/结束标记后面/前面不会紧跟着任何内容:
$body = @"
{
"definition": {
"id": 20
}
}
"@
Run Code Online (Sandbox Code Playgroud)
有多种方法可以更改此处字符串($body
变量的值):
$body = @{
definition = @{
id = 20
}
}
Run Code Online (Sandbox Code Playgroud)
$body = @"
{
"definition": {
"id": 20
}
}
"@
Run Code Online (Sandbox Code Playgroud)
正如boxdog所提到的。
$body = '
{
"definition": {
"id": 20
}
}
'
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
8817 次 |
最近记录: |