Custom default with job-templates

Skip to first unread message

Lesley Kimmel

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. 

    name: conf1
    folder: conf1-folder
    var1: conf1-var1

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

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

    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.


Andrew Grimberg

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.

> --
> 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
> <>.
> To view this discussion on the web visit
> <>.

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.

Lesley Kimmel

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

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
0 new messages