#########################################
Setup Jenkins on EC2 and Build load using Jenkins
#########################################
sudo apt update sudo apt install wget unzip -y
sudo apt install awscli -y
aws configure enter your Access Key enter your Secret Access Key
aws s3 ls
vi MyJenkins.sh
sudo apt install default-jre -y
sudo wget -O /usr/share/keyrings/jenkins-keyring.asc
https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc]
https://pkg.jenkins.io/debian-stable binary/ | sudo tee
/etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update -y sudo apt-get install jenkins -y
sudo systemctl start jenkins.service sudo systemctl status jenkins
echo "InitialAdminPassword" echo "-------------------" sudo cat /var/lib/jenkins/secrets/initialAdminPassword
#Save & quit
chmod +x MyJenkins.sh
./MyJenkins.sh
jenkins --version
curl ifconfig.me
http://18.234.238.69:8080/ # Use your respective ip address
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
ex: e606c92ebb3b430ca5c2e480f5257e1f
Click on Install suggested Plugins on Customize Jenkins page.
Enter user id and password. Save & Continue.
In next step, on Instance Configuration Page, verify your Jenkins Public IP and Port Number then click on Save and Finish
Start Using Jenkins
Click on Manage Jenkins > Plugins
Click on Available Plugins. Search for 'Maven'. Select 2 plugins as listed below:
- Maven Integration Plugin and click 'Install'
Once the installation is completed, Go back to 'Manage Jenkins'.
Click on 'Tools'
Inside Tools, look for Maven Installations and click Add Maven. Give the Name as Maven-yourname, choose Version as 3.9.6 (or latest) and Click 'Save'.
Create your Github account Fork the following repository and create your own repository 'jenkins-proj'. Repository: https://github.com/..../...
Now you need to make a project for your application build. For that, select 'New Item' from the Home Page of Jenkins.
Enter an item name as 'jenkins-proj' and select the project as Maven Project and then click OK.
After you click on OK, you will be prompted to the configure page inside 'jenkins-proj' project. Go to Source Code Management tab, select Source Code Management as Git. You need to provide the GitHub Repository URL and GitHub Account Credentials. In the Credentials field, you have to click Add. Then click on Jenkins.
Then you will get prompted for Jenkins Credentials Provider page of Jenkins. Under Add Credentials, you can add your GitHub Username, Password and Description. Then click on Add.
After returning to the Source Code Management Page, click on Credentials and Choose your GitHub Credentials.
Keep all the other values as default and select Build menu on the left side. Inside Goals and options add 'clean package' and save the configuration by clicking on Save.
Get back to Maven project 'jenkins-proj'. Click on 'Build Now' for building the .war file for your application.
sudo apt install tomcat9 tomcat9-admin -y
sudo systemctl enable tomcat9
sudo vi /etc/tomcat9/server.xml #Change 8080 to 9999 in 1 place. (line 69 / red color font)
#Now restart the system for the changes to take effect sudo service tomcat9 restart sudo service tomcat9 status
sudo cp -R /var/lib/jenkins/workspace/jenkins-proj/target/welcome-page-war-1.0.war /var/lib/tomcat9/webapps
http://18.234.238.69:9999/welcome-page-war-1.0/
sudo service tomcat9 stop sudo apt remove tomcat9
########## The End ##########