3

有没有办法在 Jenkins Job Builder 的 YAML 模板中使用 for 循环?
喜欢它 Ansible with jinja2类似的
东西

jobs: job1, job2, job3  

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

所以它会像

- trigger-builds:
    - project: project_job1 project_job2 project_job3
4

2 回答 2

0

您可以使用 jinja2 模板来实现此目的。

像这样的东西:

- 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
于 2022-02-10T06:30:18.117 回答
0

来自文档: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}"

上面的示例将省略作业:

  1. 构建-axe1val1-axe2val1-axe3val2
  2. 构建-axe1val1-axe2val2-axe3val1
  3. 构建-axe1val2-axe2val2-axe3val1
于 2021-10-05T11:29:43.340 回答