What are Pipelines in Jenkins ๐ค ?
The pipeline is a plugin in the Jenkins tool.
The pipeline is written in code(or)script which follows groovy syntax.
It is a collection of steps or jobs interlinked in a sequence.
It helps in implementing and Integrating Continuous Delivery pipelines.
It can automate version control system users and customers.
Jenkins provides plugins to pipelines as well.
We can write code in a Jenkins file and store it in source code management as a file as well.
Types of Jenkins Pipeline.
They are two types:
Scripted Pipeline:
This code is written using groovy syntax and this is the first type of pipeline used in Jenkins.
It will contain stages only.
Let us see an example of a Scripted Pipeline.
node {
stage (โBuildโ {
//...
}
stage (โTestโ) {
//...
}
}
Declarative Pipeline:
It was an updated form of the scripted pipeline and added some extra tags to it and it will also follow groovy syntax only.
The pipeline will be head and all the script is written inside the pipeline tag.
Agent defines where the pipeline will be run, similar to the node for the scripted one.
Stages contain all of the stages.
pipeline {
agent any {
stages {
stage('Build') {
//....
}
stage('Test') {
//....
}
}
}
}
Let us run a Hello world Jenkins Declarative pipeline ๐ธ.
Log in to Jenkins and select New Item in Jenkins Dashboard.
Enter the Name of your choice to Job and select pipeline and click ok.
Enter the Description of your choice.
Go to the pipeline section and enter the script.
pipeline { agent any stages { stage ('Hello') { steps { echo 'Print Hello World! in console.' } } } }
If you want to get the script automatically you can select the dropdown on the right side of the script.
I have entered it on my own so it will be easy for me to remember the syntax of the script.
Click on save and in Job click on Build Now.
Now Select Build #1.
Open Console to check whether our commands got printed or not.
Summary:
What is a pipeline in Jenkins?
Types of Jenkins pipelines.
Syntax of Jenkins pipeline.
Created one job in Jenkins using the simple pipeline to print hello world.