A Scripted Pipeline is a Jenkins pipeline written in Groovy code that gives full control over the flow and logic. It is more flexible but requires programming knowledge.
Click to reveal answer
beginner
What is a Declarative Pipeline in Jenkins?
A Declarative Pipeline is a simpler and more structured way to write Jenkins pipelines using a predefined syntax. It is easier to read and write for beginners.
Click to reveal answer
intermediate
Which Jenkins pipeline style is better for complex logic and custom scripting?
Scripted Pipeline is better for complex logic and custom scripting because it allows full Groovy programming capabilities.
Click to reveal answer
intermediate
Which Jenkins pipeline style enforces a strict structure and is easier to maintain?
Declarative Pipeline enforces a strict structure and is easier to maintain because it uses a clear syntax and predefined blocks.
Click to reveal answer
intermediate
Name one advantage of Declarative Pipelines over Scripted Pipelines.
Declarative Pipelines provide better error handling and built-in features like post actions, making pipelines more robust and easier to manage.
Click to reveal answer
Which Jenkins pipeline style uses Groovy scripting for full control?
AScripted Pipeline
BDeclarative Pipeline
CMultibranch Pipeline
DFreestyle Pipeline
✗ Incorrect
Scripted Pipeline uses Groovy scripting to allow full control over the pipeline logic.
Which pipeline style is recommended for beginners due to its simple syntax?
AScripted Pipeline
BFreestyle Pipeline
CPipeline as Code
DDeclarative Pipeline
✗ Incorrect
Declarative Pipeline has a simple and structured syntax, making it easier for beginners.
Which Jenkins pipeline style enforces a strict structure with predefined blocks?
AScripted Pipeline
BMultibranch Pipeline
CDeclarative Pipeline
DFreestyle Pipeline
✗ Incorrect
Declarative Pipeline enforces a strict structure using predefined blocks like stages and steps.
Which pipeline style allows more flexibility but requires Groovy knowledge?
AScripted Pipeline
BDeclarative Pipeline
CMultibranch Pipeline
DFreestyle Pipeline
✗ Incorrect
Scripted Pipeline allows more flexibility but requires knowledge of Groovy scripting.
Which pipeline style provides built-in error handling and post actions?
AScripted Pipeline
BDeclarative Pipeline
CFreestyle Pipeline
DMultibranch Pipeline
✗ Incorrect
Declarative Pipeline provides built-in error handling and post actions for better pipeline management.
Explain the main differences between Scripted and Declarative Pipelines in Jenkins.
Think about control, syntax, and ease of use.
You got /5 concepts.
When would you choose a Scripted Pipeline over a Declarative Pipeline?
Consider pipeline complexity and programming skills.
You got /4 concepts.
Practice
(1/5)
1. Which statement best describes the main difference between scripted and declarative Jenkins pipelines?
easy
A. Scripted pipelines use Groovy code and are flexible; declarative pipelines have a fixed structure and are easier to read.
B. Declarative pipelines use Groovy code and are flexible; scripted pipelines have a fixed structure and are easier to read.
C. Both scripted and declarative pipelines have the same syntax and flexibility.
D. Scripted pipelines are only for building Java projects; declarative pipelines are for all other projects.
Solution
Step 1: Understand scripted pipeline nature
Scripted pipelines use Groovy code, allowing more flexibility but requiring more coding skill.
Step 2: Understand declarative pipeline nature
Declarative pipelines have a fixed, simpler structure designed for easier writing and reading.
Final Answer:
Scripted pipelines use Groovy code and are flexible; declarative pipelines have a fixed structure and are easier to read. -> Option A
Each stage must contain a steps block that holds the commands to run.
Step 2: Check the snippet
The 'Build' stage directly contains echo without wrapping it inside steps {}, which is invalid.
Final Answer:
Missing 'steps' block inside the 'Build' stage -> Option C
Quick Check:
Declarative stages require steps block [OK]
Hint: Declarative stages always need a 'steps' block [OK]
Common Mistakes:
Omitting the 'steps' block inside stages
Confusing scripted and declarative syntax
Thinking 'echo' must be replaced by 'sh'
5. You want to create a Jenkins pipeline that runs a complex Groovy script for dynamic branching but also wants to keep some stages simple and readable. Which approach is best?
hard
A. Use a fully scripted pipeline for all stages to keep consistency.
B. Use a declarative pipeline with a scripted block inside for complex parts.
C. Use only declarative pipeline and avoid any Groovy scripting.
D. Write two separate pipelines and run them manually.