Ekaterina Giuliani
Ekaterina Giuliani

Reputation: 31

Azure pipeline concatenating variable names and accessing new variable value

In my Azure pipeline I have 2 vairables $name1 = hello $name2 = world. Those variable value change at run time.

I can concatenate those 2 variable value which will create $helloworld variable.

How do I access $helloworld value? $Helloworld variable is also declared in the pipeline

I'm trying to pass the value of this variable as an argument to the powershell

The following doesn't seem to work $($(name1)$(name2))

Upvotes: 1

Views: 10144

Answers (3)

Levi Lu-MSFT
Levi Lu-MSFT

Reputation: 30383

Azure pipeline concatenating variable names and accessing new variable value

AFAIK, this issue is about nested variables rather than the concatenate variable.

As you test, you can get the helloworld by the ($name1)($name2), but we could not access value in $helloworld by the nested variable $($(name1)$(name2)).

That is because the value of nested variables (like $($(name1)$(name2))) are not yet supported in the build pipelines at this moment.

You could add your request for this feature on our UserVoice site (https://developercommunity.visualstudio.com/content/idea/post.html?space=21 ), which is our main forum for product suggestions.

Hope this helps.

Upvotes: 0

Hury Shen
Hury Shen

Reputation: 15754

You may use $helloworld = "$name1 $name2", please have a try.

The update:

Please have a try with the commands below:

$name1 = "h" 
$name2 = "w"

New-Variable -Name "${name1}${name2}" -Value 'helloword' -Force

$hw

Upvotes: 0

Sajeetharan
Sajeetharan

Reputation: 222720

You just need to refer it as,

Let's say you had $name1 = 'hello' and $name2 = 'world'.

$($name1)$($name2) = 'helloworld'

Upvotes: 1

Related Questions