Create working jenkins with affordable

I am working on a project to deploy the jenkins CI server on centos7 using the indispensable And I am having problems creating jenkins jobs from an xml template using the irreplaceable.

Everything works fine so far, but now I want to be able to create tasks and give them the basic configuration from an xml file using unsible. 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 fine when entered manually in the centos7 field, but when I put it in the indispensable 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 

The following error message appears:

 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 about this? As far as I can see, I am doing it right (since the command works when it is not entered without help)

+5
source share
3 answers

The command module does not support input and output redirection because it does not pass the command line to the shell. Here is what its documentation says:

It will not be processed through the shell, so variables like $ HOME and operations like "<", ">", "|" and & will not work (use a shell module if you need these functions).

So:

 - name: create jenkins jobs with xml files sudo: yes shell: "java -jar {{ jenkins.cli_dest }} -s http://localhost:8080 create-job {{ item.name }} < {{ jenkins_dest }}/{{ item.xml_name }}" with_items: jenkins_jobs 
+3
source

I manage jenkins CI / CD pipelines and customize them with the ability, and I rely heavily on available libraries (groovy DSL, python jenkins-job-builder) and create jenkins XML configuration templates using jinja2. I was asked to demonstrate what can be done with the opportunity in a local meeting, and I am working on some code that I will supply and share at this meeting in the new year. I seriously think that this material can help you a lot, I am currently using this setting in my current project and cannot imagine how to manage jenkins in any other way.

https://github.com/Azulinho/ansible-jenkins-showcase

+8
source

You can use shell redirection by executing a shell. For example, the sh command echo test> hello.txt will work as intended. Just wrap the entire command with something like "/ bin / sh" java ...> ... ".

0
source

Source: https://habr.com/ru/post/1207204/


All Articles