0

I've defined Variable Group which downloads secrets from Key Vault.
Looks like that unlike other variables, secrets aren't set automatically as environment variables.
I've tried using a bash script to take those 'task variables' and set them as environment variables but they were gone by the next task:

export ENV1=$(someSecretTaskVariable)

I'm using npm task which can't be provided with environment variables via the UI and the yaml is read only.

How should this be done?

SagiLow
  • 5,721
  • 9
  • 60
  • 115

2 Answers2

1

I dont think you can do this via UI, but via yaml you would do this:

- task: xxx
  env:
    ENV1=$(someSecretTaskVariable)

apparently you can do this:

Unlike a normal variable, they are not automatically decrypted into environment variables for scripts. You can explicitly map them in, though.

To pass a secret to a script, use the Environment section of the scripting task's input variables.

seems like with UI you can only do this with scripting tasks

https://learn.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=classic%2Cbatch#secret-variables

4c74356b41
  • 69,186
  • 6
  • 100
  • 141
1

If you want to create an environment variable that is passed to subsequent Azure DevOps tasks, maybe try this :

echo '##vso[task.setvariable variable=ENV1]$(someSecretTaskVariable)'

instead of export ENV1=$(someSecretTaskVariable)

Set variables in scripts