Skip to content

Commit

Permalink
Separate seed job Groovy script from XML
Browse files Browse the repository at this point in the history
This makes the script easier to read and modify. The conversion of
special characters is done by a custom Jinja2 filter.

Add '*.pyc' to '.gitignore'.
  • Loading branch information
Olav Philipp Henschel committed Oct 16, 2017
1 parent 39e5397 commit 450547d
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.pyc
*.retry
15 changes: 15 additions & 0 deletions ansible/filter_plugins/filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
def escape_to_xml(string):
char_to_escaped_string = [
('"', '"'),
("'", '''),
('<', '&lt;'),
('>', '&gt;')
]
for char, escaped in char_to_escaped_string:
string = string.replace(char, escaped)
return string


class FilterModule(object):
def filters(self):
return {'escape_to_xml': escape_to_xml}
3 changes: 3 additions & 0 deletions ansible/roles/jenkins-seed-job/defaults/main.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
---
seed_job_name: seed_job
seed_job_script_path: "{{seed_job_name}}.groovy"
seed_job_script: "{{ lookup('file', seed_job_script_path) }}"
seed_job_script_xml: "{{ seed_job_script | escape_to_xml }}"
seed_job_template: "{{seed_job_name}}_config.xml.j2"
seed_job_target_dir: "{{jenkins_home_dir}}/jobs/{{seed_job_name}}"
6 changes: 6 additions & 0 deletions ansible/roles/jenkins-seed-job/files/seed_job.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node ('master') {
git credentialsId: 'github-user-pass-credentials',
url: REPOSITORY_URL,
branch: REPOSITORY_COMMIT
jobDsl targets: JOB_DESCRIPTORS_FILES
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,7 @@
</org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty>
</properties>
<definition class="org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition" plugin="[email protected]">
<script>
node (&apos;master&apos;) {
git credentialsId: &apos;github-user-pass-credentials&apos;,
url: REPOSITORY_URL,
branch: REPOSITORY_COMMIT
jobDsl targets: JOB_DESCRIPTORS_FILES
}</script>
<script>{{seed_job_script_xml}}</script>
<sandbox>true</sandbox>
</definition>
<triggers/>
Expand Down

0 comments on commit 450547d

Please sign in to comment.