CJE Distributed Builds & Agent Management 2 — Questions and Answers
Question 1: What is the purpose of the 'agent' directive in a Jenkins Declarative Pipeline?
- To define environment variables available throughout the build
- To specify where the entire pipeline or a specific stage should execute (Correct answer)
- To configure credential bindings for the pipeline
- To set the timeout duration for the pipeline or stage
Correct answer: To specify where the entire pipeline or a specific stage should execute
The 'agent' directive specifies the executor environment — such as a node label, Docker container, or Kubernetes pod — where the pipeline or an individual stage will run.
Question 2: What does 'agent none' at the top level of a Declarative Pipeline mean?
- No agents are registered in the Jenkins cluster
- The pipeline will run exclusively on the Jenkins controller
- No global agent is allocated; each stage must define its own agent directive (Correct answer)
- The pipeline is paused until an agent becomes available
Correct answer: No global agent is allocated; each stage must define its own agent directive
'agent none' at the top level means Jenkins will not allocate a global workspace; instead, each stage is responsible for declaring its own 'agent' directive specifying where it should run.
Question 3: What is the Jenkins best practice regarding the number of executors on the controller node?
- Set it to match the number of CPU cores on the controller for maximum efficiency
- Set it to 0 so the controller does not run builds and reserves resources for system management (Correct answer)
- Set it to 1 so the controller can handle lightweight builds only
- Set it to the same value as the busiest agent to maintain consistency
Correct answer: Set it to 0 so the controller does not run builds and reserves resources for system management
Best practice is to set the controller's executor count to 0, preventing it from running builds so its resources remain dedicated to managing jobs, agents, and the system.
Question 4: In a Declarative Pipeline using a Docker agent, what does the 'args' parameter in 'docker { image "..." args "..." }' specify?
- The name of the Docker image to pull from the registry
- Additional flags passed directly to the 'docker run' command when starting the container (Correct answer)
- The registry authentication credentials to use
- The port mappings exposed from the container to the host
Correct answer: Additional flags passed directly to the 'docker run' command when starting the container
The 'args' parameter passes additional command-line flags to 'docker run', allowing customization such as adding volume mounts (-v), environment variables (-e), or privileged mode (--privileged).
Question 5: What is a 'flyweight executor' in Jenkins?
- A dedicated executor type for running Docker container builds
- A lightweight executor on the controller used for administrative tasks like SCM polling and pipeline orchestration steps (Correct answer)
- A minimal executor with restricted file system permissions for security
- An executor optimized specifically for fast-running unit test builds
Correct answer: A lightweight executor on the controller used for administrative tasks like SCM polling and pipeline orchestration steps
Flyweight executors run on the Jenkins controller and handle non-build operations such as SCM polling, pipeline step coordination, and trigger evaluation without consuming regular build executor slots.
Question 6: How can you configure a Declarative Pipeline to run different stages on different agents or node types?
- By creating a separate Jenkinsfile for each stage and chaining them with triggers
- By defining an 'agent' directive at the individual stage level within the pipeline (Correct answer)
- By using only the 'parallel' block to distribute stages across nodes
- By creating separate downstream jobs for each stage and triggering them sequentially
Correct answer: By defining an 'agent' directive at the individual stage level within the pipeline
In a Declarative Pipeline with 'agent none' at the top level, each stage can define its own 'agent' directive, enabling different stages to execute on different nodes, labels, or container images.
Question 7: What does Jenkins Node Monitoring automatically check to determine whether an agent should be taken offline?
- Network packet loss and latency between the agent and external services
- Health metrics such as available disk space, clock difference from controller, and response time (Correct answer)
- CPU utilization and memory consumption against configurable thresholds
- The number of failed builds in the last hour on that agent
Correct answer: Health metrics such as available disk space, clock difference from controller, and response time
Jenkins Node Monitoring performs periodic health checks on agents including available disk space (tmp, swap, workspace), clock skew compared to the controller, and response time, taking the agent offline if thresholds are breached.
What is the purpose of the 'agent' directive in a Jenkins Declarative Pipeline?