1、jenkins安装配置略
2、配置maven
[[email protected] maven]# cat /etc/profile.d/maven.sh
export MAVEN_HOME=/usr/local/maven
export PATH=$PATH:$MAVEN_HOME/bin
[[email protected] maven]# source /etc/profile
3、jenkins里配置maven环境
4、新建自动风格项目-api_125_8181
5、编写ansilbe-playbook
[[email protected] ansible]# ll
总用量 28
-rw-r--r--. 1 root root 19179 1月 30 04:15 ansible.cfg
drwxr-xr-x. 2 root root 16 7月 2 12:50 group_vars
-rw-r--r--. 1 root root 129 6月 26 15:40 hosts
drwxr-xr-x. 12 root root 4096 6月 28 20:00 roles
备注:全局变量,指定了jenkins的workspace
[[email protected] ansible]# cat group_vars/all
jenkins_home: /var/lib/jenkins/workspace/
[[email protected] roles]# cat api_125_8181/tasks/main.yml
- name: copy api
copy: src={{ jenkins_home }}/api_125_8181/target/exchange-api.war dest=/opt/exchange-api/www/ROOT.war backup=yes
- name: restart api
shell: /opt/script/startapi.sh #调用目标主机的脚本,进行服务重启
[[email protected] roles]# cat api_125_8181/api.yml #该入口文件配置在上面的jenkins当中,当jenkins构建时,调用执行任务
- hosts: 172.16.1.125
remote_user: root
roles:
- api_125_8181 #指定roles目录下哪个项目
[[email protected] ansible]# tree roles/api_125_8181/
roles/api_125_8181/
├── api.yml
├── files
│?? └── startfront.sh
├── front.retry
└── tasks
└── main.yml
2 directories, 4 files
[[email protected] ansible]#
6、构建调试
原文地址:http://blog.51cto.com/9682938/2135024
时间: 2024-10-08 17:04:00