Hooks using git bash on windows

Hi there, we have our windows boxes set to use shell="C:\Program Files\Git\bin\bash.exe" in their buildkite-agent.cfg.

…we ALSO have a command.bat that runs the command with "%ProgramFiles%\Git\bin\bash.exe" -c "!BUILDKITE_COMMAND!"

If I delete the command.bat, jobs will error, trying to run the command hook in cmd. Which seems like it always runs hooks in cmd.

QUESTION 1: I’d like to have the agent shell set to bash, and the agent run the command hook in bash. Is this possible?

I noticed in the documentation it says the command hook can be run IF the shell is set to powershell.

QUESTION 2: Does that mean it will run command.bat in powershell? or does it need to be called command.ps1? Why does this work, and not bash?


So I ended up having a command.ps1 just pipe directly into our bash command hook. This achieves what I wanted, but I would have expected a shell=bash would use the bash hooks in the first place.

&"$Env:ProgramFiles\Git\bin\bash.exe" -c ".buildkite/hooks/command"

For context the specific problem we were having is all of our CI runs in bash so we ran BUILDKITE_COMMAND with bash like so

"%ProgramFiles%\Git\bin\bash.exe" -c "!BUILDKITE_COMMAND!"

The problem was if there’s any spaces in the command, like echo "wow look a space", it would completely stop the entire job at the space. It would end with wow. Not great!

Regardless, I think the docs should call this oddity out at least.

I’m also seeing this as well and would love an update!

Hey folks!

Unfortunately, Windows has some caveats and the agent use batch as default for the hooks. The workaround you proposed is the best alternative at the moment.