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
  • 318
  • 2
  • 16

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.

spikey_richie
  • 8,367
  • 2
  • 25
  • 42
  • yeah I do not want to display it in an external tool. It has to be printed in the cmd console itself so it gets displayed to the user on the Jenkins webpage ;) But thanks for your input! – derHugo Mar 06 '20 at 16:27
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
  • 318
  • 2
  • 16
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
  • 6
  • There are two issuea: `which is not the console by default` I will try again but I'm pretty sure to remember that I didn't see anything in the console when using `-`. That's the reason why I started this whole logfile workaround in the first place... Then also this is in general running in a batch script, not in the Powershell... But thanks for your input! Any little hint that brings me closer to a solution is very welcome! – derHugo Mar 11 '20 at 06:05
  • Boy I tried again and you are right! This doesn't actually answer the question but totally solves all my trouble as the `-` option in fact simply produces the output I need to the console. As jenkins stores this ouput I don't need it in a file actually. I guess I only tried it without specifying this parameter at all so it didn't produce any output! I now don't even need the log file at all. Thanks to hint me on that again! – derHugo Mar 11 '20 at 08:36
  • I didn't have time to reply earlier, but I suppose the note about the console was Unity-specific. You know, those in-IDE logs? And - is a fairly common placeholder for stdin/stdout in arguments which need a file. – jaskij Mar 11 '20 at 08:39