1

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))

3 Answers 3

1

You just need to refer it as,

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

$($name1)$($name2) = 'helloworld'
Sign up to request clarification or add additional context in comments.

1 Comment

It doesn't work. ($name1)($name2) makes 'helloworld. And now I need to access value in $helloworld
0

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

7 Comments

$name1$name2 create variable name $helloworld and I want to access value of $helloworld. When I use $(helloworld) and hard code the name of that variable it works. But if I use concatenation it doesn't work
@EkaterinaGiuliani, please have a try with the command below: $name1 = "h" $name2 = "w" New-Variable -Name "${name1}${name2}" -Value 'helloword' -Force $hw
@EkaterinaGiuliani, since the comment is not so clear, so I update the answer. Please take a look.
I'm trying to access this variable from the pipeline. $name1 and $name2 are variables in pipeline that change at the run time. I want to concatenate they value to make name or another variable and then access its value
You may try to use this command: Get-Variable -Name "${name1}${name2}". If you want to access the $helloword value by expression but not by command, you can use New-Variable -Name "test" -Value (Get-Variable -Name "${name1}${name2}").Value -Force and then we can access the value via $test.
|
0

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.

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.