Jenkins Jenkins Pipeline 2 — Questions and Answers
Question 1: What is a Jenkinsfile?
- A binary file that stores compiled pipeline definitions
- A text file checked into source control that defines the pipeline as code (Correct answer)
- A Jenkins configuration backup file
- A plugin descriptor file
Correct answer: A text file checked into source control that defines the pipeline as code
A Jenkinsfile is a text file stored in source control that defines the pipeline using either Declarative or Scripted syntax.
Question 2: How do you define a parallel execution of stages in a Declarative Pipeline?
- Use concurrent {} block
- Use parallel {} inside a stage's steps
- Use parallel {} inside a stage block (Correct answer)
- Use concurrent: true on each stage
Correct answer: Use parallel {} inside a stage block
In Declarative Pipeline, parallel stages are defined using the `parallel {}` block inside a `stage {}` block.
Question 3: What does the `stash` step do in a Jenkins Pipeline?
- Saves files in source control
- Temporarily saves files for use in a later stage or node (Correct answer)
- Archives artifacts for download
- Compresses log files
Correct answer: Temporarily saves files for use in a later stage or node
The `stash` step saves a set of files from the workspace for retrieval with `unstash` in another stage or node.
Question 4: Which Declarative Pipeline directive is used to set environment variables for use in pipeline steps?
- params {}
- variables {}
- environment {} (Correct answer)
- globals {}
Correct answer: environment {}
The `environment {}` directive in Declarative Pipeline defines key-value pairs available as environment variables throughout the pipeline.
Question 5: What is the purpose of `input` step in a Jenkins Pipeline?
- To read a file from the workspace
- To pause the pipeline and wait for human approval before continuing (Correct answer)
- To accept parameters at build time
- To inject credentials into the environment
Correct answer: To pause the pipeline and wait for human approval before continuing
The `input` step pauses pipeline execution and displays a prompt requiring a human to approve or abort before the pipeline proceeds.
Question 6: What is a Shared Library in Jenkins?
- A plugin that shares build artifacts between jobs
- A reusable collection of Groovy code centrally stored and shared across multiple pipelines (Correct answer)
- A shared workspace mounted across agents
- A library of pre-built Dockerfiles
Correct answer: A reusable collection of Groovy code centrally stored and shared across multiple pipelines
Jenkins Shared Libraries allow teams to define common pipeline logic in a centralized Git repository and reuse it across multiple pipelines.
What is a Jenkinsfile?