Last active
July 13, 2016 07:13
-
-
Save algotrader-dotcom/8373a2567c1a49ad802f9029664516cb to your computer and use it in GitHub Desktop.
Setup jenkins + ansible to autdeploy for JAVA, PHP projects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Requirments | |
Jenkins, Ansible on the same machine | |
$docker run -p 8080:8080 -p 50000:50000 -v /opt/jenkins:/var/jenkins_home thuannvn/my-jenkins | |
Dockerfile can be found here https://github.com/thuannvn/docker-jenkins-extended | |
# Setup for java project (traditional) | |
GIT: https://github.com/thuannvn/hello-world-java | |
Open jenkins -> Create new job -> Choose Freestyle -> Choose Git (Source code management) -> Build (Execute shell) with content: | |
javac HelloWorld.java | |
java HelloWorld | |
# Setup for java project with maven build, autodeploy to tomcat | |
GIT: https://github.com/thuannvn/hello-world-java-maven | |
Open jenkins -> Create new job -> Choose Freestyle -> Choose Git (Source code management) -> Build (Execute shell) with content: | |
# Remember to set env PATH=$PATH:/var/jenkins_home/apache-maven-3.3.9/bin/ | |
pwd | |
mvn clean package | |
After build success, check autodepoy war package to tomcat | |
# Set for PHP project | |
GIT: https://github.com/thuannvn/hello-world-php | |
Poll SCM: ***** (Trigger build/deploy when commit) | |
Open jenkins -> Create new job -> Choose Freestyle -> Choose Git (Source code management) -> Build (Execute shell) with content: | |
ansible 172.17.0.13 -m shell -a "apt-get install git -y" | |
ansible 172.17.0.13 -m shell -a "rm -Rf /app-latest" | |
ansible 172.17.0.13 -m git -a "repo=https://github.com/thuannvn/hello-world-php.git dest=/app-latest/" | |
ansible 172.17.0.13 -m shell -a "ls -la /app-latest/" | |
ansible 172.17.0.13 -m shell -a "rsync -arvz /app-latest/ /app/" | |
ansible 172.17.0.13 -m shell -a "ls -la /app/" | |
# FAQs | |
/etc/ansible/hosts | |
[ansible-lab] | |
172.17.0.13 ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass=root # my-apache-php | |
172.17.0.10 ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass=root # my-centos | |
172.17.0.9 ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass=root # my-ubuntu | |
/etc/ansible/ansible.cfg | |
[defaults] | |
host_key_checking=false | |
# Re-check if ansible workds | |
$ansible all -m ping | |
# Troube shooting | |
sudo apt-get install sshpass | |
# Ansible instalation lastest | |
http://www.virtxpert.com/installing-ansible-via-git/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment