Fix jobs cleanup when job templating is used

Change-Id: Ica972e427ea6aaee8bca8cf0128ba7e6a976dbf2
diff --git a/jenkins/client/job.sls b/jenkins/client/job.sls
index 3822ca5..217278d 100644
--- a/jenkins/client/job.sls
+++ b/jenkins/client/job.sls
@@ -46,28 +46,22 @@
 
 {%- if client.get('purge_jobs', False) %}
 
-{%- set jobs =  client.get('job', {}).keys() %}
+  {%- set jobs =  client.get('job', {}).keys() %}
 
-{%- for job_template_name, job_template in client.get('job_template', {}).iteritems() %}
-
-{%- if job_template.get('enabled', true) %}
-
-{%- for param_name, params in job_template.param.iteritems() %}
-
-{%- set replacer = "{{" + param_name + "}}" %}
-
-{%- for param in params %}
-
-{%- set job_name = job_template.name|replace(replacer, param) %}
-
-{%- endfor %}
-
-{%- endfor %}
-
-{%- endif %}
+  {%- for job_template_name, job_template in client.get('job_template', {}).iteritems() %}
+    {%- if job_template.get('enabled', true) %}
+      {%- for param_name, params in job_template.param.iteritems() %}
+        {%- set replacer = "{{" + param_name + "}}" %}
+        {%- for param in params %}
+          {%- set job_name = job_template.name|replace(replacer, param) %}
+          {%- do jobs.append(job_name) %}
+        {%- endfor %}
+      {%- endfor %}
+    {%- endif %}
+  {%- endfor %}
 
 jenkins_clean_undefined_jobs:
   jenkins_job.cleanup:
   - jobs: {{ jobs|yaml }}
 
-{%- endif %}
\ No newline at end of file
+{%- endif %}