0

Trying to pull all of the various build scripts out of the jenkins definitions and store them into one or more scripts in the source repository.

Some of the scripts are shell scripts, some are batch files. A shell script starts it off by running c:\program files\git\git-bash.exe and performing some git commands (no, I am not using the plugin - not my jenkins server and I have been given the most restrictive, minimal access to do this work, so I am going to run git commands from a script file). Some other work is done too to set variables, configure files for the build, etc.

The problem I am having, is trying to run a batch file from that shell script.

In jenkins, I have one shell script to kick off the process (with three parameters passed as arguments):

#!c:\Program Files\Git\git-bash.exe
/f/git/project/builds/step1.sh $MASTER_BRANCH $BUILD_TYPE $TAG_CLIENT

The step1.sh script works its way down to

# Override Jenkins value
WORKSPACE=/f/git/project
WIN_WORKSPACE=`cygpath -w $WORKSPACE | sed 's/\\\\/\\\\\\\\/g'`
echo "WIN_WORKSPACE: $WIN_WORKSPACE"
...
echo "Building!"
echo cmd.exe /c call builds\\step2.bat $WIN_WORKSPACE
cmd.exe /c call builds\\step2.bat $WIN_WORKSPACE
echo "done building"

What happens, is that the cmd.exe (with or without the "call" keyword) just pops out to a command prompt and sits there until I type "exit":

Building!
cmd.exe /c call builds\step2.bat F:\\git\\project
Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.

F:\git\project>exit  <--- I have to type that.
exit
done building

Is it possible to run batch files from git-bash shells? Is there a better approach? I am in the process of trying to convert to a batch file, but the syntax (for things like capturing command output and storing to a variable) is nicer with shell scripts. I also need to run at least a couple of shell (expect) scripts later in the build process for communicating with another server to complete another portion of the build.

Jon
  • 1,675
  • 26
  • 57

1 Answers1

1

Hopefully this painfully simple solution works; replace /c with //c, so:

cmd.exe //c call builds\\step2.bat $WIN_WORKSPACE

This is because the posix path fails with git-bash, even though you only intend for it to be passed with a command inside, so it must be escaped.

Bloodied
  • 1,004
  • 7
  • 20
  • Okay... that did it. Why? – Jon Mar 31 '16 at 18:13
  • 1
    Git isn't as smooth with windows, Cygwin is better for crossing bash and cmd, so windows posix paths fail to pass. [here](https://github.com/git-for-windows/build-extra/blob/master/installer/ReleaseNotes.md) [here](https://github.com/lavv17/lftp/issues/109) [and maybe here](http://stackoverflow.com/questions/11865085/out-of-a-git-console-how-do-i-execute-a-batch-file-and-then-return-to-git-conso) – Bloodied Mar 31 '16 at 18:19