Default Parameters Plus Per-Job Parameters

69 views
Skip to first unread message

Brian Auron

unread,
Feb 18, 2020, 1:15:59 PM2/18/20
to jenkins-job-builder
Is there a way to have a set of default parameters on a set of job(-templates) but also include special parameters for special jobs?

For example:

job-template:
  name: a
  parameters: '{default_parameters}'
job-template:
  name: b
  parameters: '{default_parameters}'
job-template:
  name: c
  parameters: '{default_parameters}{special_parameters}' # Or some way to update default_parameters here

Thanks!

Thanh Ha

unread,
Feb 18, 2020, 4:09:53 PM2/18/20
to Brian Auron, jenkins-job-builder
Hi Brian,

Not sure if I fully understand the question so let me ask a clarifying question. Do you mean you want to concatinate the variables?

So for example:

default_parameters: -f dir/pom.xml
special_parameters: -X

Thusly the result of example C would be:

parameters = -f dir/pom.xml -X

If so you can have multiple variables in a job-template field similar to what you have listed. Here's a fully working example that I just tested myself:

- defaults:
   name: global
   default_parameters: -f dir/pom.xml
   special_parameters: -X

- job-template:
   name: test
   parameters:
     - string:
         name: mvn_params
         default: '{default_parameters} {special_parameters}'

- project:
    name: test
    jobs:
      - test

Which resulted in this XML:

        <hudson.model.StringParameterDefinition>
          <name>mvn_params</name>
          <description/>
          <defaultValue>-f dir/pom.xml -X</defaultValue>
        </hudson.model.StringParameterDefinition>

Hope this helps,
Thanh

--
You received this message because you are subscribed to the Google Groups "jenkins-job-builder" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkins-job-bui...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkins-job-builder/62fce634-1b79-4c85-a5c3-16a1626ac75d%40googlegroups.com.

Brian Auron

unread,
Feb 18, 2020, 4:37:42 PM2/18/20
to jenkins-job-builder
Hi Thanh,

No, sorry for the confusion. I want to augment the job parameters. If you execute the jobs in the Jenkins UI, you'd see jobs a and b with, for example, two string parameters foo and bar.

Job c needs to have parameters foo and bar but also baz. I'd like to accomplish this without writing new job(-templates) with separate lists of parameters all the time. 

If it's not possible, at least then I'd know. Thanks!

-Brian

Thanh Ha

unread,
Feb 18, 2020, 4:56:42 PM2/18/20
to Brian Auron, jenkins-job-builder
No that's not possible you must use a different job template to specify different parameters. For parts of the job that's all the same you can take advantage of YAML anchors so that you don't have to redefine the same sections multiple times.

We use it heavily in our job templates. You can see some examples of this in the repo below. All of our job templates support both gerrit and github projects and we use anchors to template that out.


We also take advantage of JJB id fields so we can have multiple job-templates that have the same name resulting in the same job names in production regardless if you are using the gerrit or github version of the job.

Hope this helps,
Thanh

--
You received this message because you are subscribed to the Google Groups "jenkins-job-builder" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkins-job-bui...@googlegroups.com.

Brian Auron

unread,
Feb 18, 2020, 5:33:32 PM2/18/20
to jenkins-job-builder
Fair enough. Thanks for clearing it up for me!
Thanh

To unsubscribe from this group and stop receiving emails from it, send an email to jenkins-job-builder+unsub...@googlegroups.com.

Darragh Bailey

unread,
Aug 31, 2020, 7:06:26 AM8/31/20
to jenkins-job-builder

On Wed., Feb. 19, 2020, 05:37 Brian Auron, <brian...@gmail.com> wrote:
Hi Thanh,

No, sorry for the confusion. I want to augment the job parameters. If you execute the jobs in the Jenkins UI, you'd see jobs a and b with, for example, two string parameters foo and bar.

Job c needs to have parameters foo and bar but also baz. I'd like to accomplish this without writing new job(-templates) with separate lists of parameters all the time. 

If it's not possible, at least then I'd know. Thanks!

-Brian

On Tuesday, February 18, 2020 at 10:15:59 AM UTC-8, Brian Auron wrote:
Is there a way to have a set of default parameters on a set of job(-templates) but also include special parameters for special jobs?

For example:

job-template:
  name: a
  parameters: '{default_parameters}'
job-template:
  name: b
  parameters: '{default_parameters}'
job-template:
  name: c
  parameters: '{default_parameters}{special_parameters}' # Or some way to update default_parameters here

Thanks!

I forgot to reply at the time and just got reminded seeing https://review.opendev.org/#/c/746682 go by

You can approximate this to a degree with something like the following:

- job-template:
    name: 'test-job-{variant}'
    properties:
      - '{builddiscarderproperty|defaultproperties}'

- property:
    name: defaultproperties
    properties:
      - &defaultrebuild rebuild

- property:
    name: discarder
    properties:
      - *defaultrebuild
      - build-discarder:
          days-to-keep: 7

- project:
    name: test-project

    jobs:
    - 'test-job-{variant}':
        variant: abc

    - 'test-job-{variant}':
        variant: def
        builddiscarderproperty: discarder


It's not as neat as the proposed enhancement in that you need to construct a macro or substitution for each time you wish to augment the defaults, but it does provide some flexibility to use a default and replace with a different set based on a single setting instead of needing to maintain multiple templates.
Reply all
Reply to author
Forward
0 new messages