azure-pipelines-agent: [YAML] Support for variables is inconsistent in template expressions

Trying to use system variables inside a template expression in a reusable step generates syntax errors in some cases but works in others. I cannot see any differences between the syntax being used.

Have you tried trouble shooting?

Tried variations and the request keeps failing

Agent Version and Platform

Version of your agent? 2.102.0/2.100.1/…

OS of the machine running the agent? Windows

VSTS Type and Version

VisualStudio.com or On-Prem TFS? VSTS

If VisualStudio.com, what is your account name? http://fsmb.visualstudio.com

What’s not working?

When trying to queue a build I get the following error - Unrecognized value: ‘$’. Located at position 40 within expression: coalesce(parameters.testAdapterFolder, $(System.DefaultWorkingDirectory)). For more help, refer to https://go.microsoft.com/fwlink/?linkid=842996

The template in question.

parameters:
   searchFolder: ''   
   
steps:
- task: VSTest@2
  displayName: Test Assemblies
  inputs:
     testSelector: testAssemblies
     searchFolder: '${{ coalesce(parameters.searchFolder, $(System.DefaultWorkingDirectory)) }}'

But in another template used by the same build I don’t get any errors and it executes properly.

parameters:
   sourceFolder: ''   

steps:
- task: DeleteFiles@1
  displayName: Delete package solutions
  inputs:
     sourceFolder: '${{ coalesce(parameters.sourceFolder, $(Build.SourcesDirectory)) }}\packages'
     contents: '**/*.sln'

Changing variables doesn’t have any impact. Changing the $() reference to simply ‘’‘’ works. Changing to variables[‘‘System.DefaultWorkingDirectory’’] changes the error to

Unexpected null value,vstest-standard.yml (Line: 27, Col: 32): Unexpected null value

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 17 (9 by maintainers)

Most upvoted comments

Hi everyone. I’m still have troubles with clarifying what quotes where to use and how expressions and variables work in templates. It is nonsense, it just like playing blindly in lottery. I have no chance to know when and in witch order all these tricks parsed. Using yaml is awful, terrible part of my life. This is so hard not userfriendly!

Sorry, I forgot system.defaultworkingdirectory is defined only on the agent side. All of the template expansion stuff happens on the server when the pipeline is initialized.

The following example will coalesce with the string value, which contains a macro (and macros are delay-expanded)

steps:
-task: VSTest@2
 inputs:
    searchFolder: "${{ coalesce(parameters.searchFolder, '$(System.DefaultWorkingDirectory)') }}"

Hopefully this helps some.