<p>I am creating a pipeline to deploy a application , I have created variable group for database password in azure pipeline and want to use the password values in separate yaml which use to deploy application.
azure-pipeline.yml</p>
<pre><code>variables:
- group: databaseCredentials
steps:
- script: |
    set -x
    export POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
</code></pre>
<p>Below is my secret yaml file , secret.yaml:</p>
<pre><code>apiVersion: v1
kind: Secret
metadata:
  name: mysecret
type: Opaque
data:
  postgres-password: ${{POSTGRES_PASSWORD}}
</code></pre>
<p>I want to use the env variable value in yaml file , i tried like this but it fails , i dont want to do search/replace.
Please suggest.</p>

Umesh Kumar
<p>If you want to modify your yaml file you may use <a href="https://marketplace.visualstudio.com/items?itemName=qetza.replacetokens" rel="nofollow noreferrer">Token replace task</a>. It will allow you to replace token in file with your variable values.</p>
<p>Here you have example usage:</p>
<pre class="lang-yaml prettyprint-override"><code>- task: replacetokens@3
  inputs:
    targetFiles: 'yourfile.yaml'
    encoding: 'auto'
    writeBOM: true
    actionOnMissing: 'warn'
    keepToken: false
    tokenPrefix: '#{'
    tokenSuffix: '}#'
    useLegacyPattern: false
    enableTelemetry: true
</code></pre>
<p>and you file should be:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Secret
metadata:
  name: mysecret
type: Opaque
data:
  postgres-password: #{POSTGRES_PASSWORD}#

</code></pre>
<p>And then you don't need this:</p>
<pre class="lang-yaml prettyprint-override"><code>steps:
- script: |
    set -x
    export POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
</code></pre>
<p>Unless there is no other place where you want to use this env variable.</p>
