4
votes

I have a release pipeline with a variable, but there doesn't seem to be any way to set the value of that variable to something that's evaluated at release time. For example, another variable.

Here's a real example:

enter image description here

All I want to do is set the value of MyExpressionBasedVariable to the value of MyOtherVariable.

All the docs and examples online seem to suggest it's possible, but I can't get it to work. I always end up with the literal string rather than the evaluated value.

I've tried using these different syntaxes:

  • $(MyOtherVariable)
  • $[variables['MyOtherVariable']]
  • ${{variables['MyOtherVariable']}}

I've seen that you can define custom tasks to set variable names as part of the pipeline but this seems massively overkill.

Essentially all I want to do is rename a key vault secret to a different variable name for convention-based XML variable replacement in config files.

E.g. I have a secret called this-is-a-secret-name-which-is-a-different-naming-convention-to-my-connectionstrings but I need it in a variable called MySecret-ConnectionString.

How do I use the value of another variable in a release pipeline variable?

1
You shouldn't have to do anything special. Foo = $(Bar) and Bar = Baz will result in Foo = Baz. It could have something to do with your usage of the variables. Can you update your question with actual usage?Daniel Mann
That’s what I thought but it doesn’t work as far as I can tell. Does that only work for build pipelines rather than release or should it be the same?theyetiman
It's the same. I do it all the time. I'm working on release definitions right now that do this.Daniel Mann
Hmm. Ok. Not sure what I’m doing wrong. Could it be that I’m using a variable from a variable group where I have the tick box enabled for allowing access to all pipelines? I.e it’s kind of inherited and not explicitly imported into the pipeline?theyetiman
@DanielMann after some playing around I can confirm that's what it is! If I "link" the variable group in the pipeline, it works. If I "unlink" the variable group it stops working and I just get the literal name $(MyOtherVariable), even though I can use the same variable directly within pipeline tasks - it just doesn't work within the pipeline variables screen. Facepalm.theyetiman

1 Answers

2
votes

How do I use the value of another variable in a release pipeline variable?

As I test, what you set should be work. You can try to follow below steps to check if you still have this issue:

  • Create a new release pipeline without link any variable group.
  • Set the Variable like following:

    enter image description here

  • Add a Run Inline Powershell task to output the value of the Variable:

    Write-Output 'The value of MyExpressionBasedVariable is $(MyExpressionBasedVariable)'
    
    Write-Output 'The value of $(MyOtherVariable) is $(MyOtherVariable)'
    

Then we could get the log:

enter image description here

So, what you set should be work, if this still does not work for you, then you need to make sure that the variable you describe in the question is the variable your actual test.

Besides, at this moment, the value of nested variables (like $(TestVar_$(Release.Reason))) are not yet supported in the build/release pipelines, check this thread for some details, so make sure there are no such nested variables in your project.

Hope this helps.