Search code examples
azure-devopsazure-pipelinesazure-yaml-pipelines

Azure DevOps Pipeline - Use previously defined variables in variable definition


I don't know if there's a way to use previously defined variables in variable definition. Basically I want to do something like this:

variables:
- name: basePath
  value: \\somepath
- name: servicePath
  value: $(basePath)\servicePath
- name: backupPath
  value: $(basePath)\backups

The later variables don't recognize basePath. Is there a different syntax I can use?


Solution

  • We do something similar, here's what we have in our yaml:

      - name: cdn-base
        value: 'https://cdn-name.azureedge.net'
      - name: 'CDN_URL'
        value: '$(cdn-base)/$(site-name)-$(environment)/'
      - name: NODE_MODULES_CACHE_FOLDER
        value: $(System.DefaultWorkingDirectory)/node_modules
    

    Might just need to wrap your strings in quotes. Also check your agent type because it might be you using windows path separator on a linux agent.