0

I have a long taking batch process in Jenkins (Unity3D to be exact) that doesn't provide any output to the console.

It only writes a logfile lets say unityLog.txt and does not produce any output to the console itself.

I need to display the output while it gets appended to the logfile in the console so it gets visible to the user via the Jenkins web interface.

So what I am currently doing is e.g. (more on the Unity Command line argments)

E:\Unity\2019.3.3f1\Editor\Unity.exe -quit -batchmode -projectPath E:\Projects\Example -executeMethod JENKINS.AutoBuilder.PerformBuild -logFile unityLog.txt -buildFolder E:\Projects\Example\Build

type unityLog.txt

The command actually runs in the project folder so this works but only displays the content of the file after unity finishes.

I have already read a lot questions similar to Displaying Windows command prompt output and redirecting it to a file which works great but they always assume the command itself produces any direct console output.

As said this is not the case here.

So what I would need is actually a form doing in batch what in bash I probably would do like (This is also just an example, unfortunately not a bash expert either ;) )

function MyLongTakingProcess()
{
    pid=$!

    E:\Unity\2019.3.3f1\Editor\Unity.exe -quit -batchmode -projectPath E:\Projects\Example -executeMethod JENKINS.AutoBuilder.PerformBuild -logFile unityLog.txt -buildFolder E:\Projects\Example\Build       

    kill $pid
}

touch unityLog.txt
tail -f unityLog.txt & MyLongTakingProcess

to permanently display added lines but cancel this as soon as the command has finished.

Any idea how this could be achieved?

derHugo
  • 368

3 Answers3

0

If I'm understanding the question, you want the tail the log in Windows. If that's your use case, then have a look at BareTail. It's a Windows utility which tails log files, for real-time log analysis.

0

I have found I can achieve what I was looking for doing the following

first I create the file (euivalent to touch)

echo. 2>test.txt

Then I start a "background" process for powershell -c "get-content test.txt -wait" (equivalent to tail -f test.txt)

start /b "logoutput" powershell -c "get-content test.txt -wait -ErrorAction Ignore"

the additional -ErrorAction Ignore hides any errors from the console.

Then I start the actual long taking task which generates output to test.txt using

start /b "long" /wait LONGTEST.bat

in order to wait for it to finish

Then finally I simply use

del test.txt

Deleting the file makes the powershell exit with an error. The error however I surpessed using -ErrorAction Ignore.


So in total

echo. 2>test.txt
start /b "logoutput" powershell -c "get-content test.txt -wait -ErrorAction Ignore"
start /b "long" /wait LONGTEST.bat
del test.txt

Using this I now see the full log in the console and am able to "kill"(make fail exit) the get-content process in the end.

derHugo
  • 368
0

Quoting the documentation you linked (emphasis mine):

Specify where Unity writes the Editor or Windows/Linux/OSX standalone log file. To output to the console, specify - for the path name. On Windows, specify - option to make the output go to stdout, which is not the console by default.

Than, as this answer states you can use Tee-Object in PowerShell to copy that stdout to a file to should you need it.

jaskij
  • 165