Report progress with scripts (powershell)

usability
(GerjanOnline) #1

I have a database update step/task that can take a while so I would like to report some progress to the Octopus UI. Is that possible?

Currently I am using a Script step with a referenced package (my db tool) and I will execute it with Powershell. When its done, I will grab the log and upload it as artifact.

However, when this tasks will take for example 30 minutes it would be nice to show some progress.

  1. Can I make a Powershell script that continously polls the log and show it in the deployment log? I think this is possible but its a bit hard with PS and is it recommended?
  2. Sometimes you see a loader in the log header (for example when download/uploading packages). Is it possible to create this with custom scripts? (ie like TeamCity special log messages ##octopusmessage)
(Justin Walsh) #3

Hi @GerjanOnline!

  1. It definitely is possible to have a progress update in your powershell, in fact, many of our step templates do just this. For example, take a look at Our “Stop IIS App Pool” community template for how they do this!
  2. Progress bars are not something that’s currently possible, but our engineering team is working on a way to do this easily in the near future!

Please don’t hesitate to let me know if you have any further questions.

(GerjanOnline) #4

So with 1. I think you mean I can create a while loop and grab/update the log each time?

What about continuously polling a log file and display that log in the deployment log? What do you recommend?

My considerations:

  1. Use PowerShell Jobs (thats hard)
  2. Get-Content -Wait (can I use that? How do I know its finished)
  3. Log the StdOut and StdErr from my process (my tool supports that)

Problem with number 3 is that logging continuously is still hard because ProcessStartInfo.WaitForExit is still blocking.
I know I can use Register-ObjectEvent BeginOutputReadLine but that one is also complex.

Your advice?