我正在尝试使用 powershell 对构建进行排队并创建发布。我能够成功地对构建进行排队,但不幸的是,该版本没有触发持续部署。
我希望我可以在允许我发布应用程序的 powershell 脚本中完成这两项工作。我正在使用 TFS 2015 更新 3
我一直在研究发表在这里的一篇文章:http://blog.nwcadence.com/vststfs-rest-api-the-basics-and-working-with-builds-and-releases/
总之,执行以下操作:
关于版本名称
我的脚本:
$releaseDef = Invoke-RestMethod -Method Get -UseDefaultCredentials -Uri "$Uri/$defaultCollection/$TeamProject/_apis/release/definitions?api-version=2.2-preview.1"
$id = $releaseDef.value | Where-Object { $_.name -eq $releaseName} | select id
$releaseDefId = $id.id
$release = Invoke-RestMethod -Method Get -UseDefaultCredentials -ContentType "application/json" -Uri "$Uri/$defaultCollection/$TeamProject/_apis/release/definitions/$releaseDefId`?api-version=2.2-preview.1"
$alias = $release.artifacts.alias
$aliasId = $release.artifacts.id
$releaseUri = "$Uri/$defaultCollection/$TeamProject/_apis/release/releases?api-version=2.2-preview.1"
$jsonReleaseString = "{""alias"": ""$alias"", ""instanceReference"" : ""id"" : ""$aliasId""}}"
$jsonRelease = @"
{
"definitionId": $releaseDefId,
"description": $buildNbr,
"artifacts": [
$jsonReleaseString
]
}
$releaseResponse = Invoke-RestMethod -Method Post -UseDefaultCredentials -ContentType "application/json" -Uri $releaseUri -Body $jsonRelease
一切似乎都很好,直到我点击最后一条语句。我收到的错误是:
{"$id":"1","innerException":null,"message":"VS402903: The parameter with name releaseStartMetadata should be an ReleaseStartMetadata, but the specified value is not convertible to
ReleaseStartMetadata","typeName":"System.InvalidOperationException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089","typeKey":"InvalidOperationException","errorCode":0,"eventId":0}
At line:1 char:12
+ $release = Invoke-RestMethod -Method Post -UseDefaultCredentials -ContentType "a ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
最佳答案
我可以在这里想到两个问题:-
对于 TFS17,上面的 #2 应该是可选的。
关于powershell - 使用 powershell 创建 TFS API 发布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41216277/