creating jenkins jobs with ansible

不羁岁月 提交于 2019-12-01 05:58:31

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:

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

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

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!