Run jekins setup script
cat /var/lib/jenkins/secrets/initialAdminPassword
Click new item > Name: Hello world > select freestyle project > Build Steps > Select Execute on shell > echo "Hello World!" && uptime > Save.
Click on Build now > Check build history > See output.
cat /var/lib/jenkins/workspace/
echo "jenkins-server" > /etc/hostname
yum install git -y & git -v
Click Dashboard > manage jenkins > manage pulgins > Avaliable > Search for github > check and click on install without restart.
Click Dashboard > manage jenkins > click tools > go for git > name git > Path to Git executable: /usr/bin/git (Exceute cmd whereis git to get path)> save
Click Dashboard > new item > Name: PUllcodefromgitRepo > source code management > select git > Enter git url name > credential none > click save.
Click on build now > check the build history successfull.
cd /var/lib/jenkins/workspace/PullcodefromGitRepo
Search maven install & maven download > copy link from the maven download Binary tar.gz archive.
cd /opt
wget https://dlcdn.apache.org/maven/maven-3/3.9.1/binaries/apache-maven-3.9.1-bin.tar.gz
tar xzvf apache-maven-3.9.1-bin.tar.gz
mv apache-maven-3.9.1 maven
/opt/maven/bin/mvn -v
M2_HOME=/opt/maven
M2=/opt/maven/bin
JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.18.0.10-3.el9.x86_64
find / -name java-11*
OUTPUT= /usr/lib/jvm/java-11-openjdk-11.0.18.0.10-3.el9.x86_64
Export the variable to .bash_profile (check before executing file there should not be any path entry)
echo -e "M2_HOME=/opt/maven\nM2=/opt/maven/bin\nJAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.18.0.10-3.el9.x86_64\nPATH=b\$PATH:b\$HOME:bin:b\$JAVA_HOME:b\$M2_HOME:b\$M2\nexport PATH" >> .bash_profile && source .bash_profile
echo $PATH
mvn -v
Click Dashboard > manage jenkins> plugins > Available > search maven > check maven integration > install withour restart
Click Dashboard > manage jenkins> TOOLS >
- jdk > Name: Java-11 > JAVA_HOME: /usr/lib/jvm/java-11-openjdk-11.0.18.0.10-3.el9.x86_64 > MAVEN ADD > Name: Maven-3.9.1 MAVEN_HOME: /opt/maven > apply & save.
- Click Dashboard > new item > Name:Build_Maven_Artifact > select maven project > Source_code_management:check Git,
- repo url:https://github.com/Pruthvi360/ci-cd-hello-world.git
- Build > Root POM: pom.xml> Goals and options: clean install (Check maven lifecycle)
- Apply & save
follow the steps in the tomcatinstall.md to complete the installation. Run the tomcat-setup.sh
Click Dashboard > manage jenkins > plugins > available > Search: Deploy to continer > check and click install withour restart.
- Click Dashboard > manage jenkins > manage credentials > system > global > select usernam & password > specify username & password >
- name: tomacat-deployer > description:tomcat-deployer.
- Click Dashboard > new item > Name:Deploy-to-container > Source_code_management: check git and git url > Build > Root POM: pom.xml > Goals and options: clean install
- Post build action > select deploy to continer > specify war file path webapp/target/webapp.war or **/*.war
- Containers > Select Tomatcat 9 > Give credentials select from previously created > Tomcat URL: http://35.231.215.116:8080/ > click Apply and save
Modify the existing job and Select
git clone https://github.com/Pruthvi360/ci-cd-hello-world.git
Edit index.jsp
git status > It should be **modified** state
git add . > In the current directory state should be **staging**
git commit -m "Auto Tigger to CI/CD" > In the state **commited** ready to push
git remote -v > used to show the remotes mapped to git remote repository
git branch > Check the branch
git push origin master > push the commited changes to the repository
Watch the Build history in jenkins and validate the changes in the tomcat server.
Refer the Docker-install.md file
FROM tomcat:latest
RUN cp -R /usr/local/tomcat/webapps.dist/* /usr/local/tomcat/webapps
COPY ./*.war /usr/local/tomcat/webapps
docker build -t mytomcat .
docker run -d --name tomcat -p 8082:8080 mytomcat
useradd dockeradmin
passwd
usermod -aG docker dockeradmin
nano /etc/ssh/sshd_config
passwordAuthentication yes
Click Dashboard > manage jenkins > plugins > available > Search Publish over SSH > install without restart
Click Dashboard > manage jenkins > click system > scroll down > publish over ssh > add > enter ip (public/private) > dockeradmin: password apply and save
passwd root
echo -e "FROM tomcat:latest
RUN cp -R /usr/local/tomcat/webapps.dist/* /usr/local/tomcat/webapps
COPY ./*.war /usr/local/tomcat/webapps" > Dockerfile
docker build -t app:v1 .
docker run -d --name myfirstapp -p 8087:8080 app:v1
Click Dashboard > manage jenkins > click system > scroll down > publish over ssh > add > enter hostname (public/private) > username: root: password apply and save
gcloud compute --project=qwiklabs-gcp-00-88cd768cca2a firewall-rules create docker-ports --direction=INGRESS --priority=999 --network=default --action=ALLOW --rules=tcp:8080,tcp:8087 --source-ranges=0.0.0.0
- Click Dashboard > New Item > Name: Build_and_deploy_container > Description: Build code with help of maven and deploy it on tomcat docker container.
- Source code manangement > Check Git > git url: > Check it is master > Build Triggers: Poll SCM : * * * * * >
- Build > Root POM: pom.xml > Goal and Options: clean install
- Post Build Action: Name: root > Transfers: webapp/target/*.war > Remove prefix: webapp/target > Remote Directory: //opt//docker
- Exec command : echo -e "FROM tomcat:latest RUN cp -R /usr/local/tomcat/webapps.dist/* /usr/local/tomcat/webapps COPY ./*.war /usr/local/tomcat/webapps" > Dockerfile
docker build -t app:v2 . docker run -d --name myfirstapp -p 8087:8080 app:v2
docker container prune
docker images prune -a
Edit Exec commads in the Post Build Actions:
echo -e "FROM tomcat:latest
RUN cp -R /usr/local/tomcat/webapps.dist/* /usr/local/tomcat/webapps
COPY ./*.war /usr/local/tomcat/webapps" > Dockerfile
CONTAINER=myfirstapp
docker build -t app:v1 .
docker stop $CONTAINER
docker rm $CONTAINER
docker run -d --name $CONTAINER -p 8087:8080 app:v1
Refer to ansible/ansible.tf file
ansible --version
python3 --version
ansible -m ping localhost
tree /etc/ansible/
cat /etc/ansible/hosts
useradd ansibleadmin
passwd ansibleadmin
sed -i '/%wheel/a ansibleadmin ALL=(ALL) NOPASSWD: ALL' /etc/sudoers
sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config
sed -i 's/PermitRootLogin no/PermitRootLogin yes/g' /etc/ssh/sshd_config
sed -i 's/PubkeyAuthentication no/PubkeyAuthentication yes/g' /etc/ssh/sshd_config
su - root
ssh-keygen
ssh-copy-id <docker-host-ip private or public ip if both are in same VPC>
echo -e "docker-host-ip" > /etc/ansible/hosts
ansible all -m ping
ansible all -m command -a uptime