There are cases where I'd like to use an expression - e.g. when passing a variable - I'd like to coalesce it. I couldn't find how to do it until I was told that I can use coalesce in variable definition usin the $[ ] syntax.
Can they only be used in conditions and variable definitions? What is the $[ ] syntax and what does it mean? Is this in any way related to the logging commands?
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
This is going to be a challenging one to write and keep updated, but I agree it's important.
Hi.
Is it possible to use expressions in Variable groups in Azure DevOps Pipelines? I am struggling to find any documentation for this topic.
I've not forgotten this one, it's just a big dig that I haven't had time to invest in. Sorry 😞
Thanks for your question. It looks like your question isn't an issue with the documentation, but an issue or question specific to your implementation or a bug in the product itself.
For help with a specific task, here are a couple of options where you might consider asking your question:
If you've encountered an issue with the product itself, to make sure it gets in front of the right people, please submit your bug here.
If you have an idea for improving the product, please submit your idea here.
@mijacobs I don't understand why you would say it's not an issue with the documentation? It was previously approved by @vtbassmatt as one.
It's about documenting the $[ ] syntax.
Can this only be used in conditions and variable definitions?
What is the $[ ] syntax and what does it mean?
Is this in any way related to the logging commands?
My apologies, this was closen by mistake. Reopening.
I would agree that having a more complete explanation of where the $[] syntax is (and is not) valid would improve these docs greatly.
Can someone put an example in this issue which can be used as a reference until the docs are update. At the moment i try
- stage: stage_name
displayName: Stage name
variables:
containerRepoDst: $[coalesce('${{ parameters.A}}', '${{ parameters.B}}')]
and it doesn't resolve right
@orhanmaden the $[ ] syntax basically says "defer this calculation as long as possible into runtime" while ${{ }} says "perform this calculation during template expansion time". I would have to see the rest of your pipeline to understand what you're trying to achieve. Let's assume that you get an empty string passed in for parameter A and the word foo passed in for parameter B. After template expansion but before runtime, this snippet would read:
- stage: stage_name
displayName: Stage name
variables:
containerRepoDst: $[coalesce('', 'foo')]
Then at runtime, I expect we would resolve the $[] to the word foo.
@vtbassmatt Going back to the original question in this thread, where can the $[] syntax be used? Anywhere in the pipeline YAML (eg in a parameter for a template or task)
More or less, variables and conditions (and in conditions, you don't actually write the $[]) are it. There are a few miscellaneous other properties that allow runtime expressions and we're looking at expanding that set, but it's a rather arbitrary grouping right now and I don't recommend it.
Ok so this means that runtime expressions can’t be used in step templates as there’s no ability to have variables in them (unlike jobs and stages)
It would be great if they could just be used anywhere (like compile time expressions) but for the meantime can you update the documentation to make this explicitly clear that they can’t be used in most places.
@vtbassmatt, @juliakm -- please look into this issue.
variables and conditions (and in conditions, you don't actually write the $[]) are it
Thank you! That simple sentence is so much more clear than the official documentation, which simply states that "runtime expressions are more limited".
@juliakm I think you have this on your backlog already. If you want my input, we can chat offline.
I've added an example and text that runtime expressions can be used in variables and conditions. I hope this clears up some confusion.
I've added an example and text that runtime expressions can be used in variables and conditions. I hope this clears up some confusion.
Hi, where exactly is an example please? :-) Thank you.
I've added an example and text that runtime expressions can be used in variables and conditions. I hope this clears up some confusion.
Hi, where exactly is an example please? :-) Thank you.
@neustupa The changes are published in this article linked to this GitHub issue:
Expressions - Azure Pipelines
Here is the commit with the exact changes in the public repo, you should be able to see exactly what was changed to help answer this question:
https://github.com/MicrosoftDocs/azure-devops-docs/commit/d310b1010e0ff9fe34e1ebf70bde7bd975a5277a#diff-401551f579489edc5dca5a56e7250531
Most helpful comment
@mijacobs I don't understand why you would say it's not an issue with the documentation? It was previously approved by @vtbassmatt as one.
It's about documenting the $[ ] syntax.
Can this only be used in conditions and variable definitions?
What is the $[ ] syntax and what does it mean?
Is this in any way related to the logging commands?