Tom Davies
Tom Davies

Reputation: 2446

Jenkins coping with spaces in batch file arguments

I'm setting up Jenkins on Windows to take care of the builds for a Windows project I've been working on. Until now, I've just been building locally. I've got a batch file that performs the build, which ends up generating some msi installers.

Some of the projects contain post builds steps that run batch files. The arguments to the batch files sometimes contain spaces. This isn't a problem when I run my build batch file from the command prompt.

However, Jenkins seems to have a problem with this - I get errors such as

"File not found: C:\Program"

I'm puzzled as to why the error happens when Jenkins triggers the batch, but not when I run it manually - any ideas?

Upvotes: 5

Views: 9292

Answers (2)

Peter Bernier
Peter Bernier

Reputation: 8069

As Jason mention, you need to pass your arguments and paths with quotes.

Also, check the build log and see which type of quotes you're using. Depending on where it's being passed you may need single or double quotes, or some sort of escape character.

If you want to look at the actual batch file that Jenkins runs for your external commands or pre/post build events, check the build log and load up the temporary batch file in an editor to see what it actually looks like. Sometimes this is necessary to debug your build.

Upvotes: 0

Jason Swager
Jason Swager

Reputation: 6501

For arguments that include spaces, wrap them in double quotes. Example:

WRONG: PROCESS_FILE.EXE C:\Program Files\This File.txt

CORRECT: PROCESS_FILE.EXE "C:\Program FIles\This File.txt"

Upvotes: 3

Related Questions