title: set up global variables dynamically in gitlab-ci
body: <p>I want to set some variables by getting the values from a pom.xml file. These variables need to be global because they will be used in multiple stages and jobs.</p>
  
  <p>According to the gitlab-ci documentation, I can set global variables in two differents ways:</p>
  
  <ol>
  <li><p>using a variable statement:</p>
  
  <pre><code>variable:  
   pom_artifactID: $(grep -m1 '&lt;artifactId&gt;' pom.xml | cut -d '&lt;' -f2  |cut -d '&gt;' -f2)
  </code></pre></li>
  <li><p>Using a "before" script:</p>
  
  <pre><code> before_script:
     - pom_artifactID=$(grep -m1 '&lt;artifactId&gt;' pom.xml | cut -d '&lt;' -f2  |cut -d '&gt;' -f2)
     - pom_artifactVersion=$(grep -m1 '&lt;version&gt;' pom.xml | cut -d '&lt;' -f2  |cut -d '&gt;' -f2)
     - pom_packaging=$(grep -m1 '&lt;packaging&gt;' pom.xml | cut -d '&lt;' -f2  |cut -d '&gt;' -f2)
     - pom_finalName=$({ grep -m1 '&lt;finalName&gt;' pom.xml |  cut -d '&lt;' -f2 | cut -d '&gt;' -f2; [ ${PIPESTATUS[0]} -eq 0 ] &amp;&amp; true || echo ${pom_artifactID}-${pom_artifactVersion}.$pom_packaging}; })
  </code></pre></li>
  </ol>
  
  <p>The first doesn't work because gitlab-ci doesn't evaluate $(command), so <code>pom_artifactID</code> becomes a literal "$(grep -m1 '' pom.xml | cut -d '&lt;' -f2  |cut -d '>' -f2)" </p>
  
  <p>The second doesn't work either because "before_script" relies on the "grep" command and some docker images used in my pipeline have an old version of grep.</p>
  
  <p>There is another way to set global variables o pass variables between stages and jobs?</p>