how-to-build-a-cicd-pipeline-using-jenkins
how-to-build-a-cicd-pipeline-using-jenkins
An effective continuous integration (CI) and continuous delivery (CD) pipeline is essential for modern
DevOps teams to cope with the rapidly evolving technology landscape. Combined with agile
concepts, a fine CI/CD pipeline can streamline the software development life cycle resulting in
higher-quality software with faster delivery.
In this article, I will discuss:
(This article is part of our DevOps Guide. Use the right-hand menu to go deeper into individual practices
and concepts.)
What is Jenkins?
Jenkins is an open source server for continuous integration and continuous deployment (CI/CD)
which automates the build, test, and deploy phases of software development. With numerous
plugins you can easily integrate, along with choices of tools, programming languages, and cloud
environments, Jenkins is highly flexible and makes it easier to efficiently develop reliable apps.
Extensive plugin support: Whatever you want to do, there is likely already a plugin for it, which
speeds and simplifies your work.
Active open source community: Being free of licensing costs is just the beginning. It is
supported by an active community, contributing solutions, advice, ideas, and tutorials.
Platform independent: You are not tied to a specific operating system.
Scalable: You can add nodes as needed and even run builds on different machines with
different operating systems.
Integratable: Whatever tools you are using, you can likely use them with Jenkins.
Time-tested: Jenkins was one of the first CI/CD tools, so it is tried and true.
1. The developer writes the code and commits the changes to a centralized code repository.
2. When the repo detects a change, it triggers the Jenkins server.
3. Jenkins gets the new code and carries out the automated build and testing. If any issues are
detected while building or testing, Jenkins automatically informs the development team via a
pre-configured method, like email or Slack.
4. The final package is uploaded to AWS Elastic Beanstalk, an application orchestration service,
for production deployment.
5. Elastic Beanstalk manages the provisioning of infrastructure, load balancing, and scaling of the
required resource type, such as EC2, RDS, or others.
The tools, processes, and complexity of a CI/CD pipeline vary from this example. Much depends on
your development requirements and the business needs of your organization. Typical options
include a straightforward, four-stage pipeline and a multi-stage concurrent pipeline — including
multiple builds, different test stages (smoke test, regression test, user acceptance testing), and a
multi-channel deployment (web, mobile).
pipeline {
agent any
stages {
stage('Hello') {
steps {
echo 'Hello World'
}
}
}
}
We can verify that the pipeline has been successfully executed by checking the console output for
the build process.
Step 7: Expand the pipeline definition
Let's expand the pipeline by adding two more stages to the pipeline. For that, click on the
"Configure" option and change the pipeline definition according to the following code block.
pipeline {
agent any
stages {
stage('Stage #1') {
steps {
echo 'Hello World'
sleep 10
echo 'This is the First Stage'
}
}
stage('Stage #2') {
steps {
echo 'This is the Second Stage'
}
}
stage('Stage #3') {
steps {
echo 'This is the Third Stage'
}
}
}
}
Save the changes and click on “Build Now” to execute the new pipeline. After successful execution,
we can see each new stage in the Stage view.
The following console logs verify that the code was executed as expected:
Good luck!
Cloud-based Azure CI/CD pipeline example
With the increased adoption of cloud technologies, the growing trend is to move the DevOps tasks
to the cloud. Cloud service providers like Azure and AWS provide a full suite of services to manage
all the required DevOps tasks using their respective platforms.
The following is a simple cloud-based DevOps CI/CD pipeline entirely based on Azure (Azure
DevOps Services) tools.
1. A developer changes existing or creates new source code, then commits the changes to Azure
Repos.
2. These repo changes trigger the Azure Pipeline.
3. With the combination of Azure Test Plans, Azure Pipelines builds and tests the new code
changes. (This is the Continuous Integration process.)
4. Azure Pipelines then triggers the deployment of successfully tested and built artifacts to the
required environments with the necessary dependencies and environmental variables. (This is
the Continuous Deployment process.)
5. Artifacts are stored in the Azure Artifacts service, which acts as a universal repository.
6. Azure application monitoring services provide the developers with real-time insights into the
deployed application, such as health reports and usage information.
In addition to the CI/CD pipeline, Azure also enables managing the SDLC using Azure Boards as an
agile planning tool. Here, you’ll have two options:
Related reading
BMC DevOps Blog
SRE vs DevOps: What’s The Difference?
How Containers Fit in a DevOps Delivery Pipeline
How & Why To Become a Software Factory
Book Review of The Phoenix Project: DevOps For Everyone
Enterprise DevOps: Increase Agility Across the Enterprise