0

I'm pulling my hair out trying to get some very basic iteration working using non-execution set variables (ie setting things at Global with potential to override at lower scope).

Setting a $variable to some value works fine but I need to do something like...

foreach $DeployConfigKey in @MapKeys(%DeployConfigs)
{
  ...
}

So far I'm getting nowhere fast with execution errors saying "Invalid value for property Map; expected map."

Further doing something like set %executionvar = %DeployConfigs complains that a map cannot be set to a scaler value.

The variable, DeployConfigs looks like ...

%{"Web.config": ["Web.Beta.config", "Web.Release.config"]}

and is defined at Global scope.

What am I doing wrong?

I'm using buildmaster 5.7.3

Mattl404
  • 23
  • 3

1 Answers1

1

Maps are specified as %(key: value), here is an example plan that should help:

set %map = %(Web.config: @("Web.Beta.config", "Web.Release.config"));

foreach $key in @MapKeys(%map)
{
    set @values = %map[$key];
    Log-Information `$key = $key;
    Log-Information `@values = $Join(", ", @values);
}

Sleep 3;
John Rasch
  • 62,489
  • 19
  • 106
  • 139
  • Perfect! I I think I realize where I went wrong. When I first set the value for the global variable I had it like `%("Web.config": @("Web.Beta.config", "Web.Release.config"));` This gave an Invalid key name: "Web.config". So I tried using {} which I thought I'd seen somewhere and it atleast submitted without error. I see now that doing so just make the variable a scalar. Regardless I do think there could be better examples maybe some recipes for common code scenarios. Also a validator on setting variable value that checks for % or @ at character 0 if value appears to be a string. – Mattl404 Nov 10 '17 at 21:39