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?
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"
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.
Related
I have created a windows batch file to run a code which is located in a particular folder. However, I am running the batch file but it does not work. What I want it to do is:
Change working directory in Spyder (Spyder is already openned so I don't want it to open it first)
Run the script I want to execute
Basically, the script I am running is plotting a bunch of graphs and all the files needed to create this are located in the working directory.
#echo off
"C:\Users\Mason\Desktop\WinPython-64bit-2.7.6.4\spyder.exe"
chdir /D "F:\optimisation"
"F:\optimisation\plot.py"
pause
The batch file runs fine without any errors, but nothing happens in Spyder e.g. it doesn't change the working directory and neither executes the code.
I'd suggest
#echo off
setlocal
chdir /D "F:\optimisation"
"C:\Users\Mason\Desktop\WinPython-64bit-2.7.6.4\spyder.exe" "F:\optimisation\plot.py"
pause
That is, switch to the required directory, having set a local environment (this restores the original environment when the batch terminates).
Then run the spyder executable, providing it with the name of the file. It would be normal practice to use this structure to provide a significant filename to an executable (eg notepad fred,txt)
Since the current directory when spyder runs is f:\optimisation, it is probably not necessary to specify the entire path in spyder's argument.
Note this is all just speculation using normal practice. I have no experience of spyder- in fact, this is the first I've heard of it.
I am trying to have a batch file run once when Office is started. I opened the following key and inserted it in there but I am obviously not invoking the right command.
HKCU\Software\Microsoft\Office\15.0\FirstRun
I am inserting the item as C:\program files\Office2013Templates\OfficeTemplate3.bat which will run manually but not run from the registry key.
so the entire string looks like this:
"msofficeTemplate"="C:\\program files\\office2013templates\\officetemplate3.bat
I would also like to run it silent, but one thing at a time.
Thanks for any help you might be able to give me.
If office is using CreateProcess it won't work because it's not a program. CMD.EXE runs batchfiles. So try this command.
C:\Windows\System32\Cmd.exe /c "C:\program files\Office2013Templates\OfficeTemplate3.bat"
Office may require backslashes to be escaped. Registry files require backslashes and quotes to be escaped. But the registry itself doesn't. So enter above in registry editor and export to get properly formatted regfile.
I am vaguely familiar with batch. Super light knowledge. Anyways, I have this program that runs in a command line mode (it happens to render minecraft maps).
It is normally used by opening cmd, and typing mapcrafter.exe -c config.config -j 8 which runs the exe, specifies the config file, and runs the job with 8 threads.
One thing I wanted to do was put all of this in a batch file so I didn't have to type everything in every time I wanted to re-render it. It looked like:
start cmd.exe /K mapcrafter.exe --config "config.config" --jobs 8
This worked great, when the batch file was in the same directory as the exe.
Anyways, what I don't know how to do is to:
Start command prompt
change directory (cd) to the folder containing the .exe
Run the .exe with the two (-c -j) parameters
I want to do all of this in one batch file, and I want it to keep the command prompt window open, since the .exe outputs errors and percent completion.
I'm lucky I was able to get the one-line batch file working, with my limited knowledge of batch. At this point, I'm out of ideas as to how I should approach this. Thank you in advance for any help you can offer!
Why don't you just create a batch file with
mapcrafter.exe --config "config.config" --jobs 8
The reason it doesn't work when it is not in the same directory is because your path variable doesn't have the location of mapcrafter. An easier way around would be to use full path something like
D:\MineCraft\mapcrafter.exe --config "config.config" --jobs 8
If you want to learn more about configuring PATH environment variable see
Adding directory to PATH Environment Variable in Windows
you could just make a shortcut of the .bat file and have that on your desktop or wherever you want it. here is Microsoft's support page on this http://support.microsoft.com/kb/140443
I am automating a file download thorough CuteFTP using VBScript. At the end of the VBScript I am calling a batch file that will use 7zip's CLI to expand the zip file.
The batch file and the 7zip executable are stored on Server1 (nt950id3). The expansion takes place on Server2 (nt950a1). Due to corporate restrictions, this cannot be changed. Since the VBS is working, I have omitted its code. This is the batch command-
"\\nt950id3\c$\apps\CFI\7zip\7za.exe" e -y "\\nt950a1\filexfr$\Spectrum\File.zip" -o"\\nt950a1\filexfr$\Spectrum"
Expansion is accomplished awkwardly because 7zip will extract to the CWD of the batch file, as opposed to the directory the zip file is in unless I specify the -o switch.
When I double-click the batch file or run it via a scheduled task, it works just peachy. When VBScript calls the batch file, it fails stating UNC paths are not supported - I did not know there would be a difference. PUSHD and POPD should fix this.
Further research through this post on CLI Crash Course lead me to use PUSHD on each directory and set them as variables-
SET UZEXE=PUSHD "\\nt950id3\c$\apps\CFI\7zip\7za.exe"
SET ZSRC=PUSHD "\\nt950a1\filexfr$\Spectrum\File.zip"
SET ZEDST=PUSHD "\\nt950a1\filexfr$\Spectrum"
At the bottom of the code I use 'POPD' three times (also attempted at the end of each line) and despite having this very simple SO post on setting paths I am unable to make this work. I also attempted this without PUSHD-
SET UZEXE="\\nt950id3\c$\apps\CFI\7zip\7za.exe"
This also failed stating UNC paths are not supported.
Could the community kindly explain my errors and point me towards an example of how I can accomplish running a command using multiple, separate PUSHD/POPD directories?
Following Bill's guidance, I used only VBS - no calls to batch - for my issue. I was not aware this was so easily possible and will endeavor to do better research going forward. The working code - with stand-in UNC paths - is as follows:
Set wshShell = CreateObject("wscript.shell")
wshShell.Run"""\\server1\path\7z.exe"" e -y ""\\server1\path\srcfile.zip"" -o\\server2\path\unzipdest", 0, True
At first, the executing code stated it could not find the file. This turned out to be an issue with white space in the file paths. After using this Google groups topic to learn to properly place the quotes, it is now working within the CuteFTP script with no errors.
Currently I have a batch file that sets all the environment variables needed before starting the build process.
It's a must to use the same bat for setting the env variables.
I tried to use EnvInject Plugin, didn't have any success.
Also tried "Execute Windows batch command" before running msbuild. e.g. start mybat.bat - this didn't seem to work either
How can I integrate the same bat file to set the variables?
Each Jenkins "build step" has it's own environment, I explained this in detail in this answer: Can not change Jenkins String Parameter Variable
If you are using the MSBuild plugin, it is its own build step, so using other build steps to change the environment is futile. If you are launching MSBuild through command line using "Execute Windows batch command", then just ran your bat file within the same build step, preceding the MSBuild command
In the case of MSBuild plugin, the only proper way is to use EnvInject plugin. Maybe you should try to figure out what isn't working for you with EnvInject plugin. From the example documentation, you want to be using "At job level" configuration, to populate your whole job with the variables from your .bat file.