Ability to enforce single job_template jobs
Change-Id: Ib305fe81ded57610ec64e5d036a998d38ae800a4
diff --git a/jenkins/client/_job_template.sls b/jenkins/client/_job_template.sls
new file mode 100644
index 0000000..de4ba21
--- /dev/null
+++ b/jenkins/client/_job_template.sls
@@ -0,0 +1,31 @@
+{%- if job_template.get('enabled', true) %}
+ {#- Matrix way, simulating behavior of Jenkins job builder, not fully
+ supported at the moment #}
+ {%- for param_name, params in job_template.get('param', {}).iteritems() %}
+ {%- set replacer = "{{" + param_name + "}}" %}
+ {%- for param in params %}
+ {%- set job_name = job_template.name|replace(replacer, param) %}
+ {%- set job = job_template.template|yaml|replace(replacer, param)|load_yaml %}
+ {%- include "jenkins/client/_job.sls" %}
+ {%- endfor %}
+ {%- endfor %}
+
+ {#- Simple list of jobs togenerate with multiple parameters to replace #}
+ {%- for job_params in job_template.get('jobs', []) %}
+ {%- set _job_name = [job_template.name] %}
+ {%- set _job = [job_template.template] %}
+
+ {%- for key, value in job_params.iteritems() %}
+ {#- You may think WTF hack is this but we can't update variables in
+ inner scope to replace all parameters. But we can abuse lists for
+ this purpose }:-) #}
+ {%- set replacer = "{{" + key + "}}" %}
+ {%- do _job_name.append(_job_name|last|replace(replacer, value)) %}
+ {%- do _job.append(_job|last|yaml|replace(replacer, value)|load_yaml) %}
+ {%- endfor %}
+
+ {%- set job_name = _job_name|last %}
+ {%- set job = _job|last %}
+ {%- include "jenkins/client/_job.sls" %}
+ {%- endfor %}
+{%- endif %}
diff --git a/jenkins/client/job_template.sls b/jenkins/client/job_template.sls
index 8d519cd..3f8acea 100644
--- a/jenkins/client/job_template.sls
+++ b/jenkins/client/job_template.sls
@@ -1,38 +1,22 @@
{% from "jenkins/map.jinja" import client with context %}
-include:
- - jenkins.client
+{%- if salt['pillar.get']('job_template_name', False) %}
+
+{%- set job_template_name = salt['pillar.get']('job_template_name') %}
+{%- set job_template = salt['pillar.get']('jenkins:client:job_template:'+job_template_name) %}
+{% include "jenkins/client/_job_template.sls" %}
+
+{%- elif salt['pillar.get']('job_template_names', False) is iterable %}
+
+{%- for job_template_name in salt['pillar.get']('job_template_names') %}
+{%- set job_template = salt['pillar.get']('jenkins:client:job_template:'+job_template_name) %}
+{% include "jenkins/client/_job_template.sls" %}
+{%- endfor %}
+
+{%- else %}
{%- for job_template_name, job_template in client.get('job_template', {}).iteritems() %}
- {%- if job_template.get('enabled', true) %}
- {#- Matrix way, simulating behavior of Jenkins job builder, not fully
- supported at the moment #}
- {%- for param_name, params in job_template.get('param', {}).iteritems() %}
- {%- set replacer = "{{" + param_name + "}}" %}
- {%- for param in params %}
- {%- set job_name = job_template.name|replace(replacer, param) %}
- {%- set job = job_template.template|yaml|replace(replacer, param)|load_yaml %}
- {%- include "jenkins/client/_job.sls" %}
- {%- endfor %}
- {%- endfor %}
-
- {#- Simple list of jobs togenerate with multiple parameters to replace #}
- {%- for job_params in job_template.get('jobs', []) %}
- {%- set _job_name = [job_template.name] %}
- {%- set _job = [job_template.template] %}
-
- {%- for key, value in job_params.iteritems() %}
- {#- You may think WTF hack is this but we can't update variables in
- inner scope to replace all parameters. But we can abuse lists for
- this purpose }:-) #}
- {%- set replacer = "{{" + key + "}}" %}
- {%- do _job_name.append(_job_name|last|replace(replacer, value)) %}
- {%- do _job.append(_job|last|yaml|replace(replacer, value)|load_yaml) %}
- {%- endfor %}
-
- {%- set job_name = _job_name|last %}
- {%- set job = _job|last %}
- {%- include "jenkins/client/_job.sls" %}
- {%- endfor %}
- {%- endif %}
+{% include "jenkins/client/_job_template.sls" %}
{%- endfor %}
+
+{%- endif %}