1. What is Pipeline?
Jenkins pipeline allows us to define a complete list of events that happen in the code lifecycle. Starting from the build to testing and deployment. We can use a set of plugins that help in the implementation of certain processes as a continuous delivery pipeline.
2. What is Jenkins File:
Jenkins Pipeline is defined using a text file called the Jenkinsfile. Additionally, the pipeline implements code using Groovy Domain-specific language through an editor or the configuration page on the Jenkins instance. Moreover, the Jenkinsfile gives leverage to the developer to easily access, edit, or check the code anytime.
3.Types Of Pipeline in Jenkins:
Scripted :
the scripted pipeline syntax is the old traditional way to write the Jenkinsfile on Jenkins web UI. Moreover, it strictly follows the groovy syntax and helps to develop a complex pipeline as code.
Declarative: The declarative syntax is a new feature that uses code for the pipeline. It provides a limited pre-defined structure. It offers an easy & simple continuous delivery pipeline. Moreover, it uses a pipeline block.
Pipeline - A pipeline is a set of instructions that includes the processes of continuous delivery. For example, creating an application, testing it, and deploying the same. Moreover, it is a critical element in declarative pipeline syntax, which is a collection of all stages in a Jenkins file. We declare different stages and steps in this block.
Node: A node is a machine that is part of the Jenkins environment and is capable of executing a Pipeline.
node block is mainly a part of the Scripted pipeline syntax.
Stage: A stage consists of a set of processes that the Pipeline executes and the tasks are divided in each stage.
Steps: A step in Jenkins defines what we have to do at a particular stage in the process. There can be a series of steps within the stage.
Agent: An agent is a directive that enables the users to execute multiple projects within the same Jenkins instance by distributing the load. You can either use a single agent for the entire pipeline or use a distinct agent for the different stages of the pipeline.
4. Why Should We Use Jenkins Pipeline?
The pipeline can be run in a loop.
Since the Jenkins pipeline is written in code, any number of users can use it as a template, modify it, and run customized tests and processes.
Multiple jobs can be run in parallel.
Jenkins Pipeline is robust. The pipeline can automatically be resumed from it might have stopped for any reason.
5. Tasks To Do:
Create a New Job, this time select Pipeline instead of Freestyle Project.
Follow the Official Jenkins Hello world example
Complete the example using the Declarative pipeline
First Start your Jenkins instance and then log in to your Jenkins dashboard.
Step 1:
Click on New Item in your Jenkins dashboard and then give your project any name.
But this time as we are creating a declarative pipeline project, so don't select here Freestyle Project, Select Pipeline.
Step 2:
Now give your project a description as per your choice.
Step 3:
Scroll down to the same page and come into the pipeline section, as Jenkins pipeline follows the groovy syntax and this is a declarative pipeline.
Pipeline: This is a mandatory block and the declarative pipeline will always start with this block.
Agent: The agent is where the Jenkins build job should run. Here, we have selected agents as any.
Stages/Stage: Stages block consist of different stage blocks. There should be at least one stage block inside the stages.
You can give any name to your stage block, here it is named Build
Steps: Steps blocks consist of the actual operation that needs to be performed inside Jenkins. Here print the simple hello world by using the echo command.
Step 4:
If you click on the Build Now option, you can see the pipeline is running successfully. But if it fails in any stage then your pipeline will turn red at that stage and it won't proceed into the next stage.
Step 5:
This is the console output page.
Thank you for reading. I hope you were able to understand and learn something new from my blog.
Happy Learning!