Running job of BASH commands via Cygwin?

I am moving a job from another continous integration product to TeamCity.

The job is simply a BASH script, containing 10 or 12 lines. Since I am running on Windows, the CI server runs it via Cygwin.

When I try get it going in TeamCity however, by pasting it into the Custom Script field, it does not like most of the commands:

'#!' is not recognized as an internal or external command, (this is the shebang line)

[06:15:47]operable program or batch file.

[06:15:47]'#export' is not recognized as an internal or external command, (this is a commented-out line)

[06:15:47]operable program or batch file.

[06:15:47]'export' is not recognized as an internal or external command, (trying to set environment variables here)

[06:15:47]operable program or batch file.

[06:15:47]The system cannot find the path specified.

[06:15:47]'NEWEST' is not recognized as an internal or external command,(trying to declare a variable)



What am I missing here? Do I need extra configuration to "tell" TeamCity that the commands should be run via Cygwin? Or how does it know?


Many thanks












3 comments
Comment actions Permalink

How can I have the cygwin output script in the Teamcity because for now I have nothing?

1
Comment actions Permalink

Hi Evan. Welcome to TeamCity!

On Windows command-line runner executes shell scripts using native cmd.exe interpretor. And it knows nothing about UNIX #!sh notation.
You need to explicitly call bash.exe, like this:
Capture.PNG

0
Comment actions Permalink

Thanks Michael.

I've made the alteration you suggested. Things are now getting further - the first UNIX command in the script gets executed correctly.

It assigns a variable like:

NEWEST=`ls -rt /cygdrive/c/Logs/*.txt | tail -1`

So it seems that it is finding this directory OK.

However, the next statement is a grep on the file referenced by NEWEST, and it fails thus:

grep: /cygdrive/c/Logs/<thelogfile>
[04:33:51]: No such file or directory


I am wondering why the variable assignment fails, but the grep does not? If I run the grep manually in Cygwin, it works.

Do you have any suggestions?

Thanks

0

Please sign in to leave a comment.