3

In azure devops, inside the classic build, I can generally do $(myVar) to get the value of a variable in certain places. I am not sure if that particular usage has a name.

Is there a way to pass an expression for the same use cases. I mean instead of $(myVar) can I do something like $(coalesce(myVar, otherVar))? I have tried wrapping it in different brackets, doesn't seem to work.

I have checked the docs here: https://learn.microsoft.com/en-us/azure/devops/pipelines/process/expressions?view=azure-devops

It doesn't show how to use in the classic pipelines, only yaml.

3 Answers 3

3

Is there a way to pass an expression for the same use cases. I mean instead of $(myVar) can I do something like $(coalesce(myVar, otherVar))?

Agree with Daniel, the common use of Expressions is to define conditions for a step, job, or stage or define variables. The expressions work well in Yaml pipelines while it's not supported in Classic pipelines if you want to define variables using $(coalesce(myVar, otherVar)) instead of $(myVar).

The $(coalesce(...))is one of the built-in functions. The only working scope of those functions in classic pipelines is conditions for Job/Task, see:

Job:

enter image description here

Task:

enter image description here

But it seems you're trying to use built-in functions when defining variables, for now that's not supported in classic pipelines. Those can only be used to define/control the conditions for job/task in classic pipelines.

Sign up to request clarification or add additional context in comments.

2 Comments

Yeah this makes sens. I too was using custom conditions as a work around. it just adds more tasks. Which is why I was trying use an inline expression.
Didn't realize you could use custom condition in tasks too. That really simplified the process, so I am marking this as the answer. I'll look more into YAML in future
1

Expressions as outlined in the documentation you linked only apply to YAML. You won't be able to do what you want to do unless you use YAML.

1 Comment

Odd. I have used it in certain places in the classic definitions as well.
1

While using expressions in classic pipelines is not supported (except in the control section of the task), I've had success defining a release variable with the expression, and using that release variable instead.

In my case I wanted to do releases based on git tags, and extract the version number from the tag.

Variable definition (with the expression I want to use):

enter image description here

Using the variable in the task:

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.