Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting environment variables in Jenkins with a bat file?

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?

like image 787
Gerald Hughes Avatar asked Mar 12 '14 16:03

Gerald Hughes


People also ask

How do I set an environment variable in a batch file?

When creating batch files, you can use set to create variables, and then use them in the same way that you would use the numbered variables %0 through %9. You can also use the variables %0 through %9 as input for set. If you call a variable value from a batch file, enclose the value with percent signs (%).

How do I add a batch file to Jenkins?

Add the batch command as run. Click on Apply and save the configuration then, you will redirect to the Project Workspace. Click on the Build Now, it will execute the given batch command that executes the run. bat file. You can see the console results on the Console Output.


1 Answers

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.

like image 62
Slav Avatar answered Nov 05 '22 17:11

Slav