diff --git a/build.py b/build.py
index 061455f64fa3fde5b3e88a3b777436f0a7256802..eca9a80fe89cddb620cc880e95f129be78f3c4ba 100644
--- a/build.py
+++ b/build.py
@@ -22,12 +22,13 @@ class ConfigBuilder:
             for job in service['scraping']:
                 self.logger.debug("Templating: " + service['service_name'] + ' -> ' + job['template'])
                 self.load_template(job)
-                template = self.substitute_template_field(job, service)
+                output = self.substitute_template_field(job, service)
+
                 # store generated prometheus job config
                 if 'ignore' in job and check_true(job['ignore']):
                     job['output_yaml'] = None
                 else:
-                    job['output_yaml'] = yaml.safe_load(template)
+                    job['output_yaml'] = yaml.safe_load(output)
 
     def load_template(self, job):
         """Substitute 'template' field with its content"""
@@ -39,7 +40,7 @@ class ConfigBuilder:
         env = jinja2.Environment(undefined=jinja2.DebugUndefined)
         template = env.from_string(job['template'])
         data = service.copy()
-        data['targets'] = job['targets']
+        data['job'] = job
         data['snippet'] = collect_snippets(self.config.templates)
 
         return template.render(data)