Hello, I'm trying to use ansible to set up a small team buildfarm with jenkins. This is my first use of ansible.
I'm successfully using ansible 2.2's jenkins_job module <http://docs.ansible.com/ansible/jenkins_job_module.html> as in: tasks: > - jenkins_job: > name: feeds > config: "{{ lookup('file', '../jenkins/jobs/feeds/config.xml') }}" > The job is defined by the xml, which the module caries over to jenkins using jenkins' rest API. This is great. Now, most of my jobs are written as jenkins "pipeline" jobs <https://jenkins.io/doc/book/pipeline/overview/>. The job xml mostly holds and wraps a groovy script <http://www.groovy-lang.org/>, like this (dumb) one: node ('linux'){ > sh 'test -d .qi || (rm -rf .qi; mkdir -p .qi && touch .qi/stamp)' > checkout scm sh 'make' > } > Instead of editing the job/config.xml, I would prefer to edit the job/script.groovy, and embed it in the xml. I tried using a role to do so: - { role: jenkinspipelinejob, name: 'feeds', script: "{{ lookup('file', > 'jenkins/jobs/feeds/script.groovy') }}" } > With $ cat roles/jenkinspipelinejob/tasks/main.yaml > - debug: msg="CONFIG {{ lookup('template', 'config.xml.j2') }}" > - jenkins_job: > name: "{{ name }}" > config: "{{ lookup('template', 'config.xml.j2') }}" > and $ cat roles/jenkinspipelinejob/templates/config.xml.j2 > <?xml version='1.0' encoding='UTF-8'?> > <flow-definition plugin="[email protected]"> > <actions/> > <description></description> > <keepDependencies>false</keepDependencies> > <properties> > > <org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty> > <triggers/> > > </org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty> > </properties> > <definition class="org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition" > plugin="[email protected]"> > <script> > {{ script }} > </script> > <sandbox>true</sandbox> > </definition> > <triggers/> > </flow-definition> > It does work, but requires me to escape my script.groovy for xml inclusion. For instance, instead of sh 'test -d .qi || (rm -rf .qi; mkdir -p .qi *&&* touch .qi/stamp)' > > I need to write sh 'test -d .qi || (rm -rf .qi; mkdir -p .qi *&&* touch .qi/stamp)' > > I would like this escaping to be done automatically, how should I proceed? I guess I could write a module, but there might be a simpler way. I've looked for "xml escaping jinja filter" without any luck. -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/86961899-0ebb-4bf2-875c-2ce61f557522%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
