26
DecChristmas Special : Upto 40% OFF! + 2 free courses - SCHEDULE CALL
As we discussed in the last blog about the Jenkins download and installation(mainly on Linux CentOS machine). We started a discussion about Jenkins dashboard also, but that was too limited. Let's take that Jenkins installation one step further.
For now, let’s start creating our first job. If you click on “New Item” in your Jenkins dashboard, you will get different options of which type of job is required:
“Enter an item name” and select type of item (Jenkins job/project). Each project has its purpose defined & as per your requirement, click on the appropriate and press “OK”. It will navigate you to the job’s configuration page. Click on “Save”. Dummy project is ready !.
Let's together create a project for this blog. As mentioned in detail, we will discuss pipeline concepts and will create a dummy pipeline project. Now, we have taken this type because of its wide usage across many organizations. Other types are based on need but “Pipeline” is an idea finding its ways automatically in achieving CI/CD nature.
The first question will be -
It can be defined based on following two methods(or known as Jenkinsfile syntax):
Declarative pipelines are much more popular than Scripted, because of its abundant syntactical attributes and much better design which result in effortless reading/writing of Pipeline code. General snippet of Declarative Jenkinsfile syntax is as follows:
pipeline { agent any stages { stage('Checkout') { steps { //Checkout } } stage('Compile') { steps { //Compile Stage } } …… … } } Corresponding Scripted Jenkinsfile syntax: node { stage('Checkout') { //Checkout } stage('Compile') { //Compile } }
Jenkinsfile is defined in the parent directory of the source code project. For this blog, we will go with the most popular one that is, Descriptive. Jenkinsfile code is defined using Groovy DSL. Various characteristics of Jenkinsfile syntax:
Jenkins Pipeline attaches a powerful stack of automation tools that will support every kind of scenario from plain continuous integration of third-party tools to complex continuous delivery of final software. In a nutshell, the following are some of the key aspects provided by pipelines:
With the help of Jenkins pipeline, a CD can be achieved in a much faster way and frequent releases help in catching the failures/errors in the very early stage. The ongoing build will act as a base or provide feedback for subsequent future releases. Now, let’s go through Jenkinsfile examples.
Pipeline Script DEMO
1. Install the “Pipeline” plugin(if not installed). Go to Manage Jenkins → Manage Plugins
2. There are 4 tabs available, Go to Available(if not installed), otherwise, it will be present in the “Installed” tab.
3. Select Pipeline plugin and “Install without restart”. The plugin will be available in “Installed” tab after this
4. Go to Jenkins Dashboard, select New Item → Enter name → Select Pipeline → Click Ok
You will be moved to Job’s configuration page
5. In this Jenkinsfile examples, the Pipeline option, there will two types of definition available:
Pipeline Script
Here you will create your pipeline script in the below given text box with all stages defined. It’s like you were creating a Jenkins file in that Script box.
6.2. Pipeline Script from SCM
This means that you have to pick required Jenkinsfile from SCM(Source Code Management). Default options are “None”, “Git” or “Subversion”
Script Path → Path of your Jenkinsfile. If in the root directory(default location), simply write “Jenkinsfile”.
DevOps Training & Certification Course
We will try both options one by one. Let’s start with “Pipeline Script’ first to have a basic idea of flow from one stage to another.
6. In the backend, Jenkinsfile is based on Groovy syntax. Write the Jenkinsfile in script box and click ‘Save’
7. Click on “Build Now” and you will see different stages as blocks in the Job dashboard. See Console Output
And stage view:
It will show all stages and time taken to complete each stage. When you hover an arrow on each stage, you will see the “Logs” option. Clicking that “Logs” will show you the steps executed in that stage.
Pipeline Script from SCM - DEMO
4. In the Jenkinsfile, we are using two tools Maven and JAVA, so we have to configure these tools as well so that our Jenkinsfile can execute without any issue
Go to Manage Jenkins → Global Tool Configuration → Add JDK and Maven Installation like below:
I checked both as “Install Automatically”. If it is already installed in your machine, just provide the executable path instead of asking Jenkins to install automatically.
6. Click Save and configuration Done.
7. Click on Build Now. Now, from the console output, you will get the view that first it will download JDK8 and M3. Then proceed to each and every stage
8. Now, here we did build, unit test and do some post actions like “cleaning up workspace”. Post block will come after “stages”
9. Now, you can achieve CI/CD by adding different stages like
Above will be basic stages that will cater to the whole software cycle process. Similarly, post actions can be utilized in multiple ways:-
10.So, a variety of tasks and integration can be performed using Jenkinsfile.
DevOps Training & Certification Course
Some of the plugins that can enhance the view of Jenkins stage flow are:
Build PIpeline
Install “Build Pipeline plugin” from Manage Jenkins → Manage Plugins
This will connect different jobs to form a build pipeline.
Go to Jenkins Dashboard, Click on new view “+”
Select “Build Pipeline View”
Select Initial Job and let all be as Default. Click Save
Click on Run
Now, we will create one more job and add it to this pipeline. Go to previously create “Test-Pipeline” jenkins pipeline example job → configure and add
When you rerun “Build” job, it will trigger “Test-pipeline” job and you can create more complex pipelines like this:
Blue Ocean
Install “Blue Ocean” Plugin.
Once Installed, it will be visible in left side of dashboard
Click on “Open Blue Ocean”, Then you will see job list in a completely different view:
Click on “Test-Pipeline” and build whose status you want to see. YOu will get stage view like this:
As you can see, this beautifies the pipeline dashboard and gives various options like how build flows from Start to End, how much time, each build took, total time etc. In my personal opinion, this is the best dashboard that can be shared with upper management to give a much better understanding of the whole process.
DevOps Training & Certification Course
We discussed a lot about pipelines in this blog: Why pipeline, What is Pipeline, How to create pipeline, different views of pipeline etc. Try creating your own first pipeline and then discuss your success stories. After this, next, we will discuss JENKINS management.
See you soon !!
As an experienced DevOps professional, I am having a good understanding of Change and Configuration Management as well. I like to meet new technical challenges and finding effective solutions to meet the needs of the project. I believe in Sharing is Learning.
Cyber Security
QA
Salesforce
Business Analyst
MS SQL Server
Data Science
DevOps
Hadoop
Python
Artificial Intelligence
Machine Learning
Tableau
Search Posts
Related Posts
Receive Latest Materials and Offers on DevOps Course
Interviews