-with open(template_file, "r") as infile:
- with open(project_file, "w") as outfile:
- for line in infile:
- if not re.match("\s*#", line):
- line = re.sub("PROJECT", project, line)
- line = re.sub("DISABLED", disabled, line)
- line = re.sub("STREAMS", streams, line)
- line = re.sub("MAVEN_GOALS", mvn_goals, line)
- line = re.sub("MAVEN_OPTS", mvn_opts, line)
- line = re.sub("DEPENDENCIES", dependent_jobs, line)
- line = re.sub("EMAIL_PREFIX", email_prefix, line)
- line = re.sub("SONAR_BRANCH", sonar_branch, line)
- line = re.sub("ARCHIVE_ARTIFACTS", archive_artifacts, line)
- outfile.write(line)
+use_templates = templates.split(",")
+use_templates.insert(0, "project")
+job_templates_yaml = ""
+for t in use_templates:
+ if t == "project": # This is not a job type but is used for templating
+ pass
+ elif t == "sonar":
+ job_templates_yaml = job_templates_yaml + \
+ " - '%s-%s'\n" % (project, t)
+ else:
+ job_templates_yaml = job_templates_yaml + \
+ " - '%s-%s-{stream}'\n" % (project, t)
+
+with open(project_file, "w") as outfile:
+ for t in use_templates:
+ template_file = "jjb-templates/%s.yaml" % t
+ with open(template_file, "r") as infile:
+ for line in infile:
+ if not re.match("\s*#", line):
+ line = re.sub("JOB_TEMPLATES", job_templates_yaml, line)
+ line = re.sub("PROJECT_SHORTNAME", project.project, line)
+ line = re.sub("PROJECT_PATH", project.path, line)
+ line = re.sub("JENKINS_SETTINGS", jenkins_settings, line)
+ line = re.sub("DISABLED", disabled, line)
+ line = re.sub("STREAMS", str_streams, line)
+ line = re.sub("POM", pom, line)
+ line = re.sub("MAVEN_GOALS", mvn_goals, line)
+ line = re.sub("MAVEN_OPTS", mvn_opts, line)
+ line = re.sub("DEPENDENCIES", dependent_jobs, line)
+ line = re.sub("EMAIL_PREFIX", email_prefix, line)
+ line = re.sub("SONAR_BRANCH", sonar_branch, line)
+ line = re.sub("ARCHIVE_ARTIFACTS", archive_artifacts, line)
+ # The previous command may have created superfluous lines.
+ # If a line has no non-whitespace, it has to be '\n' only.
+ line = re.sub(r'^\s+\n', "", line)
+ outfile.write(line)
+ outfile.write("\n")