创造jenkins工作与ansible [英] creating jenkins jobs with ansible
问题描述
我正在开发一个项目,在centos7上使用可靠的
部署jenkins CI服务器。我在使用ansible从xml模板创建jenkins作业时遇到了问题。
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.
到目前为止,一切正常,但现在我希望能够创建作业,并使用ansible从xml文件中为其提供一些基本配置。我的解决方案是jenkins-cli中的以下命令:
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
在centos7框中手动输入时,此功能非常完美,但是当我将它放入并运行它:
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)
推荐答案
命令模块不支持输入和输出重定向,因为它不会传递命令字符串到外壳。这是它的文档说的:
The command module doesn't support input and output redirection since it doesn't pass the command string to a shell. This is what its documentation says:
它不会通过shell进行处理,因此变量像$ HOME和像<的操作,>,|和&将无法使用(如果您需要这些功能,请使用外壳模块)。
所以:
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
这篇关于创造jenkins工作与ansible的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!