bash task in Azure Devops not working on self hosted windows agent
That is because the WSL installed per a specific user, but if we run the self-hosted agent as service, it will using the NETWORK SERVICE/SYSTEM
account instead of local user account.
You could try to set Log On As
with the specific user (It should be the same user as you installed WSL. Then restart your server.
Detailed step for setting the Log On As with the specific user:
- Press the Win + R keys on your keyboard, to open the Run window. Then, type “services.msc” and hit Enter or press OK.
- Find the service for the self-hosted agent and right click it, select Properties, switch to Log On tab.
- Change the account to the specific user.
For example, I use xxxxxx\leoliu
account to login the server 2019:

Then install WSL with that account. After that, I open the services.msc and change the Log On As with that user:

Last but not least, restart your server, just restart the services is not enough.
Now, I could use my self-hosted agent to run the bask task:
