I'm looking for a way to allow some instances of a jjb job-template
to add additional parameters, or add them via an inherited child template.
The same thing really applies to any array/list/sequence-valued key. Instead of overriding the whole key, I want to append to it. Possibly some 'n' levels deep, needing something like YAML anchors and merge-keys.
So either:
- A
project
that instantiates ajob-template
can add its own extraparameters:
; or - A
job-template
that inherits / extends anotherjob-template
can add extra parameters without overriding the already specified ones.
I want a working version of this:
- job-template: &base-template
name: base-params
parameters:
- string:
name: foo
default: FOO
description: Foofoo
- project:
name: thing
jobs:
- more-params
parameters:
- !APPEND # This is wrong
- string:
name: bar
default: BAR
description: Baaaa
or this:
- job-template: &base-template
name: base-params
parameters:
- string:
name: foo
default: FOO
description: Foofoo
- job-template:
name: more-params
<< : *base-template
parameters:
- !APPEND # This is wrong
- string:
name: bar
default: BAR
description: Baaaa
- project:
name: thing
jobs:
- more-params
or this:
- job-template: &base-template
name: base-params
parameters: &base-template-parameters
- string:
name: foo
default: FOO
description: Foofoo
- job-template:
name: more-params
<< : *base-template
parameters:
- << &base-template-parameters # THIS IS WRONG
- string:
name: bar
default: BAR
description: Baaaa
- project:
name: thing
jobs:
- more-params
I looked at making a child job-template
with YAML inheritance, then using that in the project. But that doesn't look like it'll work because yaml doesn't have a way to extend/append sequences/lists. Merge keys don't work for lists and the yaml spec doesn't plan on accepting anything like them; in fact, merge keys are being gently deprecated.
JJB itself doesn't appear to offer a way to say "this job-template extends this other job-template, and you should merge the parameters:
lists". It relies on YAML inheritance, implemented in JJB itself not the YAML reader, but doesn't have a (findable/documented) list equivalent.
I suspect it may be possible with !j2
Jinja2 tags, but I'm not at all sure how, or if it's sensible to go that way.
Surely this is a common need? I had similar issues with Ansible some time ago.
The only way I found to do it so far is with snippets in include files, which is ugly as hell, like (untested)
# File base-template-params.yml.inc
- string:
name: foo
default: FOO
description: Foofoo
# File templates.yml
- job-template: &base-template
name: base-params
parameters:
!include base-template-params.yml.inc
- job-template:
name: more-params
<< : *base-template
parameters:
!include base-template-params.yml.inc
- string:
name: bar
default: BAR
description: Baaaa
- project:
name: thing
jobs:
- more-params