Jenkins CI is an automation server used to build, test and deploy software. This tutorial will walk you through configuring a Jenkins Pipeline which can run automatically on every push to the GitLab Server.
Jenkins CI is a tool that allows users to create pipelines for building and testing software. The “jenkins ci/cd pipeline example” will show how to create a Jenkins CI CD Pipeline.
Jenkins provides built-in support for Continuous Integration/Continuous Delivery (CI/CD), in case you didn’t know. Your software development process may be considerably improved by incorporating a Jenkins CI CD pipeline into your project.
Jenkins is one of the most widely used DevOps automation technologies on the market today. You’ve also come to the proper spot if you’re wanting to get started with the Jenkins CI CD pipeline.
Continue reading to discover how to build up a Jenkins CI CD pipeline using GitHub in this article.
The Best DevOps Tools in 2021 for DevOps Automation
To follow along with the examples in this lesson, you must meet the following criteria.
Jenkins must already be installed on your system. Jenkins v2.319.1 on a Windows 10 20H2 PC will be used in the examples in this course.
The Best DevOps Tools in 2021 for DevOps Automation
- Jenkins’ web console must be able to be accessed through the internet.
- You’ll need a Github account to connect to the Jenkins CI CD pipeline.
- Git SCM stands for version control system. The newest (2.34.1) 64-bit version of Git for Windows is used in this tutorial.
Getting the GitHub Repository Ready
The goal of this tutorial is to connect a Jenkins CI CD pipeline to a GitHub repository. It’s easier to get started by forking an existing repository than than starting from scratch.
1. Log in to your GitHub account by opening a browser and entering your username and password.
2. Next, go to the URL for the sample repository (MyShuttle2 application from Microsoft Connect 2016). Click the Fork button on the top-right area of the website once you’re on the repo page.
Creating a fork of a repository
Allow for the completion of the forking procedure. By the Conclusion, you’ll have a GitHub account with a repository entitled “username/MyShuttle2” to which you have complete access.
3. Next, create a Jenkinsfile file in the repository. A Jenkinsfile is a text file that includes a Jenkins Pipeline’s definition. This file should be kept in the repository of source code.
On your repository page, click Add file —> Create new file.
Adding a new file to the list
4. For the new file’s name, type Jenkinsfile. Next, copy and paste the code below into your Jenkinsfile.
- The phrase pipeline refers to a series of code instructions for continuous delivery.
- A stage block visualizes the Jenkins pipeline process by including a sequence of pipeline phases.
- A step is a single task that performs a given job at a specific time. A pipeline is a collection of steps.
This Jenkinsfile is just a simple pipeline script sample. Pipeline scripts in production will be more complicated, with several actions on one or all stages.
pipeline agent at any time steps echo ‘Building..’ stage(‘Build’) stage(‘Build’) stage(‘Build’) stage(‘Build’) stage(‘Build’) stage(‘Build’) stage(‘Build’) stage(‘Build’) ‘Testing….’ stage(‘Deploy’) steps echo ‘Deploying….’ stage(‘Test’) steps echo ‘Testing….’
After you’ve finished creating the code, your file should look like the one below.
Script for Jenkinsfile pipeline
5. Scroll to the bottom of the screen and choose Commit new file from the drop-down menu.
Adding a new file to the repository
On your repository, you now have a Jenkinsfile.
A new Jenkinsfile has been added to the GitHub repository.
6. Finally, make a note of the repository’s URL. To do so, go to Code and choose Copy from the drop-down menu. During the Jenkins CI CD pipeline construction, you’ll need the resultant URL.
Copying the URL of the repository
Creating a Jenkins Continuous Integration and Continuous Delivery Pipeline
Developing a feature requires several code modifications. A series of chores must be completed between each code update. Committing changes, compiling, testing, and packaging are examples of these activities.
Jenkins and other automation systems aid in making these tasks quick and error-free.
1. Log in to Jenkins by opening a browser and going to the Jenkins URL.
2. On the Jenkins Dashboard, go to the left-hand menu and choose New Item.
In Jenkins, you may make a new item.
3. Give your new pipeline a name. You’ll call it demoPipeline and use the Pipeline template for this lesson. To finish, click OK.
Putting up a Pipeline project
4. On the settings page’s General tab, check the GitHub project box. Then, in the Project URL field, put the repository URL you copied previously.
Adding the URL to the GitHub repository
5. Check the GitHub hook trigger for GITScm polling box in the Build Triggers section, as seen in the picture below.
Choosing a build trigger
6. Next, scroll down to the Pipeline section and select/specify the values shown below:
- Definition: SCM pipeline script
- SCM: Git
- Repository URL: This is the URL of your repository.
Defining the pipeline’s parameters
7. Scroll to the bottom of the page and double-check that Jenkinsfile is the Script Path value. This number refers to the Jenkinsfile you prepared previously as part of the Github repo preparation process. Finally, click the Save button.
The pipeline configuration is saved.
Using GitHub to set up a Webhook
You must first build a webhook in the GitHub repository before Jenkins can launch a new task. This webhook will alert Jenkins whenever a new push is made to the repository.
To create a Webhook, follow the instructions below.
1. Go to your GitHub repository’s Settings page and choose the Webhooks tab. Click Add webhook on the Webhooks page.
Including a webhook in the mix
2. In the Payload URL box, insert /github-webhook/ to your Jenkins URL. HTTP://jenkinsURLhere/github-webhook/, for example.
Change the Content type to application/json as well.
Specifying the URL and content type for the webhook
3. Pick the Let me select specific events option under Which events would you wish to trigger this webhook selection.
Individual events are chosen.
4. Scroll down and choose the Checkboxes for Push and Pull Requests. Using these parameters, GitHub will send a payload to Jenkins at these specified occurrences.
Enabling events for Push and Pull requests
5. Click the Add webhook button at the bottom to validate the webhook. If the webhook validation was successful, you’d get a notice similar to the one shown below at the top of the page.
Notification of webhook creation
Create a Jenkins Build Job to Automate Web Deployments Related:Create a Jenkins Build Job to Automate Web Deployments
Jenkins CI CD Pipeline Job Execution and Triggering
How do you know your pipeline is working now that you’ve constructed and configured it? Jenkins has a Pipeline Stage View plugin that allows you to see the state of your pipeline.
1. Open the pipeline in Jenkins and choose Status from the drop-down menu. Because there hasn’t been an event that would activate the pipeline, the Stage View status indicates No data available, as seen below.
View of the Jenkins pipeline stage
2. Click Build Now to create initial construction data and wait for the build process to finish. As you can see in the screenshot below, the Stage View now just contains one entry, indicating that no modifications have been made in this release.
Click Build Now to create basic build data.
3. Now, test the pipeline by committing a new dummy file to the repository. To do so, go back to your GitHub repository and click click Add File —> Create new file.
Make the new file’s name dummy and make sure it has content.
Creating a new document
Finally, at the bottom of the page, click Commit new file.
4. Return to the Jenkins pipeline status page and look for a new build item with one commit, as shown below.
Build status of Jenkins pipeline
You’ve learnt how to build up a Jenkins CI CD pipeline to automate the software development lifecycle in this article. You’ve also learnt how to utilize Jenkins to keep a CI chain in a software project going.
Do you believe using the Jenkins CI CD pipeline for your projects is a good idea? Or do you already have anything in place that you think is a superior CI/CD solution?
Jenkins CI is a continuous integration and continuous deployment tool. This article will teach you how to create a Jenkins CI CD pipeline that uses Amazon Web Services as the backend for your infrastructure. Reference: ci/cd pipeline jenkins aws.
- jenkins kubernetes pipeline example
- ci/cd pipeline using jenkins devops tutorial
- ci/cd pipeline jenkins docker step by step
- ci/cd pipeline using jenkins git and maven
- ci/cd pipeline jenkins interview questions