How to Build Angular Application in jenkins ?
Last Updated :
26 Apr, 2024
Jenkins is a popular tool for Continuous Integration. Using Jenkins, we can externalize the build process for our code. It allows teams to collaborate more efficiently and deliver software in shorter cycles. In this article, we will learn how to build an angular app in Jenkins.
Pre-Requisites
Clone the Code By using the below link.
"https://github.com/StellarStrategist/jenkins-angular.git"
Step 1: Install NodeJS on your system
For the purpose of this tutorial, I have a NodeJS installed on my Windows machine.
- Install NodeJS on Windows
- Install NodeJS on Linux
- Install NodeJS on MacOS
- Install NodeJS on your system
Step 2: Create a new Angular Project
Open the terminal on your machine and type the following command:
ng new my-angular-app
This command creates a new angular project on your machine by the name of my-angular-app. Choose any routing and styling settings you want and generate. Remember the directory where you have created this project. Leave it as it is for now.
Step 3: Install Jenkins on your system
Next, please make sure you have Jenkins up and running on Linux. There are many ways to use Jenkins depending on your needs. For this tutorial, I have set up Jenkins using a virtual machine. To learn how to install Ubuntu in a virtual box click here. Then, please refer to the following links to install Jenkins.
- Install Jenkins in AWS EC2
- Install Jenkins in Debian Linux
Step 4: Add Jenkinsfile to your project
Now, open the project you created earlier in your IDE and create folder called Jenkins inside the root directory of your project. Create another folder called scripts inside this folder. This folder will hold our bash scripts.
Create two text files inside this folder called deliver.sh and kill.sh.
The content for deliver.sh will be as follows:
#!/usr/bin/env sh
npm run ng build
npm run ng serve &
sleep 1
echo $! > .pidfile
echo 'Now...'
echo 'Visit http://localhost:4200 to see your Node.js/Angular application in action.'
This script is responsible for building and serving your angular application.
The content for kill.sh will be as follows:
#!/usr/bin/env sh
kill $(cat .pidfile)
This script will properly close down your angular application.
Now create another file in the root directory of your project called the Jenkinsfile. This file will contain all the settings that jenkins will read from when it fetches code from GitHub.
The content of Jenkinsfile is as follows:
pipeline {
agent any
tools {nodejs "NODEJS"}
stages {
stage('Build') {
steps {
sh 'npm install'
}
}
stage('Deliver') {
steps {
sh 'chmod -R +rwx ./jenkins/scripts/deliver.sh'
sh 'chmod -R +rwx ./jenkins/scripts/kill.sh'
sh './jenkins/scripts/deliver.sh'
input message: 'Finished using the web site? (Click "Proceed" to continue)'
sh './jenkins/scripts/kill.sh'
}
}
}
}
Make sure that your directory structure matches the following:
Directory StructureStep 5: Upload Code to GitHub
Create a git repository and set it up to hold with your angular code. For the purpose of this tutorial, please keep the repository as public.
Now we will see how to build our angular application using Jenkins.
Step 6: Install Git in your Linux Environment
Git is necessary for communication between GitHub and Jenkins. To install git in Ubuntu, run the following command in your terminal:
sudo apt install git-all
How to build angular application using Jenkins?
Step 1: Install the plugin support for Jenkins
Open your Jenkins dashboard and on the side panel, click on manage Jenkins:

After this, click on plugins:

Now, click on the Available plugins option:

Type NodeJS in the search box and click install for the following plugin:

After the plugin has installed, click on the following option:

This takes you back to the manage Jenkins page.
Step 2: Configure the tool setup in Jenkins
Now, click on the Tools option on the Manage Jenkins page:

Scroll to the Section of NodeJS and click on the Add NodeJS button:

This will option the following form, fill it according to the image provided:

Make sure that the Name is exactly the same as in the image, otherwise Jenkins will not be able to build your project. Now we will create our Jenkins job to build our angular application.
Step 3: Create a new Jenkins Job
In your dashboard click on the create a job option:

type a name for your pipeline and click on pipeline and click OK:

Enter some description for your pipeline if you want:

Go to your GitHub repository and copy the public URL of your project:

Now configure pipeline settings as follows:

Specify the name of the branch you want to build and the path to the Jenkinsfile. Then click on save:

Step 4: Build your Project
Proceed to the homepage of your job and click on build-now:

The build progress appears in the side navigation bar along with the build number as follows:
.jpeg)
Click on the build number. This will allow you to view everything about the current build. On left hand side, click on the 'View-Console' option as follows:
.jpeg)
Now, you will be able to see the entire build process as it happens. Wait till you the message 'your application is live on port 4200'. When you see this, visit http://localhost:4200 in your browser. You will see that your angular application is running through the Jenkins pipeline which you have created. In case you don't see the output, wait for sometime and reload the page.
.jpeg)
This will take you to your angular application as:
.jpeg)
When you have completed using your page, head to the view-console page and click on the 'Proceed' button as follows:

Output
Upon clicking the proceed button, your kill.sh file is run by Jenkins. This stops the angular application from running and you can see the message 'Finished: SUCCESS' on your console as follows:
.jpeg)
This indicates that the build was a success.
Conclusion
In this article we covered a lot of things. We setup our computer to build our projects using Jenkins and also learnt how we can do so through Virtual machine. We hosted our code on a source code manager and externalized our build process using Pipeline-as-a-code. The code we wrote for our file was in the form of a bash script. Next, we viewed our running application and afterwards, we successfully stopped the process and completed our build. That were indeed a lot of things. If you faced any unwanted errors, please feel free to discuss in the comments below.
Similar Reads
How To Build Java Application In Jenkins ?
In the software development lifecycle, building and testing applications are basic steps toward ensure code quality and dependability. Jenkins, an open-source automation server, plays a vital role in automating these cycles, especially for Java applications. Java, being one of the most generally uti
7 min read
How to Build Python Application Using Jenkins ?
Jenkins is one of the most popular automation tools used worldwide for Continuous Integration and Continuous Delivery. It is a free and open-source automation server that enables developers to build, integrate and test the code automatically as soon as it is committed to the source repository. Build
7 min read
How to Build React App in Jenkins?
Jenkins is a popular tool for Continuous Integration. Using Jenkins, we can externalize the build process for our code. It allows teams to collaborate more efficiently and deliver software in shorter cycles. In this article, we will learn how to build a react app in Jenkins. Steps To Install Jenkins
7 min read
Deploying An Application Using Jenkinsfile
In the IT world, initially, there were silos between the development and testing teams that created delays in moving the application to user availability. DevOps came into the picture with a culture practice that brings automation with a lot of tools. Jenkins is one of the popular CI/CD tools. Jenki
5 min read
How to Deploy Angular App in Kubernetes ?
In the modern world of web development, Angular has become one of the most popular frameworks for building dynamic and responsive web applications. As the demand for scalability and reliability increases, deploying these applications in a containerized environment using Kubernetes has become a commo
5 min read
What are the main building blocks of an Angular Application?
Angular is a widely used open-source front-end framework used to build dynamic web applications. It consists of several key building blocks that work together to create scalable, and maintainable applications. In this article, we will explore all the main building blocks of an Angular application an
8 min read
Deployment Of Spring Boot Application In Jenkins
In this article, we will be exploring how to automate the process of building Spring Boot applications by employing a polling trigger. We will also learn how to generate reports and store artifacts in the process. To achieve this, we will be leveraging the Jenkins server. Our goal is to create a pip
5 min read
How to Add GIT Credentials in Jenkins?
Git is a famous distributed version control system. Version Control Systems are mainly two types. Distributed & Centralised Version Control System. Centralized Version Control Systems are older & very hectic to use. That is why Distributed Version Control Systems are nowadays very famous for
5 min read
How to Install Bootstrap in Angular?
If you have completed your practice in the field of HTML & CSS and want to develop more interesting and attractive webpages in the future, moving ahead for the Bootstrap topic along with the Angular concept will be appropriate for you. However, to have Bootstrap on your Angular Project you shoul
5 min read
Create Angular Application with SCSS
Angular is a popular JavaScript framework for building web applications. It provides a set of tools and libraries for building client-side applications using modern web technologies. Sass (Syntactically Awesome Style Sheets) is a CSS preprocessor that adds powerful features to CSS, such as variables
6 min read