AZURE PIPELINE pass variable from one script to another

Viewed 1204
steps:
- script: |
    # BuildConfig = production
  env:
    TEST_ONE: 123

- script: |
    echo $TEST_ONE
  displayName: 'Running npm run'

I'd like to have $TEST_ONE in the second script and I also need that TEST_ONE to be in environment variables for the second script. When I echo it in the second script, iT Prints empty instead of 123. Any clue?

2 Answers

I would not use scripts to manage your variables, otherwise anytime you need to change them, you need to be changing the scripts. And in case you use Version Control to manage changes to your pipelines, it would require commits, etc. Why don't you leverage the release variables and set scopes for your variables (so variables for master, variables for staging env, variables for all environments, etc.). And the best part is, you can manage these variables from the Azure DevOps UI. Please have a look to this article.

Edit
Since you do not want to store these variables in your environment files together with the source of your node app, then you can manage those variables on the pipeline by defining them on the variables section, and then you can send those variables as arguments to your npm script - see more here.

You can set a new variable in your powershell and then pass it to Azure Devops, so that it can be used in one of the next tasks. Here is an example

Related