title: How to declare a global variable in Jenkins and use it in an MSBuild task within each individual project
body: <p>I am converting our CI platform from CruiseControl to Jenkins, and can't seem to figure something out that seems like it should be relatively simple to do (Disclaimer - I'm no CI or build automation expert, but this was dumped into my lap and I find it interesting)</p>
  
  <p>In CruiseControl, I am able to declare variables like this:</p>
  
  <pre><code>&lt;cb:define rootdir="J:\SOURCES\" /&gt;
  &lt;cb:define logdir="J:\SOURCES\buildlogs" /&gt;
  &lt;cb:define iisdir="J:\IIS\" /&gt;
  &lt;cb:define artifacts="artifacts\" /&gt;
  </code></pre>
  
  <p>Then use them as part of an MSBuild task</p>
  
  <pre><code>&lt;msbuild&gt;
        &lt;executable&gt;C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe&lt;/executable&gt;
        &lt;workingDirectory&gt;$(rootdir)$(ProjectName)&lt;/workingDirectory&gt;
        &lt;projectFile&gt;$(ProjectName).sln&lt;/projectFile&gt;
        &lt;buildArgs&gt;/p:BuildDate="1";OutDir="$(iisdir)$(ProjectName)\bin\\";WebProjectOutputDir="$(iisdir)$(ProjectName)\\"&lt;/buildArgs&gt;
        &lt;targets&gt;Rebuild;$(ProjectName)&lt;/targets&gt;
        &lt;timeout&gt;180&lt;/timeout&gt;
        &lt;logger&gt;C:\Program Files (x86)\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MsBuild.dll&lt;/logger&gt;
  &lt;/msbuild&gt;
  </code></pre>
  
  <p>If the root or IIS directories change, it can easily be applied to all projects at once. We have ~60 projects setup, so doing this project by project would be very time consuming. Migrating this to Jenkins, the MSBuild command line arguments now look like this (partial sample but includes what is relevant):</p>
  
  <pre><code>OutDir="J:\IIS\ProjectName\bin\\";WebProjectOutputDir="J:\IIS\ProjectName\\"
  </code></pre>
  
  <p>The IIS directory is hard coded. I need that to be something more like this:</p>
  
  <pre><code>OutDir="${IIS_DIR}\ProjectName\bin\\";WebProjectOutputDir="${ITEM_ROOTDIR}\ProjectName\\"
  </code></pre>
  
  <p>Is there a way to do that? I tried the configuration slicing plugin, which is useful, but doesn't fit this need from what I see</p>