thecoshman
thecoshman

Reputation: 8650

Invoking long NAnt process from PowerShell form Jenkins (using Pipelines)

I've been working on wrapping up the usage of some old NAnt scripts behind a Jenkins job. The Jenkins job itself is using the pipelines feature, a groovy DSL script, one of the steps is a PowerShell block, and it calls some a function that invokes NAnt, after working out lots of parameters to be parsed in.

I did have this working at some point just fine, but something has broken at some stage. The PowerShell function is called, and it triggers NAnt, and for the nearly an hour that it takes to complete, you get the output, as it happens, showing up in Jenkins.

This was done using something like Invoke-Expression "& $NAntExe $NAntFile $Target $ParameterString" | Write-Host, where $ParameterString is all the -D:Key=Value parameters.

I believe I had added the | Write-Host as without it, you only get the output at the very end, but we wanted to be able to see the progress as it's happening.

As I said, something has changed somewhere, and we were no longer getting any output from NAnt. I eventually found that removing the | Write-Host would restore the logs, but as I expected, we now have to wait for NAnt to finish before we see any logs.

What is the 'correct' way to invoke NAnt here to get the output as I desire? I want to see the output as it happens.


I've tried various ways of invoking NAnt, with no luck. Seems I'm having to settle for either "I get all the output in one go at the end" or "no output". I suspect this is not a PowerShell issue as such, but that's based on nothing but gut feeling.


Seems I can mostly recreate the symptoms I see in Jenkins. If I invoke NAnt through a fresh PowerShell session I get the same problem, I'm running something akin the following, which as far as I can tell would be the same as how the Jenkins plugin invokes PowerShell:

powershell.exe -NoProfile -NonInteractive -ExecutionPolicy ByPass -Command 'Invoke-FunctionThatCallsNAnt'

Within my Invoke-FunctionThatCallsNAnt, I had initially, as I said above, just directly called NAnt and got no logging. I then update my function to pipe the output to Write-Host or I can remove the -NonInteractive flag and I will get the output from NAnt in real time. However, when I go to Jenkins, this does not resolve the problem, I end up with getting no output at all.

Upvotes: 1

Views: 233

Answers (1)

js2010
js2010

Reputation: 27408

I'm not sure why it wouldn't stream. You should be able to write the command these ways:

& $NAntExe $NAntFile $Target $ParameterString

Or with whatever the nant command is.

$env:path += ';c:\program files\nant'  # add to path if needed
nant.exe $NAntFile $Target $ParameterString

If it's not in the path, and the folder doesn't have spaces, you can put the whole path to it as well.

c:\nant\nant.exe $NAntFile $Target $ParameterString

EDIT:

Here's a way to run something in a path with spaces:

C:\Program` Files\Internet` Explorer\iexplore.exe

EDIT2:

It looks like you have to unblock the nant zip after downloading it: How do I resolve configuration errors with Nant 0.91?

Or unblock all the files after the fact:

get-childitem -recurse c:\nant-92 |
get-item -stream zone.identifier -erroraction silentlycontinue |
select -expand filename | get-item | unblock-file

Upvotes: 0

Related Questions