# Recursive variable expansion

**URL:** https://www.finalbuilder.com/forums/t/recursive-variable-expansion/5585
**Category:** Discussion
**Created:** [August 30, 2017, 9:14am UTC](https://www.finalbuilder.com/forums/t/recursive-variable-expansion/5585 "2017-08-30T09:14:48Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![rynardald](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/r/a88e57/32.png) [@rynardald](https://www.finalbuilder.com/forums/u/rynardald)
#### Post date: [August 30, 2017, 9:14am UTC](https://www.finalbuilder.com/forums/t/recursive-variable-expansion/5585/1 "2017-08-30T09:14:48Z")

</div>

Hi,  
I want to create the name of a variable dynamic during the build and want evaluate it then. Is it possible in Continua to evaluate a variable recursive (like in FinalBuilder)?

---

<div class="post-metadata">

### Author: ![Sparky](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/sparky/32/10_2.png) [@Sparky](https://www.finalbuilder.com/forums/u/Sparky)
#### Post date: [August 31, 2017, 5:34am UTC](https://www.finalbuilder.com/forums/t/recursive-variable-expansion/5585/2 "2017-08-31T05:34:39Z")

</div>

Hi Albrecht,  
  
If a variable is defined as type Expression then any expression in the value is evaluated when the variable is used. This works recursively.  
  
e.g. If you have the following variables&nbsp;  
  
TextVar1 (type: text) = "abc"  
ExpressionVar1 (type: expression) = "%TextVar1%"  
ExpressionVar2&nbsp;(type: expression)&nbsp;= "%ExpressionVar2%"  
  
and a Log Entry action with the following Messages(s):&nbsp;  
  
TextVar1=%ExpressionVar1%  
ExpressionVar1=%ExpressionVar1%  
ExpressionVar2=%ExpressionVar2%  
  
The build log will show as follows:  
  
12:19:12 PM Log Entry [Information]  
12:19:12 PM&nbsp; &nbsp; &nbsp;&nbsp;TextVar1=abc  
12:19:12 PM&nbsp; &nbsp; &nbsp;&nbsp;ExpressionVar1=abc  
12:19:12 PM&nbsp; &nbsp; &nbsp;&nbsp;ExpressionVar2=abc  
  
Note however that expression variables are read-only can cannot be changed at run-time.  
  
You can however use the Set Variable action to expand an expression and store the result as the value of a text variable.  
  
e.g. If you have the following text variables&nbsp;  
  
TextVar1 = "abc"  
TextVar2 = ""

  
and a Set Variable action with the following properties:  
  
Variable: TextVar2  
Operation: Replace  
New Value: "%TextVar1%"  
Expand variable references in new value: True  
  

The build log will show as follows:  
  
12:22:28 PM Set Variable [TextVar2]  
12:22:28 PM&nbsp; &nbsp; &nbsp;&nbsp;Variable ‘%TextVar2%’ has been set to ‘abc’.  
  
I’m not sure if this is exactly what you are looking for. If not can you post more details of your use case.

---

<div class="post-metadata">

### Author: ![rynardald](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/r/a88e57/32.png) [@rynardald](https://www.finalbuilder.com/forums/u/rynardald)
#### Post date: [August 31, 2017, 6:45am UTC](https://www.finalbuilder.com/forums/t/recursive-variable-expansion/5585/3 "2017-08-31T06:45:27Z")

</div>

Hi Dave,   
 I tried to build the variableName which should be executed dynamic, but with no success.   
 Scenario:   
 Variables:   
 File1\_Name=“TestFile1”   
 File1\_Comments=“File1Comments”   
 File2\_Name=“TestFile2”   
 File2\_Comments=“File2Comments”   
  
 Now I want to iterate with a for-each-loop over the values “File1” and “File2”. In this loop i need a variable called FileName and one called FileComments. FileName should evaluate “%%IteratorVariable%\_Name%” and FileComment should evaluate “%%IteratorVariable%\_Comments%”. The effect of this should be that the value for FileName is in the first iteration “TestFile1” and for FileComment “File1Comments” and in the second iteration “TestFile2” and “File2Comments”.   
 Is this possible?

---

<div class="post-metadata">

### Author: ![Sparky](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/sparky/32/10_2.png) [@Sparky](https://www.finalbuilder.com/forums/u/Sparky)
#### Post date: [August 31, 2017, 7:14am UTC](https://www.finalbuilder.com/forums/t/recursive-variable-expansion/5585/4 "2017-08-31T07:14:32Z")

</div>

Hi Albrecht,  
  
Unfortunately, it is not possible to expand a nested variable name within another variable name in Continua CI. Although we are doing some work on the expression engine in the background, this is unlikely to be part of this for some time.   
  
We recommend calling a FinalBuilder (or PowerShell) script for more complex tasks like this. Note that you can pass the variables to the script then write the results back to Continua CI variables using the Continua CI actions in FinalBuilder or the via [Custom Log Messages](http://wiki.finalbuilder.com/x/BoBU)in other scripts.
