Expanding Environment Variables
<p><a href="https://www.linkedin.com/in/daolam">Dao Lam</a>, Software Engineer, Verizon Media</p>
<p>Previously, Screwdriver users had to rely on string substitutions or create a step to export variables to get environment variables evaluated. For example:</p>
<pre><code>RESTORE_STATEFILE=`echo ${RESTORE_STATEFILE} | envsubst '${SD_ARTIFACTS_DIR}'`
</code></pre>
<p>Or</p>
<pre><code>steps:
- export-env: export RESTORE_STATEFILE=${SD_ARTIFACTS_DIR}/statefile
</code></pre>
<p>With this change, users can now expand environment variables within the “environment” field in screwdriver.yaml like below:</p>
<pre><code class="yaml"><br/>jobs:
main:
image: node:10
environment:
FOO: hello
BAR: "${FOO} world"
steps:
- echo: echo $BAR # prints “hello world”
requires: [~pr, ~commit]
</code></pre>
<p><!-- more --></p>
<h2>Setting default cluster environment variables (for cluster admins)</h2>
<p>Cluster admins can now set default environment variables to be injected into user builds. They can be configured in the <a href="https://github.com/screwdriver-cd/screwdriver/tree/master/config">API config</a> under the field <code>builds: { environment: {} }</code> or via <code>CLUSTER_ENVIRONMENT_VARIABLES</code>. Read more about how to configure the API <a href="https://docs.screwdriver.cd/cluster-management/configure-api.html">here</a></p>
<h2>Order of evaluation</h2>
<p>Environment variables are now evaluated in this order:</p>
<ul><li><p>User secrets</p></li>
<li><p>Base ENV set by launcher such as <code>SD_PIPELINE_ID</code>, <code>SD_JOB_ID</code>, etc.</p></li>
<li><p>Cluster ENV set by cluster admin</p></li>
<li><p>Build ENV set by user in screwdriver.yaml environment field</p></li>
</ul><h2>Important note when pulling in this feature</h2>
<p>This new version of API <code>v0.5.677</code> needs to be pulled in together with the new version of LAUNCHER <code>6.0.1</code> because it includes a breaking change (GET /v4/builds now returns environment as an array to ensure in-order evaluation inside launcher). Please schedule a short downtime when pulling this feature into your cluster to ensure the API and LAUNCHER are on compatible versions.</p>
<p>The versions working before this change would be: API (v0.5.667) and launcher (v5.0.75)</p>
<h2>Compatibility List</h2>
<p>In order to use this feature, you will need these minimum versions (please read the note above):</p>
<ul><li><p>[API] (<a href="https://hub.docker.com/r/screwdrivercd/screwdriver">https://hub.docker.com/r/screwdrivercd/screwdriver</a>) - v0.5.677</p></li>
<li><p>[LAUNCHER] (<a href="https://hub.docker.com/r/screwdrivercd/launcher">https://hub.docker.com/r/screwdrivercd/launcher</a>) - v6.0.1</p></li>
</ul><h2>Contributors</h2>
<p>Thanks to the following contributors for making this feature possible:</p>
<ul><li><a href="https://github.com/d2lam">d2lam</a></li>
</ul><h2>Questions & Suggestions</h2>
<p>We’d love to hear from you. If you have any questions, please feel free to reach out <a href="https://docs.screwdriver.cd/about/support">here</a>. You can also visit us on <a href="https://github.com/screwdriver-cd">Github</a> and <a href="https://slack.screwdriver.cd">Slack</a>.</p>