Run Bash script using WSL
How to run bash script, with script block using WSL?
Without construction like bash -c "my script", because in this case I will have to call it every line.
And without using "Executable with parameters", in this case I will have to separate all scripts by files, but this is not very good for my case.
Please sign in to leave a comment.
Hello,
Is your script for windows or for a unix like environment? Using Powershell you can use script block by using Powershell in the runner type and setting the script from source code:
If you are using a script for an unix-like environment, can you share an example with us via our upload service and send the id back to us so that we check what might be going wrong?
https://uploads.jetbrains.com/
Please let me know if this works for you or if you have any other questions.
Thanks,
Guilherme
Hello, my is script is for unix-like system. But agent run on windows. I need run bash script on windows machine using WSL.
Hello,
It should be possible to do it using the command line runner as in your screenshot above. You can try to prepare a script, set its path in the working directory and run the WSL executable passing the script to it.
Let me know if you are having any specific errors
Thank you,
Guilherme
Hi,
I'm currently also trying to have my windows agent run a bash script using WSL. Although the original author of this post did not report any problems, I'd like to share my issue here in hopes of finding a solution.
WSL works great on the Windows agent locally and the bash script executes as it should, however during a TeamCity build the WSL calls are problematic:
After some research, I found that this may be caused by the TeamCity agent using a 32 bit version of java and attempting to run WSL which is 64 bit. This turned out to not be the case, as I could see the java that came bundled with the TeamCity agent installer is in fact 64 bit.
Digging deeper into Windows logs, I could see the error with the exception code logged. The exception code hex (0x0000409) matches the exit code seen in TeamCity build log. I've tried looking into this exception code more but with no success. The most common solution I could find online was running sfc /scannow on the Windows machine but it did not help.
Any and all help is much appreciated!
I solved my issue, hopefully this solution helps others!
Digging through the TeamCity documentation, I noticed this page https://www.jetbrains.com/help/teamcity/start-teamcity-agent.html.
There it states the following:
I proceeded to change the TeamCity Build Agent service's LogOn user account to a local user account and voila! The issue was solved. WSL now runs perfectly and the output is produced and logged as expected.
Cheers, I hope this helps someone!
Kajusn stated, this was one thing that kept wsl from starting, another thing that needs to be checked is the java version the agent is using, it must be 64 bit to be able to run in wsl.
I used jdk-18.0.2 64 bit to solve this.