Multi Stage YAML Azure Pipeline Variable Scope

Viewed 1659

I am using Multi stage Azure pipelines. Using the Classic editor I am able to set the scope for a variable but using the YAML pipeline I cannot. How is this possible using YAML Multi Stage Pipelines?

enter image description here

Here is the Classic UI where i can set the scope.

enter image description here

3 Answers

You can't. Use a variable group and link the variable group to the desired scope or store secrets in an Azure keyvault or some other secure secret store.

Actually you can, but you have to copy paste the variables in each '- stage' block.

The below method will help. In the below case I am changing in HTML file. You can use config or JSON etc. In HTML file in place of variable declare like

#{name}#

and

#{name2}#

- stage: Dev
  displayName: Deploy to Dev
  dependsOn: Build
  variables:
    name: valueDev
    name2: valueDev2
  jobs:
    - deployment: Dev
      displayName: Deploy to Dev
      environment: Dev
      strategy:
          runOnce:
            deploy:
              steps:
              - checkout: self
                clean: true
              - task: qetza.replacetokens.replacetokens-task.replacetokens@3
                displayName: 'Replace tokens in **/*.config'
                inputs:
                  targetFiles: '**/*.html'
                  tokenPrefix: '#{'
                  tokenSuffix: '}#'

- stage: Test
      displayName: Deploy to Test
      dependsOn: Dev
      variables:
        name: valueTest
        name2: valueTest2
      jobs:
        - deployment: Test
          displayName: Deploy to Test
          environment: Test
          strategy:
              runOnce:
                deploy:
                  steps:
                  - checkout: self
                    clean: true
                  - task: qetza.replacetokens.replacetokens-task.replacetokens@3
                    displayName: 'Replace tokens in **/*.config'
                    inputs:
                      targetFiles: '**/*.html'
                      tokenPrefix: '#{'
                      tokenSuffix: '}#'
Related