How to run shell script on Teamcity Windows agent? How to run shell script on Teamcity Windows agent? shell shell

How to run shell script on Teamcity Windows agent?


This is quite easy to resolve. The error does not come from Cygwin of course, but from CMD. The export command only makes sense within a Bash script; cmd has no way of knowing what to do with it.

What you need to do is simply specify to CMD that the script should run using Cygwin's command interpreter (bash). So you can either just specify the long path to the bash executable and your script, as in

C:\dev\tools\cygwin\bin\bash D:\myscript.sh

or you can just add the path to the cygwin directory to your machine's PATH variable. You can do this by changing the System Settings and append the path there, or you can do it as part of your script above:

# this is not necessary if you have already changed the System Variable to include the pathset PATH=C:\dev\tools\cygwin\bin;%PATH%bash D:\myscript.sh


There is a good chance you already have Git installed on the agent with Git Bash. Following is how I run npm commands without changing the PATH variable

"C:\Program Files\Git\bin\bash.exe" -c "cd Source && npm install && npm run build"


With this, you can run the shell/bash commands:-"C:\Program Files\Git\bin\bash.exe" -c "cd Source && npm install && npm run build"

And from Powershell, if you want to run bash scripts :-

& 'C:\Program Files\Git\bin\bash.exe' .\build.sh