Project common parameters

15 views
Skip to first unread message

Lesley Kimmel

unread,
Aug 1, 2022, 4:41:13 PM8/1/22
to jenkins-job-builder
Hello, most of our projects tend to create 2 separate jobs; one for each of 2 different "environments" (e.g. stg/prd).

The values of most vars we pass to job-templates through the project definitions tend to be pretty static so I decided to use include files with the "default" values per-environment:

# stg-yaml.incl
node_name: node1
env_name: stg

# prd-yaml.incl
node_name: node2
env_name: prd

project:
  name: project1
  jobs:
    - project1-{env_name}:
        !include: stg-yaml.incl
    - project1-{env_name}:
        !include: prd-yaml.incl

The problem is that, sometimes, I'd like to pass project-specific vars to job-templates but it doesn't appear there is a way provide key/value pairs alongside the use of '!include'. For example:
- project1-{env_name}:
    !include: stg.yaml.incl
    custom_var: value1
Throws: ScannerError: mapping values are not allowed here

I also attempted to use the '!include' in an anchor and then alias it within the project definition:

- project_defaults:
    name: project_defaults
    stg_defaults: &stg-vars
      !include: stg.yaml.incl

- project:
  name: project1
  jobs:
    - project1-{env_name}:
        <<: *stg-vars
        custom_var: value1

But then it errors saying a mapping is expected but found a scalar.

What is the recommended way to use environment-specific variable defaults that can be added to and/or overridden?

Vsevolod Fedorov

unread,
Aug 2, 2022, 1:39:05 PM8/2/22
to Lesley Kimmel, jenkins-job-builder

Hi, Lesley.

You can use defaults and parametrize jobs by a list, like in documentation here:
https://jenkins-job-builder.readthedocs.io/en/latest/definition.html#project-1

For example:

defaults:
  name: global
  my_config_2: default-config-2
  env:
    - prod:
        my_config_1: prod-config-1
        my_config_2: prod-config-2
    - dev:
        my_config_1: dev-config-1

project:
  jobs:
    name: project-1
    jobs:
      - build-{env}


Vsevolod.

--
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/3920ace6-bb76-4fe4-852f-4004029727fbn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages