我正在尝试使用PowerShell对构建进行排队并创建一个版本。我能够成功地对构建进行排队,但不幸的是,发布时没有触发持续部署。
我希望我可以在PowerShell脚本中执行这两项操作,这将允许我发布应用程序。我正在使用TFS 2015 Update 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
答案 0 :(得分:0)
我可以在这里想到两个问题: -
如果您的发布定义与某个工件链接,则instanceReference.id应该是工件的版本ID。我的意思是它应该是构建号,如果链接的工件是构建的。
您还需要传递instanceReference.name。这里应该是构建名称。
使用TFS17,上面的#2应该是可选的。
答案 1 :(得分:0)
我找到了答案。有两个问题。一个需要将所有值放在引号“”中。另一个与buildid和name相关,因为名称是on prem必需的,但是对于工件使用了错误的id。这是我的json:
{ “definitionId”:17, “description”:“ContentManagement-Dev”, “文物”:[ {“alias”:“ContentManagement-Dev”, “instanceReference”:{ “id”:“12569”, “name”:“ContentManagement-Dev_1.0.0.12569”} } ] }