Setting environment variables in Jenkins with a bat file?

13,785

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.

Share:
13,785
Gerald Hughes
Author by

Gerald Hughes

Updated on June 25, 2022

Comments

  • Gerald Hughes
    Gerald Hughes almost 2 years

    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?

  • Atul N
    Atul N over 6 years
    I was facing a similar problem in the pipeline project, running bat file within same build step resolved my issue.