Jenkins Jenkins Pipeline 1 — Questions and Answers
Question 1: What are the two types of Jenkins Pipeline syntax?
- Scripted and Structured
- Declarative and Scripted (Correct answer)
- Groovy and JSON
- YAML and Groovy
Correct answer: Declarative and Scripted
Jenkins supports Declarative Pipeline (simpler, opinionated) and Scripted Pipeline (full Groovy DSL flexibility).
Question 2: In a Declarative Pipeline, what block wraps the entire pipeline definition?
- pipeline {} (Correct answer)
- stage {}
- node {}
- script {}
Correct answer: pipeline {}
All Declarative Pipeline code must be enclosed within a top-level `pipeline {}` block.
Question 3: What does the `agent any` directive mean in a Declarative Pipeline?
- The pipeline has no agent
- The pipeline runs on any available agent (Correct answer)
- The pipeline runs on all agents simultaneously
- The pipeline uses a Docker agent
Correct answer: The pipeline runs on any available agent
`agent any` instructs Jenkins to allocate the pipeline on any available executor, controller or agent.
Question 4: What is the purpose of the `stages` block in a Declarative Pipeline?
- To define environment variables
- To contain one or more stage blocks that represent pipeline phases (Correct answer)
- To specify build triggers
- To configure post-build actions
Correct answer: To contain one or more stage blocks that represent pipeline phases
The `stages` block is a required container that holds all individual `stage` blocks representing phases of the pipeline.
Question 5: Which Declarative Pipeline section is used to define actions to run after the pipeline completes regardless of result?
- cleanup {}
- post {} (Correct answer)
- finally {}
- after {}
Correct answer: post {}
The `post {}` section in Declarative Pipeline supports conditions like always, success, failure, and cleanup.
Question 6: What does `sh` step do in a Jenkins Pipeline?
- Runs a shell command on the agent (Correct answer)
- Shares files between stages
- Sends a Slack notification
- Starts a new agent shell
Correct answer: Runs a shell command on the agent
The `sh` step executes a shell command (bash/sh) on the agent where the pipeline is running.
What are the two types of Jenkins Pipeline syntax?