Jenkins
First login to portal.azure.com, here we can see dashboard where all cloud services are
available
Select Virtual Machines
To create Virtual Machine click on create option we get three options they are:
1. Azure virtual Machines
2. Azure virtual machine with present configuration
3. More VMs and related solutions
Select first option to create vm
Fill the details of Subscription ,Resource group, Virtual machine name, Region, Image as
shown in the above figure.
Select size of VM and Authentication type as password and fill the username and password
of VM.
Click on review+create and it will valid the details of vm with their current vm’s in data
center to avoid confusion every vm in data center should be a unique name to access easily
Click on create option
Select connect to view the ip address
Copy the ip address
open the putty software
paste ip address as Host Name
Click on ConnectOnce
sudo apt update is command to update the ubuntu linux.
To install java JDK and JRE :
apt install openjdk-17-jdk openjdk-17-jre
Once installed, verify the Java version using the following command:
java --version
Add the Jenkins Debian repository.
Import the GPG keys of the Jenkins repository using the following wget command:
wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add –
sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ >
/etc/apt/sources.list.d/jenkins.list'
sudo apt update
Error : E: Package 'jenkins' has no installation candidate
Fix: -
Site: https://stackoverflow.com/questions/70541720/jenkins-has-no-installation-candidate-error-while-
trying-to-install-jenkins-on
Note :- install jenkins in ubuntu 20.
https://www.digitalocean.com/community/tutorials/how-to-install-jenkins-on-ubuntu-22-04
You can add [trusted=yes] in the /etc/apt/sources.list.d/jenkins.list file.
To replace text first need to get insert mode to do that press ‘i’
Initially /etc/apt/sources.list.d/jenkins.list will have,
deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian binary/
Update it as,
deb [trusted=yes] https://pkg.jenkins.io/debian binary/
After that run the installation instructions.
After replacing text press esc+:wq! To save successfully
Eg: for Debian releases
sudo apt-get update
sudo apt-get install fontconfig openjdk-11-jre
sudo apt-get install Jenkins
Jenkins service will automatically start after the installation process is complete. You can verify it by
printing the service status:
systemctl status Jenkins
we need to create Inbound port rule with highest priority to access jenkins
After adding Inbound port rule successfully copy the VM ip address and paste in new tab and add :8080
at end of the ip address.
We need to enter the Administrator password for the first attempt, later we need to create login
account.
To find the password of Jenkins enter this command:
vi /var/lib/jenkins/secrets/initialAdminPassword
Copy the password from your terminal, paste it into the Administrator password field and click
Continue.
On the next screen, the setup wizard will ask you whether you want to install suggested plugins or you
want to select specific plugins. Click on the Install suggested plugins box, and the installation process
will start immediately.
After installation
Once the plugins are installed, you will be prompted to set up the first admin user. Fill out all required
information and click Save and Continue.
Enter the vm ip address with port number and click on Save and Finish.
Click on the Start using Jenkins button and you will be redirected to the Jenkins dashboard.
At this point, you’ve successfully installed Jenkins on your system.
Install maven software in local machine.
sudo apt update
sudo apt install maven
mvn -version
After installing maven you need to add extension in Jenkins also
In dashboard select Manage Jenkins in that go to Plugins , click on Available plugins and search for
maven click on install
After maven plugin installation verify that is available in installed plugins or not
We need to add path of java and maven in tools which are located in our vm.
Click on apply and save.
Added maven path successfully.
Create a new pipe line name it as javapipline and select Freestyle project and click ok.
Open java github repo and copy the github repo url.
Paste the github url in Dashborad/javapipeline/Configuration
Select source code management in that choose git if the repo is public only url needed to paste
otherwise if repo is private we need to enter the github repo credentials also using Advanced option.
Click on Apply and save.
After build complete it will generate webapp.war file which is located in console output.
Check the same webapp.war files is created in your vm also.
To check that commands are:
sudo su –
cd /var/lib/jenkins/workspace/javapipeline/webapp/target/
ls
After typing ls we can see webapp.war file
Create another vm or can do this process in same vm also . while doing on same vm make sure that
to increase the size of vm and it will restart again then continue this process.
Download and install tomcat using this following commands:
cd /opt
wget https://dlcdn.apache.org/tomcat/tomcat-8/v8.5.81/bin/apache-tomcat-8.5.81.tar.gz
tar -zvxf /opt/apache-tomcat-8.5.81.tar.gz
It will download and install.
If you are created another vm install java in that vm.
After installation type to following command to entire into the tomcat directory
cd apache-tomcat-8.5.100/
ps -ef | grep tomcat
cd bin/
ls -la
Type chmod +x ./startup.sh : To give the permission for execute or start
Again type : ls -la
Observe the difference between the permissions when compare to above file.
After changing the permissions we have to create to shortcut to start and stop tomcat server instead
to coming to this directory .
Commands are:
ln -s /opt/apache-tomcat-8.5.81/bin/startup.sh /usr/local/bin/tomcatup
ln -s /opt/apache-tomcat-8.5.81/bin/shutdown.sh /usr/local/bin/tomcatdown
tomcatup
Using unique ports for each application is a best practice in an environment. But tomcat and Jenkins
runs on ports number 8080. Hence lets change tomcat port number to 8090. Change port number in
conf/server.xml file under tomcat home
Commands are:
ls
cd ..
cd conf/
vi server.xml
Type ‘ i ‘ enter into insert mode
Change the port number 8080 to 9000 in Connector port and press esc+:+wq! to save and exit from
the file.
we need to add inbound rule again with port number 9000
click on add .
copy the ip address to vm and add port number 9000 at end to ip address
Now click on the host manager.
we get Acess Denied. We need to add the roles to view the deployment.
We have to enter into context.xm file to add the roles.
cd .. -> Go to apache-tomcat-8.5.100 directory
cd webapps/hostmanger/META-INF/
vi context.xml
click ‘ i’ to get insert mode.
After adding code click esc+:+wq! to save and exit the changes.
In another location also we have to do same change
cd .. -> Go to webapps
cd manager/META-INF
vi context.xml
Press ‘ i’ to get insert mode
Add the comments to the code,
Press esc+ : + wq! to save and exit
Go to the conf and we need to add roles in tomcat-users.xml
Add the extra roles code as follows:
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<user username="admin" password="admin" roles="manager-gui, manager-script,
manager-jmx, manager-status"/>
<user username="deployer" password="deployer" roles="manager-script"/>
<user username="tomcat" password="s3cret" roles="manager-gui"/>
Enter username and password as admin and click on sign in
Install Deploy to container in Jenkins
Go to configuration and select Post-build Actions
Add details Deploy to container as above shown figure.In details of container give your credentials
and Tomcat url and click on apply and save
Jenkins Build periodically:
If you want to schedule your project build periodically then you should select the
Build periodically option from the build triggers.
This field follows the syntax of cron (with minor differences). Specifically, each line
consists of 5 fields separated by TAB or whitespace:
MINUTE HOUR DOM MONTH DOW
MINUTE Minutes within the hour (0–59)
HOURThe hour of the day (0–23)
DOM The day of the month (1–31)
MONTH The month (1–12)
DOW The day of the week (0–7) where 0 and 7 are Sunday.
*/2 * * * * (Every 2 mins )
Poll SCM:
Poll SCM periodically polls the SCM to check whether changes were made (i.e. new
commits) and builds the project if new commits were pushed since the last build.
*/2 * * * * (Every 2 mins )
Click on Build
Deployed successfully.