title: Jenkins pipeline : templating a file with variables
body: <p>I have a pipeline job that treats a template file (e.g. an XML file) and needs to replace some variables from the file with job parameters before using the rendered file, but I can't seem to find anything clean to do that, for now I'm just using shell script and sed to replace each variable one by one.</p>
  
  <p>Here is an example XML template file :</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8'?&gt;
  &lt;rootNode&gt;
      &lt;properties&gt;
          &lt;property1&gt;${property1}&lt;/property1&gt;
          &lt;property2&gt;${property2}&lt;/property2&gt;
          &lt;property3&gt;${property3}&lt;/property3&gt;
      &lt;/properties&gt;
  &lt;/rootNode&gt;
  </code></pre>
  
  <p>I would like the "variables" in my template file to be replaced with my job parameters <code>$property1</code>, <code>$property2</code> and <code>$property3</code>.
  Here is what I'm doing today :</p>
  
  <pre><code>sh  "sed -i 's/@property1@/${property1}/' '${templateFile}'" +
      "sed -i 's/@property2@/${property2}/' '${templateFile}'" +
      "sed -i 's/@property3@/${property3}/' '${templateFile}'"
  </code></pre>
  
  <p>... but I find it quite ugly... is there anything in Jenkins for templating files such as what <a href="http://jinja.pocoo.org/docs/dev/" rel="noreferrer">Jinja2</a> (or any templating framework) would do ?</p>