How to declare a global variable in Jenkins and use it in an MSBuild task within each individual project How to declare a global variable in Jenkins and use it in an MSBuild task within each individual project jenkins jenkins

How to declare a global variable in Jenkins and use it in an MSBuild task within each individual project


You can do this with built-in Jenkins' functionality:

enter image description here

Then you need to expand your variable. This, actually, depends on where you would use it.

For example: %MSBuild% and %IIS_DIR% for "Execute windows batch command" build step. Other build steps (and plugins) may use it differently.


For global variables, you need EnvInject plugin. This allows you (among other things) to setup variables at the Global (node) level, at job level or as a step. You can set variables directly, or from properties file, or from scripts.

Once set, the variables are available as environment variables to the rest of Jenkins and its steps (within scope).

For passing arguments to MSBuild, when you configure an MSBuild step, there is an option to pass "Command line arguments" in the format /p:Param=Value.

The "value" could be an environment variable. On Windows environment you would reference it as %myvar%

So, if you configure a global GLOBAL_IIS_DIR=C:\path\to\IIS using EnvInject, you can then reference it on command line with /p:IIS_DIR=%GLOBAL_IIS_DIR%