[OpenStack-Infra] jenkins-job-builder: passing lists as variables / YAML anchors and aliases?
Michael Prokop
openstack.org at michael-prokop.at
Tue Feb 11 10:14:35 UTC 2014
Hi,
in my jenkins-job-builder configurations I would like to have one
single place where I specify global defaults, then overwrite values
only as needed in the according projects/jobs.
This somewhat works with YAML anchors and aliases (see
http://pyyaml.org/wiki/PyYAMLDocumentation#Aliases - thanks to
Antoine Musso for pointing me there!), where you can use for example
"&repos" for assigning a new variable and then "*repos" for
referring to it:
,---- [ simple example ]
| - defaults:
| name: global
| repos: &repos
| - 'git://git.example.org/foo'
|
| # here we use the default repos:
| - project:
| name: test_job1
| repos: *repos
|
| # here we do NOT use the default repos:
| - project:
| name: test_job2
| repos: 'git://git.example.org/bar'
| [...]
|
| # finally we use/refer to the repos variable:
| - job-template:
| name: '{name}-source'
| project-type: matrix
| scm:
| - git:
| url: '{repos}'
| [...]
`----
This also works for lists containing more than one value ("&distri"
and "*distri" here):
,---- [ distri.yaml ]
| - project:
| name: test_distri
| distributions: &distri
| - precise
| - jessie
| jobs:
| - '{name}-source'
|
| - job-template:
| name: '{name}-source'
| project-type: matrix
| axes:
| - axis:
| type: user-defined
| name: distribution
| values: *distri
`----
The resulting config.xml looks as expected:
,---- [ config.xml as resulting from distri.yaml ]
| <axes>
| <hudson.matrix.TextAxis>
| <name>distribution</name>
| <values>
| <string>precise</string>
| <string>jessie</string>
| </values>
`----
But: I don't want to use the same distributions in all the jobs.
Sadly the approach from my simple example above doesn't work here,
because I need to pass the distribution list as-is down to the
job-template (it's no longer a simple string as for '{repos}' from
the example above).
Sadly re-using the same anchors/aliases names isn't possible
("yaml.composer.ComposerError: found duplicate anchor ..."),
otherwise the solution would be as simple as:
,---- [ fail.yaml ]
| - project:
| name: custom1
| distributions: &a
| - precise
| - jessie
| jobs:
| - '{name}-source'
|
| - project:
| name: custom2
| distributions: &a
| - bla
| - baz
| jobs:
| - '{name}-source'
|
| - job-template:
| name: '{name}-source'
| project-type: matrix
| axes:
| - axis:
| type: user-defined
| name: distribution
| values: *a
`----
So I need another way how to pass a *list* as data structure from
the defaults/project down to the job-template definition, similar to
what can be done with "{variable}" for strings.
Something like that would come close to what I would need:
,---- [ custom_distri.yaml ]
| - project:
| name: test_custom_distri
| distributions: !!python/tuple [precise, jessie]
| jobs:
| - '{name}-source'
|
| - job-template:
| name: '{name}-source'
| project-type: matrix
| axes:
| - axis:
| type: user-defined
| name: distribution
| values: '{distributions}'
`----
But this does NOT generate what I actually want:
,---- [ config.xml as resulting from custom_distri.yaml ]
| <axes>
| <hudson.matrix.TextAxis>
| <name>distribution</name>
| <values>
| <string>(</string>
| <string>'</string>
| <string>p</string>
| <string>r</string>
| [...]
`----
So the "distributions" variable isn't passed as-is. :(
I've put my YAML test files online so you can run them through
"jenkins-jobs test -o $outputdir $file.yaml" on your own:
custom_distri.yaml: https://gist.github.com/mika/8fab6a390cfb96aaf952
distri.yaml: https://gist.github.com/mika/85047c872251abfc4846
fail.yaml: https://gist.github.com/mika/54bc7eaceddce1823332
I've also put a more complete example (including notes of what I
already tried to pass the list as-is) online:
https://gist.github.com/mika/855dfc96d2e4bd44c10c
Any ideas how to properly pass a list of values down to the job-template?
regards,
-mika-
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: Digital signature
URL: <http://lists.openstack.org/pipermail/openstack-infra/attachments/20140211/4b376bc9/attachment.pgp>
More information about the OpenStack-Infra
mailing list