Interview-2: DevOps Interview Questions
Jenkins Pipeline and it's types
Jenkins: Pipeline
A pipeline is a collection of steps or jobs which are interlinked with one another in a sequence.
Jenkins supports different plugins which help to implement CI/CD pipelines into Jenkins i.e., Git plugin, Build Pipeline plugin, Jenkins Maven plugin, Full Stage View…etc.
A pipeline can be written using two types of syntax- Scripted and Declarative.
Scripted Pipeline-
This is the original pipeline syntax for Jenkins, which is based on the Groovy scripting Language (old method to create the pipeline).
It provides a lot of flexibility and control over the workflow but it can be more complex.
Syntax-
Hands-On-
Let’s create a pipeline with a simple syntax and check for the pipeline “Full Stage View“-
Declarative Pipeline-
It’s a simpler approach or It’s a more recent addition to Jenkins and provides a more structured and simpler syntax for defining the pipelines.
The code is simplified because declarative syntax is more limited. You won’t be able to inject code into the pipelines whenever you want.
This type of pipeline is not worth it while working on a complex logic.
Syntax-
Hands-On -
Let’s create a pipeline with a simple syntax and check for the pipeline “Full Stage View“-
Scripted vs Declarative Pipeline-
1. Pipeline Code Validation-
Scripted Pipeline- Code Validation happens during the pipeline execution, which means at the very end stage only we will get to know about the errors or issues.
Example- We are deleting the echo message and then we will check in the full stage view after build-
Declarative Pipeline- Code Validation happens when the pipeline is loaded into the Jenkins, i.e., before running the pipeline.
Example-
2. Restart From Stage-
Scripted Pipeline- Restarting from a specific stage is not directly supported, we need to restart it from the beginning and it will consume more time as previously executed stages need to be repeated.
Declarative Pipeline- Restarting from a specific stage is supported and by this we can save time and resources by skipping already completed stages.
Example-
3. Skipping Stage-
Scripted Pipeline- All stages will be executed sequentially, there is no built-in support for skipping stages.
Declarative Pipeline- Supports skipping stages using the “when“ directive and allows conditional skipping of stages based on specified conditions.
Happy Learning!! 😁