Fix job template

Change-Id: I59b2b45029466b3eaf7e3835424f4e18a1de7983
diff --git a/jenkins/client/job_template.sls b/jenkins/client/job_template.sls
index 43d1f1d..e974656 100644
--- a/jenkins/client/job_template.sls
+++ b/jenkins/client/job_template.sls
@@ -4,21 +4,14 @@
   - jenkins.client
 
 {%- for job_template_name, job_template in client.get('job_template', {}).iteritems() %}
-
-{%- if job_template.get('enabled', true) %}
-
-{# now just 1 defined param is supported #}
-
-{%- if job_template.param|length == 1 %}
-
-{%- 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) %}
-{%- set job = job_template.template|yaml|replace(replacer, param) %}
+  {%- if job_template.get('enabled', true) %}
+    {# now just 1 defined param is supported #}
+    {%- if job_template.param|length == 1 %}
+      {%- 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) %}
+          {%- set job = job_template.template|yaml|replace(replacer, param)|load_yaml %}
 
 jenkins_job_{{ job_name }}_definition:
   file.managed:
@@ -28,7 +21,7 @@
   - template: jinja
   - defaults:
       job_name: {{ job_name }}
-      job: {{ job }}
+      job: {{ job|yaml }}
   - require:
     - file: jenkins_client_dirs
 
@@ -40,10 +33,8 @@
     - file: jenkins_job_{{ job_name }}_definition
     - file: /etc/salt/minion.d/_jenkins.conf
 
-{%- endfor %}
-
-{%- endfor %}
-
-{%- endif %}
-
+        {%- endfor %}
+      {%- endfor %}
+    {%- endif %}
+  {%- endif %}
 {%- endfor %}
diff --git a/jenkins/files/jobs/workflow-scm.xml b/jenkins/files/jobs/workflow-scm.xml
index 32fcc14..57c3756 100644
--- a/jenkins/files/jobs/workflow-scm.xml
+++ b/jenkins/files/jobs/workflow-scm.xml
@@ -1,5 +1,7 @@
 {%- from "jenkins/map.jinja" import client with context -%}
-{%- set job = salt['pillar.get']('jenkins:client:job:'+job_name) -%}
+{%- if job is not defined -%}
+  {%- set job = salt['pillar.get']('jenkins:client:job:'+job_name) -%}
+{%- endif -%}
 
 <?xml version='1.0' encoding='UTF-8'?>
 <flow-definition plugin="workflow-job@2.6">
diff --git a/jenkins/files/jobs/workflow.xml b/jenkins/files/jobs/workflow.xml
index 65a4e83..0469729 100644
--- a/jenkins/files/jobs/workflow.xml
+++ b/jenkins/files/jobs/workflow.xml
@@ -1,7 +1,7 @@
 {%- from "jenkins/map.jinja" import client with context -%}
-{%- if job is not defined %}
-{%- set job = salt['pillar.get']('jenkins:client:job:'+job_name) -%}
-{%- endif %}
+{%- if job is not defined -%}
+  {%- set job = salt['pillar.get']('jenkins:client:job:'+job_name) -%}
+{%- endif -%}
 
 {%- macro load_groovy_file() -%}
 {%- set groovy_file=client.dir.jenkins_source_root+'/'+job.script.repository+'/'+job.script.file -%}