3

Is there a way to use for loops in YAML templates for Jenkins Job Builder?
Like it Ansible with jinja2
Something like

jobs: job1, job2, job3  

- trigger-builds:
    - project: 
        {% for j in jobs %} 
          project_{{ j }}
        {% endfor %}

So it will be like

- trigger-builds:
    - project: project_job1 project_job2 project_job3
Anthon
  • 69,918
  • 32
  • 186
  • 246
Igor Zilberman
  • 1,048
  • 1
  • 11
  • 16

2 Answers2

1

You can use jinja2 template for achieving this purpose.

Something like this:

- builder:
    name: test-builder
    builders:
      - shell:
          !j2: |
            {{ var }}
            {% for item in test_list -%}
            {{ item }}
            {% endfor %}
- job:
    name: test-job
    builders:
       - test-builder:
          var: "test variable"
          test_list:
             - a
             - b
             - c
Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
0

From Documentation: https://docs.openstack.org/infra/jenkins-job-builder/definition.html

- project:
    name: project-name
    axe1:
      - axe1val1
      - axe1val2
    axe2:
      - axe2val1
      - axe2val2
    axe3:
      - axe3val1
      - axe3val2
    exclude:
      - axe1: axe1val1
        axe2: axe2val1
        axe3: axe3val2
      - axe2: axe2val2
        axe3: axe3val1
    jobs:
      - build-{axe1}-{axe2}-{axe3}

- job-template:
    name: build-{axe1}-{axe2}-{axe3}
    builders:
      - shell: "echo Combination {axe1}:{axe2}:{axe3}"

The above example will omit the jobs:

  1. build-axe1val1-axe2val1-axe3val2
  2. build-axe1val1-axe2val2-axe3val1
  3. build-axe1val2-axe2val2-axe3val1
Amitai Gz
  • 33
  • 5