[

🎉

G2 Spring 2024 Report] Hatica does it again! Wins Momentum Leader, Best Est. ROI and Users Love Us badge among many!Read More ->

Tools2023-05-23

Setting Up Jenkins Pipeline on AWS

Set Up Jenkins Pipeline on AWS with our step-by-step installation process and configuration of Jenkins like Creating a Pipeline, setting up AWS credentials.
How to set up Jenkins Pipeline on AWS

Jenkins is an open-source automation tool that can be used for continuous integration (CI) and continuous delivery (CD) of software. It allows you to automate the build, test, and deployment process of your software and is widely used in DevOps. In this article, we will discuss how to set up a Jenkins Pipeline on AWS.

[Read more: Integrating GitHub Webhooks to a Jenkins Pipeline]

Prerequisites of Setting up Jenkins- AWS Integration

Before you begin setting up Jenkins on AWS, you will need the following:

  1. An AWS account
  2. A running EC2 instance on AWS
  3. A domain name for your Jenkins server

How to setup Jenkins Pipeline on AWS?

Here is a step by step guide to follow for setting up the Jenkins-AWS integration:

Step 1: Install Jenkins on your EC2 instance

To install Jenkins on your EC2 instance, follow these steps:

  1. Launch an EC2 instance running an Amazon Linux 2 AMI.
  2. Log in to the instance using SSH.
  3. Install Java by running the following command:
  4. Import the Jenkins GPG key by running the following command:
  5. Add the Jenkins repository to your Yum repository list by running the following command:
  6. Install Jenkins by running the following command:
command to install Jenkins

7. Start the Jenkins service by running the following command:

command to start Jenkins Service

8. Enable Jenkins to start on boot by running the following command:

command to start Jenkins on boot

Step 2: Configure Jenkins

Once Jenkins is installed, you need to configure it to work with AWS. Follow these steps to configure Jenkins:

  1. Open a web browser and navigate to http://<your-server-domain>:8080. You should see the Jenkins login page.
  2. Enter the default administrator password. You can find this password in the file /var/lib/jenkins/secrets/initialAdminPassword on your EC2 instance.
  3. Install the suggested plugins or select the plugins that you need.
  4. Create an admin user and configure the Jenkins URL.
  5. Click the "Save and Finish" button and then the "Start using Jenkins" button.

Step 3: Set up Jenkins Pipeline

Once Jenkins is configured, you can create a Pipeline to automate the build, test, and deployment process of your software. Follow these steps to create a Pipeline:

  1. Click the "New Item" button in the Jenkins dashboard.
  2. Enter a name for your Pipeline and select "Pipeline" as the type of project.
  3. Click the "OK" button.

In the Pipeline script section, enter the script that defines your Pipeline. Here's an example script:

example scripts for Jenkins pipeline aws steps

This script defines a Pipeline with three stages: Build, Test, and Deploy. In the Build stage, the script runs the Maven clean package command to build the project. In the Test stage, the script runs the Maven test command to run the unit tests. In the Deploy stage, the script runs the eb deploy command to deploy the application to AWS Elastic Beanstalk.

  1. Click the "Save" button to save your Pipeline.

Step 4: Set up AWS credentials

To deploy your application to AWS Elastic Beanstalk in the Deploy stage of your Jenkins Pipeline, you need to set up AWS credentials in Jenkins. Here's how to do it:

  1. Log in to your AWS console and go to the IAM service.
  2. Create a new IAM user or use an existing user.
  3. Attach the "AmazonEC2FullAccess" and "AWSElasticBeanstalkFullAccess" policies to the user.
  4. Generate an access key and a secret key for the user.
  5. In the Jenkins dashboard, click on "Credentials" on the left-hand menu.
  6. Click on "Global credentials (unrestricted)" and then click "Add Credentials".
  7. Choose "AWS Credentials" from the list of credential types.
  8. Enter a description for your credentials and enter the access key and secret key for your IAM user. Click "Save".

Step 5: Modify your Pipeline script to use AWS credentials

Now that you have set up AWS credentials in Jenkins, you need to modify your Pipeline script to use them. Here's how to do it:

  1. Open your Pipeline script in Jenkins.
  2. Add the following code at the beginning of your script:
code to modify pipeline scripts to use AWS credentials

This code creates environment variables for your AWS access key and secret key, and uses the credentials that you set up in the previous step.

Modify the Deploy stage of your script to use the AWS Elastic Beanstalk CLI. Here's an example script:

code to modify deploy script of Jenkins

This script sets the AWS region, Elastic Beanstalk application name, and Elastic Beanstalk environment name as environment variables. It then uses the withCredentials block to authenticate with AWS using the credentials that you set up earlier. Finally, it runs the eb init, eb use, and eb deploy commands to deploy the application to AWS Elastic Beanstalk.

Click the "Save" button to save your modified Pipeline script.

Looking to seamlessly integrate Jira with Jenkins step by step? Check out our detailed guide on How to Integrate Jira with Jenkins to enhance your development and issue-tracking processes.

Conclusion

In this article, we have discussed how to set up a Jenkins Pipeline on AWS. We covered the installation of Jenkins on an EC2 instance, the configuration of Jenkins, the creation of a Pipeline, if you are having issues with Jenkins taking a long time to build, you can check out our article on how to speed up Jenkins builds here! the set up of AWS credentials in Jenkins, and the modification of the Pipeline script to use AWS credentials. With this setup, you can automate the build, test, and deployment process of your software, making your software development process more efficient and reliable.

To get maximum efficiency out of Jenkins, an engineering analytics tool is the need of the hour. Hatica offers metrics across 13 dashboards, powered by CI/CD tools, Jira, Asana, Jenkins, and GitHub. By collating tool activities at one place, Hatica helps teams streamline their workflow, cut through the clutter of unwanted alerts, and improve productivity. Request a demo with Hatica today!

Subscribe to the Hatica blog today to read more about unblocking developers, and boosting productivity with engineering analytics. 

Subscribe to Hatica's blog

Get bi-weekly insights straight to your inbox

Share this article:
Table of Contents
  • Prerequisites of Setting up Jenkins- AWS Integration
  • How to setup Jenkins Pipeline on AWS?
  • Step 1: Install Jenkins on your EC2 instance
  • Step 2: Configure Jenkins
  • Step 3: Set up Jenkins Pipeline
  • Step 4: Set up AWS credentials
  • Step 5: Modify your Pipeline script to use AWS credentials
  • Conclusion

Ready to dive in? Start your free trial today

Overview dashboard from Hatica