使用Powershell的TFS API创建发行版 [英] TFS API Create Release with powershell

查看:91
本文介绍了使用Powershell的TFS API创建发行版的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Powershell对构建进行排队并创建发行版.我能够成功地对构建进行排队,但是很遗憾,该版本并未触发持续部署.

I'm trying to queue a build and create a release using powershell. I'm able to successfully queue a build but unfortunately, the Continuous Deployment is not being triggered for the release.

我希望我可以在Powershell脚本中完成这两项操作,从而使我能够释放该应用程序.我正在使用TFS 2015 Update 3

My hope is that I can do both of these in a powershell script that will allow me to release the application. I'm using TFS 2015 Update 3

我一直在阅读这里发布的文章:

I've been working from an article posted here: http://blog.nwcadence.com/vststfs-rest-api-the-basics-and-working-with-builds-and-releases/

执行以下操作时的摘要:

In summary in performing the following:

  • 调用api返回发布列表
  • 执行发布列表查询并返回基于ID的信息 在发布名称上
  • 设置发布定义ID
  • 调用api返回特定的发布定义信息
  • 设置工件的别名
  • 设置工件ID
  • 设置ReleaseUri
  • 为工件构建Json字符串
  • 结合所需信息设置json
  • 调用api开始创建传入json的发行版
  • Calling api to return a list of release
  • Performing a query of the list of releases and returning the id based on the release name
  • Setting the release definition id
  • Calling the api to return the specific release definition info
  • Setting the alias for the artifacts
  • Setting the artifacts id
  • Setting the ReleaseUri
  • Constructing the Json string for artifacts
  • Setting json with the combination of required info
  • Calling api to kick off the creation of a release passing in the 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


一切正常,直到我打了最后一个声明.我收到的错误是:


All appears to be ok until I hit the last statement. The error I'm receiving is:

{"$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

推荐答案

我找到了答案.有两个问题.一种要求将所有值都放在引号中".另一个与buildid和名称有关,因为prem需要使用名称,但对工件使用了错误的ID.这是我的json:

I found the answer. There were two issue. One required placing all values in quotes"". The other was related to the buildid and name as name is required for on prem but was using wrong id for artifacts. Here is my json:

{ "definitionId":17 "description":"ContentManagement-Dev", 文物":[ {别名":"ContentManagement-Dev", "instanceReference":{ "id":"12569", 名称":"ContentManagement-Dev_1.0.0.12569"} } ] }

{ "definitionId": 17, "description": "ContentManagement-Dev", "artifacts": [ {"alias": "ContentManagement-Dev", "instanceReference" : { "id": "12569", "name": "ContentManagement-Dev_1.0.0.12569"} } ] }

这篇关于使用Powershell的TFS API创建发行版的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆