简体   繁体   English

如何从Powershell脚本中向TFS vNext报告构建进度?

[英]How to report build progress to TFS vNext from within a powershell script?

My vNext build contains very few steps - I just setup a few settings and call the main Powershell build script, which internally invokes msbuild, but it also does other things too. 我的vNext构建包含非常少的步骤-我只是设置一些设置并调用主Powershell构建脚本,该脚本在内部调用msbuild,但它也做其他事情。

I know that vNext comes with a distributed msbuild logger that allows msbuild to report events up to vNext to be displayed in the step Timeline. 我知道vNext附带了一个分布式msbuild记录器,该记录器允许msbuild将多达vNext的事件报告给在时间轴中显示的事件。

Can this be done for arbitrary logic, not just msbuild? 可以针对任意逻辑(不仅限于msbuild)执行此操作吗?

EDIT 1 编辑1

My philosophy to writing vNext (or Octopus) project is to minimize the number of steps. 我编写vNext(或Octopus)项目的理念是尽量减少步骤数。 This is because these steps are code, but neither vNext nor Octopus provide the environment I expect to get when writing code, specifically: 这是因为这些步骤是代码,但是vNext和Octopus都不提供我期望在编写代码时获得的环境,特别是:

  1. Version Control 版本控制
    • Technically vNext has it, but for me VCS implies easy diffing with the other versions. 从技术上讲vNext拥有它,但对我来说VCS意味着易于与其他版本进行区分。 vNext diff is full of irrelevant crap. vNext差异充满了无关紧要的废话。 Still light years better than Octopus, which has none. 仍然比没有章鱼的章鱼好几年。
  2. Code Review 代码审查
  3. Associated Work Items (why did X made change Y?) 相关工作项(为什么X更改了Y?)
  4. Debugging 调试

For me these are essential and that is why I tend to have one master build script. 对我来说,这些是必不可少的,这就是为什么我倾向于拥有一个主构建脚本。 I do delegate stuff to vNext (Octopus) - like publishing artifacts and tests or getting sources. 我确实将东西委托给vNext(Octopus)-例如发布工件和测试或获取资源。 But the code that runs on the particular machine locally is my Powershell script. 但是在本地特定计算机上运行的代码是我的Powershell脚本。

I agree with the comments suggesting that you split the build pipeline process into multiple steps/tasks to better see and log overall status. 我同意这些意见,建议您将构建管道过程分为多个步骤/任务,以更好地查看和记录总体状态。 That said, there is a way to report progress back to the build timeline. 也就是说,有一种方法可以将进度报告回构建时间表。 You can use the ##vso[task.setprogress] command documented on the Azure Pipeline Tasks Logging Commands page . 您可以使用Azure管道任务记录命令页面上记录##vso[task.setprogress]命令。 The following will print the progress percentage in the log/console as well as display the percentage next to the step name in the timeline: 以下内容将在日志/控制台中显示进度百分比,并在时间线中在步骤名称旁边显示百分比:

$myArray = @(1..10)
foreach ($item in $myArray) {
    $simplePercentage = (($myArray.IndexOf($item)/$myArray.Length)*100)
    Write-Output ("Current Percentage: $simplePercentage")
    Write-Output ('##vso[task.setprogress value={0};]{1}' -f $simplePercentage, 'My Sample Task')
    Start-Sleep -Seconds 3
}

You can split your Powershell script/functions into whatever overall percentage and then use that logging command to report the sections' progress. 您可以将Powershell脚本/功能划分为任何整体百分比,然后使用该日志记录命令报告各节的进度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM