SagiLow
SagiLow

Reputation: 6049

How to use secret task variables with npm tasks

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?

Upvotes: 0

Views: 1945

Answers (2)

Sebastien GISSINGER
Sebastien GISSINGER

Reputation: 676

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

Upvotes: 1

4c74356b41
4c74356b41

Reputation: 72201

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

Upvotes: 1

Related Questions