Day 24–101 Days of DevOps -Jenkins Pipeline(Scripted vs Declarative)

  • You can check it in the source control.
  • Perform code review.
  • Become a single source of truth, which can be viewed and edited by multiple members of the project.
  • Declarative Pipeline: Declarative pipeline is the new addition to Jenkins which supports pipeline as code. It makes pipeline code easier to write and read.
  • Scripted Pipeline: Scripted Pipeline is the traditional way of writing the code and it offers a tremendous amount of flexibility and extensibility to Jenkins users.
  • The declarative pipeline started with a pipeline block.
  • Agent directive is a must for declarative pipeline and it allocates executor and workspace to the pipeline. It also makes sure the source repository is checked out and made available for steps in the subsequent stages.
  • Stages and steps directive instructs Jenkins what to execute and in which stage it needs to be executed.
# Official Declarative Pipeline example
pipeline {
agent any
stages {
stage('Hello') {
steps {
echo 'Hello World'
}
}
}
}
  • The declarative pipeline started with a node block.
# Official Scripted Pipeline example
node {
def mvnHome
stage('Preparation') { // for display purposes
// Get some code from a GitHub repository
git '
https://github.com/jglick/simple-maven-project-with-tests.git'
// Get the Maven tool.
// ** NOTE: This 'M3' Maven tool must be configured
// ** in the global configuration.
mvnHome = tool 'M3'
}
stage('Build') {
// Run the maven build
withEnv(["MVN_HOME=$mvnHome"]) {
if (isUnix()) {
sh '"$MVN_HOME/bin/mvn" -Dmaven.test.failure.ignore clean package'
} else {
bat(/"%MVN_HOME%\bin\mvn" -Dmaven.test.failure.ignore clean package/)
}
}
}
stage('Results') {
junit '**/target/surefire-reports/TEST-*.xml'
archiveArtifacts 'target/*.jar'
}
}

--

--

--

AWS Community Builder, Ex-Redhat, Author, Blogger, YouTuber, RHCA, RHCDS, RHCE, Docker Certified,4XAWS, CCNA, MCP, Certified Jenkins, Terraform Certified, 1XGCP

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

From MATLAB to React & Go — The North Sprint Review with Roxana C.

OpenSSL At 1st Sight

Gopher Guides Welcomes Tim Raymond — New Partner

Implementing a Role Based Access Control Service with FastAPI and Postgres

The 10 Step Path to IT Failure

How to load assets asynchronously with Phaser 3

How To Be An Aggressive Listener

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Prashant Lakhera

Prashant Lakhera

AWS Community Builder, Ex-Redhat, Author, Blogger, YouTuber, RHCA, RHCDS, RHCE, Docker Certified,4XAWS, CCNA, MCP, Certified Jenkins, Terraform Certified, 1XGCP

More from Medium

Basics of Networking | Networking in Docker #2

I Can See Clearly Now (with Jenkins): A journey through implementing DevOps. — Shaik Wahab

Ansible And Jinja2

Keep on learning with DevOps!