Launch 2nd EC2 instance
In this section we will launch another EC2 instance and copy the build file in it to another EC2 instance which was created by Jenkins.
Last updated
In this section we will launch another EC2 instance and copy the build file in it to another EC2 instance which was created by Jenkins.
Last updated
Launch a Amazon Linux Instance (follow the same steps used to launch the first instance)
Connect using SSH or Instance connect.
Now we need to authenticate a user to talk to another server so we can copy files and host it on Tomcat Server. We have ec2-user and root as users in our machine. We should never provide our root users credentials so we will use ec2-user here.
Connect to your Tomcat server using Putty/Instance connect.
type the following command to set passwd for ec2-user
which we wil use in next step.
Amazon is very conscious about security so it will so we need to edit a file named as
To enable SSH password authentication, you must SSH in as root to edit this file:
Then, change the line
to
After making that change, restart the SSH service by running the following command as root:
Follow the steps:
In Jenkins Dashboard, goto Manage Jenkins>> Manage Plugins >> and search "Publish over SSH" plugin. This plugin will help us share files among different servers using SSH.
Now GO to Manage Jenkins >> Configure system >> scroll down till you see " Publish over SSH " plugin section. Here we need to enter Tomcat server's details >> click on SSH servers >>
Name = Tomcat Server
Hostname = <public ip-adress>
username = ec2-user
Remote directry = .
In advance section
Enter the password
Click on Test configuration. You will get a Success message.
Now click on apply and save.
Perfect! Now we are all set and we can ping jenkins from Tomcat server. Lets create another job.
Go to Dashboard
Click on create New item >> Enter Name >> scroll down >> copy from (name of your first job to copy same settings)
Scroll to the bottom and in "Add post-build action" >> Send build artifacts over SSH >>
Fill in the details :
source files = path to build file (webapp/target/webapp.war)
remove prefix = webapp/target (to not create these folders)
remote directory = .
APPLY and SAVE
It says success let us check in our Tomcat server
In Tomcat server run ls
command
MAGIC!!!! Jenkins has successfully build/test provided build file and transferred it to Tomcat server. Isn't AUTOMATION amazing!
ALRIGHT! Let's run Build now and see the results :
In the Next Section we will learn about Docker and container