我正在尝试使用 powershell 对构建进行排队并创建发布。我能够成功地将构建排队,但不幸的是,没有为发布触发持续部署。
我希望我可以在允许我发布应用程序的 powershell 脚本中完成这两项工作。我正在使用 TFS 2015 更新 3
我一直在研究这里发布的一篇文章:http: //blog.nwcadence.com/vststfs-rest-api-the-basics-and-working-with-builds-and-releases/
总而言之,执行以下操作:
- 调用api返回release列表
- 查询发布列表并根据发布名称返回 id
- 设置发布定义 id
- 调用api返回具体的发布定义信息
- 设置工件的别名
- 设置工件 ID
- 设置 ReleaseUri
- 为工件构造 Json 字符串
- 使用所需信息的组合设置 json
- 调用 api 以开始创建传递 json 的版本
我的脚本:
$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