I'm working on a project to deploy a jenkins CI server on centos7 using ansible And I'm having problems creating jenkins jobs from an xml template using ansible.
Everything works fine so far, but now i want to be able to create jobs, and give them some basic configuration from an xml file using ansible. My solution was the following command from jenkins-cli:
sudo java -jar jenkins-cli.jar -s http://localhost:8080 create-job Job_test1 < Job_test1.xml
this works perfectly when entered manually in the centos7 box, but when i put it into ansible and run it:
- name: create jenkins jobs with xml files
sudo: yes
command: "java -jar {{ jenkins.cli_dest }} -s http://localhost:8080 create-job {{ item.name }} < {{ jenkins_dest }}/{{ item.xml_name }}"
with_items: jenkins_jobs
it gives the following error message:
stderr: Too many arguments: <
java -jar jenkins-cli.jar create-job NAME
Creates a new job by reading stdin as a configuration XML file.
Does anyone know a solution to this? As far as I can see I'm doing it properly(since the command works when not entered by ansible)
I manage my jenkins CI/CD pipelines and setup with ansible, and I rely heavily on available libraries (groovy DSL, python jenkins-job-builder) and template the guts of the the jenkins XML config using jinja2. I got asked to showcase what can be done with ansible at a local meetup, and have been working some code that I will be delivering and sharing at that meetup in the new year. I seriously think this stuff could help you a lot, I currently use this setup in my current project and can't imagine managing jenkins any other way.
https://github.com/Azulinho/ansible-jenkins-showcase
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With