Effortless Angular Application Deployment with Jenkins Pipeline on AWS Infrastructure: A Step-by-Step Guide
Bhagyashree Sahu
SDET| Immediate Joiner| ISTQB Certified | Quality Assurance | Manual Testing | Selenium | Java | Software, API, Mobile App testing | Rest Assured | Telecom | Insurance | Core Banking and Finance |
In the realm of continuous integration and continuous delivery (CI/CD), Jenkins has emerged as a powerhouse tool for automating and orchestrating the software delivery process. One of its most powerful features is the Jenkins Pipeline, a suite of plugins that allows you to define and automate your entire software delivery pipeline as code.
In this article, we'll delve into the world of Jenkins Pipelines, exploring their benefits, and components, and how to set up a Jenkins Pipeline to automate the deployment of your Angular application on AWS infrastructure, ensuring efficiency, reliability, and rapid software delivery.
Understanding Jenkins Pipelines:
A Jenkins Pipeline is a set of instructions that define how your software is built, tested, and deployed. These instructions are written in a domain-specific language known as the "Pipeline DSL" or can be defined using the newer "Declarative Pipeline" syntax. Jenkins Pipelines enable you to version control your entire CI/CD process alongside your application code.
Benefits of Using Jenkins Pipelines:
Reproducibility: Pipelines ensure consistent and reproducible builds across different environments, reducing the chances of unexpected issues during deployment.
Version Control: Pipelines as code can be stored in version control systems, enabling collaboration and tracking changes over time.
Flexibility: Pipelines are customizable and adaptable to complex workflows, incorporating different stages such as building, testing, deploying, and more.
Visibility: Pipelines provide clear visibility into each stage of the software delivery process, making it easier to diagnose failures and optimize performance.
Automated Triggering: Pipelines can be triggered automatically on code commits, pull requests, or scheduled intervals, reducing manual intervention.
Components of a Jenkins Pipeline:
Agent: Specifies where the pipeline will be executed, either on the Jenkins master or on a specific node.
Stages: The primary building blocks of a pipeline, each stage represents a phase of the software delivery process, such as building, testing, and deploying.
Steps: Each stage consists of one or more steps, which are individual tasks or commands executed sequentially.
Post Actions: Actions that are executed after all stages, such as sending notifications or cleaning up resources.
Prerequisites:
1.??????Basic familiarity with Angular framework.
2.??????AWS account with administrative access.
3.??????Proficiency in Jenkins and understanding of Jenkins Pipelines.
Step 1: Configure Your AWS Resources:
1.??????Launch an EC2 instance to host your Angular application. Configure security groups, key pairs, and instance types.
2.??????Set up an RDS instance or any necessary database services for your application data.
3.??????Check the RDS status by connecting it to DBeaver
4.??????Set up necessary prerequisites on the QA server: (As discussed in my previous article)
·????????Execute sudo apt update then install java , apache2
·????????Install node js : sudo apt install nodejs.
·????????Implement sudo apt install npm.
·????????Install sudo npm install -g n
Step 2: Prepare Your Angular Application:
1.??????Ensure your Angular application is well-structured and organized for production.
2.??????In Backend code, under db.cnfig.js file , Copy the End point of RDS in Host and run below command: npm install , npm start
Step 3: Set Up GitLab Repository:
1.??????Create a GitLab project to host your Angular application's source code.
2.??????Push your application code to the GitLab repository. Maintain version control for streamlined development.
3.??????Now the local Backend folder has reached to git lab. From here we can easily connect to Jenkins
By copying this url - https://gitlab.com/angular_application/my-tutorial-be
Step 4: Configure Jenkins:
1.???????????Install Jenkins on a dedicated EC2 instance (refer my post-3 of #learningjourney)
2.??????????Launch a Jenkins master instance and an EC2 instance 'QA' for the slave node.
3.???????????Add the slave node to the Jenkins master:
?????????????Navigate to "Manage Jenkins" > "Manage Nodes and Clouds" > "New Node".
?????????????Configure the node settings and provide the necessary credentials.
Step 5: Set Up Jenkins Pipeline:
1.??????Create a new Pipeline name as “Backend deployment pipeline”
2.?????This pipeline can be executed on any agent, identify the agent by label - QA
3.??????Define your pipeline stages:
领英推荐
Save and build now
4. Checkout source code from your version control system (e.g., GitLab).
Click on pipeline syntax?and give backend repository URL and Git lab credentials
Configure GitLab or your preferred version control system to trigger the Jenkins Pipeline on code changes.
Include polling and changelog:
Click on Generate Pipeline Script
Copy paste generated pipeline script
Save and Build now
Give shell script command – sh ‘ls’
Save and build now
5.??????Install Node.js and required dependencies.
Create a new stage ‘Install’ to Install dependencies
Write commands in single code
Save and build now
Verify Stage logs of Install
Step 6: Configure Deployment onto the QA Server:
·????????Arrange the build procedures to conduct dependency installation through npm install and application initiation using npm start.
Start the application using PM2:
sudo pm2 start npm --name "be" – start
Add another stage - 'Code Analysis'?to check coding standard of the project
Save and trigger the build
Post Build Action:
?6. ?Archive the build artifacts.
Step 7: Test the Deployment:
Access the public IP or DNS of your EC2 instance in a web browser to verify successful deployment.
Step 8: Monitor and Maintain:
Implement monitoring tools to keep track of your deployed application's health and performance.
Regularly update your application, dependencies, and AWS infrastructure as needed.
Customizing Your Pipeline:
Jenkins Pipelines can be extended with plugins to integrate with various tools and services. You can add conditional logic, parallel execution, error handling, and even integration with Docker or Kubernetes for containerized deployments.
Conclusion:
Jenkins Pipelines empower development teams to establish efficient, automated, and consistent software delivery workflows. By defining your pipeline as code, you ensure transparency, repeatability, and agility in your development process. Whether you're deploying web applications, microservices, or mobile apps, Jenkins Pipelines pave the way for successful CI/CD practices, enabling you to deliver high-quality software to your users faster and with confidence.