powershelltfsmsbuildazure-devopsvnext

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.

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.

Can this be done for arbitrary logic, not just msbuild?

EDIT 1

My philosophy to writing vNext (or Octopus) project is to minimize the number of steps. This is because these steps are code, but neither vNext nor Octopus provide the environment I expect to get when writing code, specifically:

  1. Version Control
    • Technically vNext has it, but for me VCS implies easy diffing with the other versions. vNext diff is full of irrelevant crap. Still light years better than Octopus, which has none.
  2. Code Review
  3. Associated Work Items (why did X made change 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. But the code that runs on the particular machine locally is my Powershell script.


Solution

  • 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. 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.