In top menu, click on Services and then click on EC2 under Compute section
In the left menu sidebar, under NETWORK & SECURITY click on
Here, click on the blue button Create Security Group
In Security group name type
In Security group rules click on Add Rule button.
Add a new rule:
Add a new rule:
and click on Create
First, copy to clipboard the group id for the security group that you have just created
Then Click on Create Security Group
In Security group name type
Click on Add Rule
Click on Add Rule
Programmatic access and then click on Next: Permissions
Now, your user should not have any permissions now. Let's add them:
Add the following JSON code
"Version": "<here you can add your current date>",
In AWS Management Console click on EC2 under Compute service
Click on Launch Instance. Here select Amazon Linux 2 AMI (HVM), SSD Volume Type
In the next window select at least t2.small and then click on Next: Configure Instance Details
You don't need to change anything in this window so click on Next: Add Storage
On Step 4, change the SSD size from 8GB to 10GB or more (Master jenkins will not run any code and it doesn't need so much space).
Next, click on Next: Add Tags. Here click on Add Tag and for Key type
Name and for Value type
Then click on Next: Configure Security Group
Here, on Assign a security group click on the second option: Select an existing security group and then select the group named jenkins-master that you created in the first step.
Then click on the blue button Review and Launch and then Launch button.
In this step you will be prompted to select or to create a key pair. If you don't have it, then create a new one and download it.
If you create a new key pair make sure you change the permissions to the file by running the following command:
chmod 0400 my-key.pem. Replace my-key.pem with the real file name.
Connect to new created instance for the next steps
ssh -i /path/to/my-key.pem ec2-user@<master_server_public_ip>
Do not add any password for the key. You'll need it to connect to the agent server later
sudo yum install java-1.8.0-openjdk.x86_64
After the installation, you can confirm it by running the following command:
This command will tell you about the Java runtime environment that you have installed:
openjdk version "1.8.0_91"
OpenJDK Runtime Environment (build 1.8.0_91-b14)
OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)
In order to help Java-based applications locate the Java virtual machine properly, you need to set two environment variables: JAVAHOME and JREHOME.
sudo cp /etc/profile /etc/profile_backup
echo 'export JAVA_HOME=/usr/lib/jvm/jre-1.8.0-openjdk' | sudo tee -a /etc/profile
echo 'export JRE_HOME=/usr/lib/jvm/jre' | sudo tee -a /etc/profile
Finally, you can print them for review:
Use the official YUM repo to install the latest stable version of Jenkins, which is 2.150.2 at the time of writing:
sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
yum install jenkins
Start the Jenkins service and set it to run at boot time:
sudo systemctl start jenkins.service
sudo systemctl enable jenkins.service
In order to allow visitors access to Jenkins, you need to allow inbound traffic on port 8080:
sudo firewall-cmd --zone=public --permanent --add-port=8080/tcp
sudo firewall-cmd --reload
sudo /etc/init.d/jenkins start
Now, test Jenkins by visiting the following address from your web browser:
After opening this url in the browser you should see a page with the title Unlock Jenkins
Grab the acministrator password and add it into the field:
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
After you click Continue, click on Install suggested plugins button and wait until jenkins install it's needed plugins.
Whenn plugins are installed you'll be prompted with Create First Admin User form page. Fill in the form to create the Admin user as you wish and then click on Save and Continue
On Instance Configuration page click Save and Finish then Start using Jenkins
Now you should be able to have Jenkins up and running.
Create a new server instance as you did with the master, but select select Ubuntu Server 18.04 LTS (HVM), SSD Volume Type as server type, jenkins-agent as security group and set the name jenkins-agent
ssh -i /path/to/my-key.pem ubuntu@<agent_server_public_ip>
On jenkins master server run the following command and copy the output
On agent server add the output of the previous command to
echo '<paste here the id_rsa.pub content>' >> ~/.ssh/authorized_keys
To check if it works, connect to jenkins master server and run the following command:
it should connect to jenkins agent server without problems
SSH into agent server and install java 1.8
sudo apt-get update
sudo apt-get install -y openjdk-8-jdk
If your project requires additional dependencies, install them as well
sudo apt-get install openssh-server
Create a jenkins directory on the agent server
Open the jenkins url in the browser and navigate to Manage Jenkins > Manage Plugins
Click on Available and in the top right side on the Filter search type
ec2. Then select
Amazon EC2, then search for
SSH and add
SSH Agent plugins and then click Download now and install after restart
It will redirect you to a page when you see a list of plugins and the current status and below you have an option to restart jenkins when installation is complete. Click that checkbox and wait until is ready. You may refresh the page.
When the installation is complete, click again on Manage Jenkins, then click on Manage Nodes, click on Master then in the left sidebar click on Configure. In this form, change from 2 executors to 0 (zero) executors. Master jenkins doesn't need to run any job. Only agents will do this.
Navigate to Manage Jenkins > Configure System and in the bottom you'll find Cloud. Here click on Add a new cloud and select Amazon EC 2
Add jenkins agent
/home/ubuntu/ for Remote FS root
ubuntu for Remote user
sudo for Root command prefix
22 for Remote ssh port
jenkins-agent for Labels (you can set different values here to target specific pipelines)
1 for Number of Executors
Name for Name and
jenkins-agent for Value
Now click on Save to save your changes
From here, you can configure the agent server as you wish and save it as an AMI that you'll use in your projects