ビルドをキューに入れ、powershell を使用してリリースを作成しようとしています。ビルドを正常にキューに入れることができましたが、残念ながら、リリースに対して継続的デプロイがトリガーされていません。
私の希望は、アプリケーションをリリースできるようにする powershell スクリプトでこれらの両方を実行できることです。TFS 2015 Update 3 を使用しています
ここに投稿された記事から作業してきました: http://blog.nwcadence.com/vststfs-rest-api-the-basics-and-working-with-builds-and-releases/
要約すると、次のように実行されます。
- api を呼び出してリリースのリストを返す
- リリースのリストのクエリを実行し、リリース名に基づいて 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