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
variables:
- group: databaseCredentials
steps:
- script: |
set -x
export POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
Below is my secret yaml file, secret.yaml:
apiVersion: v1
kind: Secret
metadata:
name: mysecret
type: Opaque
data:
postgres-password: ${{POSTGRES_PASSWORD}}
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.
If you want to modify your yaml file you may use Token replace task . It will allow you to replace token in file with your variable values.
Here you have example usage:
- task: replacetokens@3
inputs:
targetFiles: 'yourfile.yaml'
encoding: 'auto'
writeBOM: true
actionOnMissing: 'warn'
keepToken: false
tokenPrefix: '#{'
tokenSuffix: '}#'
useLegacyPattern: false
enableTelemetry: true
and you file should be:
apiVersion: v1
kind: Secret
metadata:
name: mysecret
type: Opaque
data:
postgres-password: #{POSTGRES_PASSWORD}#
And then you don't need this:
steps:
- script: |
set -x
export POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
Unless there is no other place where you want to use this env variable.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.