Custom default with job-templates

20 views
Skip to first unread message

Lesley Kimmel

unread,
Jul 21, 2022, 6:32:33 PM7/21/22
to jenkins-job-builder
We would like to utilize job-templates that only vary by a set of options we'd further like to keep in "defaults" objects. However, it appears that the "defaults" option for jobs/job-templates expects a static string instead of a variable. 

Example:
defaults:
    name: conf1
    folder: conf1-folder
    var1: conf1-var1

defaults:
    name: conf2
    folder: conf2-folder
    var1: conf2-var1

project:
    name: custom-project
    conf:
        - conf1
        - conf2
    jobs:
        - job-{conf}

job-template:
    name: job-{conf}
    defaults: '{conf}'

Which fails with:
jenkins_jobs.errors.JenkinsJobsException: Unknown defaults set: '{conf}'

I suspect that 'defaults:' is fetched before variable replacement occurs. Is there another way to achieve what we're trying to do? I know we can put those vars into the project object but we also potentially want them to be usable by other projects/jobs/job-templates.

Thanks

Andrew Grimberg

unread,
Jul 25, 2022, 11:44:22 AM7/25/22
to Lesley Kimmel, jenkins-job-builder
Variable replacement only happens inside of quoted strings. You've got
two that are not quoted.

The name inside of the job template and the call to the job definition.

Though I haven't tried to do a default that is used in job names, this
should correct the issue for you though.

-Andy-
> --
> 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
> <mailto:jenkins-job-bui...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jenkins-job-builder/b4995150-2861-4612-896d-4473c48bd9f6n%40googlegroups.com
> <https://groups.google.com/d/msgid/jenkins-job-builder/b4995150-2861-4612-896d-4473c48bd9f6n%40googlegroups.com?utm_medium=email&utm_source=footer>.

--
Andrew J Grimberg
Manager Release Engineering
The Linux Foundation

NOTICE: The Linux Foundation supports their employees with flexible work
hours. If you recieve mail from me outside of standard business hours
please be aware that I do not expect a response until the next standard
business day.
OpenPGP_signature

Lesley Kimmel

unread,
Jul 25, 2022, 11:56:24 AM7/25/22
to jenkins-job-builder
Andy;

Thank you for the reply. However, I have to contradict you here. I have plenty of jobs that don't place replacement variables inside of quotes. The replacement still happens just fine and my jobs are rendered as expected. As per the YAML spec I have to quote them when the curly brace would immediately follow a key because it would otherwise be interpreted as the start of an object instead of a string. Hence why I quoted the variable after 'defaults: ' but not in other places. 
Reply all
Reply to author
Forward
0 new messages