Is there an index token in the Repetition statement of the Variable Substitution Syntax?

According to the documentation at http://docs.octopusdeploy.com/display/OD/Variable+Substitution+Syntax, a variable can be used to perform a repetition of substitutions but there is no way to obtain a position or index value to use during the iteration. So lets say I have the following variable:

Name: URLs
Value: www.google.com,www.yahoo.com,www.bing.com

And given the following transformation:

<URLs>
#{each url in URLs}
    <add key="**#{index}**" value="#{url}" />
#{/each}
</URLs>

I would expect an ouput like:

<URLs>
    <add key="0" value="www.google.com" />
    <add key="1" value="www.yahoo.com" />
    <add key="2" value="www.bing.com" />
</URLs>

Is there such a placeholder that could be used for this purpose?

Hi Rmardeni,

Thanks for getting in touch! You can use the Iterating over sets of values feature outlined in that document. In your case, you variables would look something like this:

Name                   Value
Urls[1].Value         www.google.com 
Urls[2].Value         www.yahoo.com

And the transformation:

<URLs>
#{each url in Urls}
    <add key="#{url}" value="#{url.Value}" />
#{/each}
</URLs>

Hope that helps!

Robert W

Hi Robert,

Thanks for the reply, I had not noticed that the value between parenthesis was available; however this approach yields a large number of variables in the context that I am using it.

I have 4 URLs that are different per environment and we have a total of 13 different environments, so this approach requires a total of 52 variables instead of just 13 variables.

I noticed that OctoStache uses the Sparce library and that there are other values that could be made available for the purpose of transformations to have more flexibility like the one I am mentioning. I will add it as a suggestion to the roadmap.

Hi Rmardeni,

Is there some sort of pattern to the URLs? For example you could have the variables:

Name                   Value                                                            Scope
Customer              alice                                                            Test
Urls[1].Value         #{Customer}.foo.com 
Urls[2].Value         #{Octopus.Environment.Name}.foo.com

Robert W

Certainly not something I can use to greatly reduce the number of variables.