title: Jenkins: How to use a variable from a pre-build shell in the Maven "Goals and options"
body: <p>I have a Maven job in Jenkins. Before the actual build step I have an "Execute shell" pre-build step. In that shell I set a variable:</p>
  
  <pre><code>REVISION=$(cat .build_revision)
  </code></pre>
  
  <p>I would like to use that variable in the Maven build job in "Goals and options":</p>
  
  <pre><code>clean install -Drevision=${REVISION}
  </code></pre>
  
  <p>But that does not work! The "Drevision" is set to "${REVISION}" not the actual value of ${REVISION}. Output:</p>
  
  <pre><code>Executing Maven:  -B -f /home/gerrit/.jenkins/jobs/&lt;job_name&gt;/workspace/pom.xml clean install -Drevision=${REVISION}
  </code></pre>
  
  <p>It works with Jenkins environment variables:</p>
  
  <pre><code>clean install -Dbuild=${BUILD_NUMBER}
  </code></pre>
  
  <p>It sets "Dbuild" to the actual build number. Output:</p>
  
  <pre><code>Executing Maven:  -B -f /home/gerrit/.jenkins/jobs/&lt;job_name&gt;/workspace/pom.xml clean install -Dbuild=54
  </code></pre>
  
  <p>My question: How to use a shell variable in Maven "Goals and options"??</p>
  
  <p>EDIT:</p>
  
  <p>I tried using <a href="https://wiki.jenkins-ci.org/display/JENKINS/EnvInject+Plugin" rel="noreferrer">Jenkins EnvInject Plugin</a> to "Inject environment variables" after the pre-build shell, and my variable is now accessible by e.g. post-build shells, but it is still not available in Maven "Goals and options".</p>
  
  <p>Then it is possible to set "Inject environment variables to the build process" using the EnvInject Plugin, which actually makes those variables available in Maven "Goals and options", but those are set right after SCM checkout, i.e. before pre-build steps, and do not support expression evaluations.</p>