将构建中的内容传递回 Visual Studio Team Services 构建

Pass content from build back into Visual Studio Team Services Build

我 运行 使用自定义构建代理在 Azure 上构建(准确地说是使用 Unity3d)我在构建机器上的 .txt 文件中生成构建的输出,并希望在工作中包含内容在构建期间创建的项目。

示例:

  1. Unity 构建失败,错误记录到 Build.log。
  2. 参考构建和错误消息创建了新错误 日志文件

现在我正在使用 powershell 脚本

$content = [IO.File]::ReadAllText("$(Build.Repository.LocalPath)\BuildProjectPC\Build.log")
Write-Host "##vso[task.setvariable variable=logContent;]$content"

为了格式化错误,我使用 System.Description = $logContent 但来自 PS 的变量内容由于某种原因确实没有出现在错误项目中(它只包含“$logContent”)。

关于如何解决这个问题的任何想法或方向,分别是如何将信息反馈到 vsts?

在附加字段中,您需要使用以下符号引用 build/release 定义变量:$(logContent)

如下图所示:

用于创建工作项的变量值在运行宁构建步骤之前初始化,因此您不能在用于创建工作项的构建步骤中指定动态变量或更改变量值. 您可以按照以下步骤进行验证:

  1. 打开您的构建定义 > 变量 > 添加一个新变量(例如 logContent,值:oldValue)
  2. Select 选项 > 失败时检查工作项 > 附加字段 > System.Title $(logContent)
  3. 添加 PowerShell 构建步骤:Write-Host "$(logContent)"
  4. 添加 PowerShell 构建步骤:Write-Host "##vso[task.setvariable variable=logContent;]newValue"
  5. 添加 PowerShell 构建步骤:Write-Host "$(logContent)"
  6. 添加 PowerShell 构建步骤:[环境]::退出(1)

日志结果:

  1. 第3步输出oldValue
  2. 第5步输出newValue
  3. 创建的工作项标题oldValue。

您的要求的解决方法是,您可以 create a work item and associated to build 通过 PowerShell with Rest API(在其他步骤末尾添加 PowerShell 步骤并选中始终 运行 选项)。

关联要构建的工作项:

请求类型:补丁

请求URL:https://[yourvsts account].visualstudio.com/DefaultCollection/_apis/wit/workitems/[work item id]?api-version=1.0

Content-Type:application/json-patch+json

Body:

[
  {
    "op": "add",
    "path": "/relations/-",
    "value": {
      "rel": "ArtifactLink",
      "url": "vstfs:///Build/Build/[build id]",
      "attributes": {
        "comment": "Making a new link for the dependency"
      }
    }
  }
]

您可以参考此博客的 PowerShell 脚本来创建和关联工作项。

Build association with work Items in vNext