title: How do I know the build number for the current project in Jenkins?
body: <p>I am aware of the <code>BUILD_NUMBER</code> environment variable; however, unless I'm mistaken, this is a <strong>global</strong> variable which appears to be shared among all projects. This is a problem since, if I have two agents running jobs, one script may try to use the current project's build number after another script has updated it for a different project.</p>
  
  <p>Here is an example scenario:</p>
  
  <ul>
  <li>Job <strong>J<sub>1</sub></strong> starts, executing some script <strong>S</strong>. <code>BUILD_NUMBER</code> is currently, let's say, 500.</li>
  <li>Someone manually starts job <strong>J<sub>2</sub></strong>, which now sets <code>BUILD_NUMBER</code> to something completely different, say, 750.</li>
  <li>Script <strong>S</strong>, which is still running, now reaches the point where it actually uses <code>BUILD_NUMBER</code>, now set to 750 (an impossible value for job <strong>J<sub>1</sub></strong>, which is only up to 500).</li>
  </ul>
  
  <p>Am I correct in this understanding? If so, how do I address this problem?</p>