Steps To Create Methods In Jenkins Declarative Pipeline
Step 1: Go to the Jenkins dashboard and create a new item.
Step 2 : Now give the item name and select pipeline .
Step 3 : Now write some demo Jenkins declarative pipeline using methods . Here using a method i have printed the different stage names.
pipeline {
agent any
stages {
stage('Stage 1') {
steps {
demoMethod("Stage 1")
echo "Hello Geeks!"
}
}
stage('Stage 2') {
steps {
demoMethod("Stage 2")
}
}
}
}
def demoMethod(stageName) {
echo "This is ${stageName}"
}
Step 4 : Now select Build Now to build the Jenkins pipeline.
Step 5 : Now see the output of Jenkins declarative pipeline in the console output.
How To Create Methods In Jenkins Declarative Pipeline?
Jenkins is an open-source automation tool used to automate the fetch, build, test, and deploy stages of a software application. Here in this guide, we will first discuss what is Jenkins. Then we will discuss what is Jenkins Declarative Pipeline. After this, I will walk you through the detailed steps to create a method in the Jenkins declarative pipeline.