0
0
Jenkinsdevops~30 mins

Scripted vs declarative comparison in Jenkins - Hands-On Comparison

Choose your learning style9 modes available
Scripted vs Declarative Jenkins Pipeline Comparison
📖 Scenario: You are working as a DevOps engineer. Your team wants to understand the difference between scripted and declarative Jenkins pipelines. You will create two simple Jenkins pipelines: one scripted and one declarative, both doing the same task of printing a message.
🎯 Goal: Build two Jenkins pipelines: a scripted pipeline and a declarative pipeline. Both pipelines will print the message "Hello from Jenkins Pipeline!" to the console. This will help you see how the two styles differ in syntax and structure.
📋 What You'll Learn
Create a scripted Jenkins pipeline that prints "Hello from Jenkins Pipeline!"
Create a declarative Jenkins pipeline that prints "Hello from Jenkins Pipeline!"
Use the exact variable and stage names as instructed
Print the output in the final step
💡 Why This Matters
🌍 Real World
Jenkins pipelines automate software build, test, and deployment tasks. Understanding scripted and declarative pipelines helps teams choose the best style for their projects.
💼 Career
DevOps engineers often write Jenkins pipelines. Knowing both scripted and declarative styles improves flexibility and collaboration in CI/CD workflows.
Progress0 / 4 steps
1
Create a scripted Jenkins pipeline
Write a scripted Jenkins pipeline using node block that prints the message "Hello from Jenkins Pipeline!" using echo.
Jenkins
Need a hint?

Use node { ... } to define the scripted pipeline and echo to print the message.

2
Add a declarative Jenkins pipeline
Add a declarative Jenkins pipeline using pipeline and stages that has one stage named PrintMessage which prints "Hello from Jenkins Pipeline!" using echo.
Jenkins
Need a hint?

Use pipeline { agent any stages { stage('PrintMessage') { steps { echo ... } } } } structure for declarative pipeline.

3
Compare the two pipelines in one script
Combine both the scripted pipeline and the declarative pipeline in one Jenkinsfile script. Keep the scripted pipeline first, then the declarative pipeline. Use exact code from previous steps.
Jenkins
Need a hint?

Just place the scripted pipeline code first, then the declarative pipeline code below it.

4
Print a summary message
Add a final echo statement outside both pipelines that prints "Scripted and Declarative pipelines completed."
Jenkins
Need a hint?

Use echo "Scripted and Declarative pipelines completed." outside the pipeline blocks.