gpt4 book ai didi

powershell - 使用 powershell 创建 TFS API 发布

转载 作者:行者123 更新时间:2023-12-03 16:39:17 31 4
gpt4 key购买 nike

我正在尝试使用 powershell 对构建进行排队并创建发布。我能够成功地对构建进行排队,但不幸的是,该版本没有触发持续部署。

我希望我可以在允许我发布应用程序的 powershell 脚本中完成这两项工作。我正在使用 TFS 2015 更新 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

    最佳答案

    我可以在这里想到两个问题:-

  • 如果您的发布定义与某个工件相关联,则 instanceReference.id 应该是工件的版本 ID。我的意思是它应该是内部版本号,如果链接的工件是内部版本。
  • 您还需要传递 instanceReference.name 。这里应该是构建名称。

  • 对于 TFS17,上面的 #2 应该是可选的。

    关于powershell - 使用 powershell 创建 TFS API 发布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41216277/

    31 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com