[Repost from the Ggroups web interface, as my email replies apparently aren't reaching the group. I hope the formatting remains sane.]
Hi Adam, yaml anchors/aliases are indeed a good way to avoid
duplication, that's an excellent suggestion, thanks!
I still think that what I was looking for still would allow for more
terse definitions in some cases, and in the meantime I noticed more
things. Interestingly this works:
- project:
name: project-name
mylist:
- foo
- bar
jobs:
- somejob-{mylist}-{x}:
x: '{mylist}'
- job-template:
name: somejob-{mylist}-{x}
and generates the two jobs:
Job name: somejob-bar-bar
Job name: somejob-foo-foo
but **only works when quoting** the string given to 'x':
- somejob-{mylist}-{x}:
x: '{mylist}'
while doing
- somejob-{mylist}-{x}:
x: {mylist}
produces the "empty OrderedDict" jobs we already encountered:
Job name: somejob-bar-OrderedDict([('mylist', None)])
Job name: somejob-foo-OrderedDict([('mylist', None)])
The documentation suggests to always use quotes ("it is good practice to
wrap the entire string in quotes, even if the rules of YAML syntax don’t
require it"), but I've been definitely been bitten here: it took a while
to figure out what was happening. Lesson learned.
This also means that what I'm looking for
*almost* works already. This:
- project:
name: project-name
mylist:
- foo
- bar
jobs:
- somejob-{x}:
x: '{mylist}'
- job-template:
name: somejob-{x}
builds the job:
Job name: somejob-['foo', 'bar']
Obviously not what I want, but I think this is only because the JJB
templating engine iterates over lists only when a list name appears in
the template name. It should iterate even when a list is passed to a
variable that is in the template name ('x' in the example above). I'll
have a look at the code :-)
Paride