0
0
Jenkinsdevops~5 mins

Agent directive in Jenkins - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the agent directive in a Jenkins pipeline?
The agent directive tells Jenkins where to run the pipeline or a specific stage. It can specify a node, a label, or run on any available agent.
Click to reveal answer
beginner
How do you specify that a Jenkins pipeline should run on any available agent?
Use agent any in the pipeline script to tell Jenkins to run the pipeline on any available agent.
Click to reveal answer
intermediate
What does agent none mean in a Jenkins pipeline?
agent none means the pipeline itself does not run on any agent by default. You must specify agents for individual stages if needed.
Click to reveal answer
beginner
How can you specify a specific label for the agent in Jenkins pipeline?
Use agent { label 'label-name' } to run the pipeline or stage on an agent with that label.
Click to reveal answer
intermediate
Can the agent directive be used inside individual stages in Jenkins pipelines?
Yes, you can specify agent inside stages to run that stage on a different agent than the rest of the pipeline.
Click to reveal answer
What does agent any do in a Jenkins pipeline?
ARuns the pipeline without any agent
BRuns the pipeline on the master node only
CRuns the pipeline on any available agent
DRuns the pipeline on a specific label
Which agent directive means no default agent is assigned to the pipeline?
Aagent any
Bagent docker
Cagent label 'linux'
Dagent none
How do you specify an agent with a label in Jenkins pipeline?
Aagent { label 'my-label' }
Bagent any
Cagent none
Dagent docker
Can you use different agents for different stages in a Jenkins pipeline?
ANo, the agent is global for the whole pipeline
BYes, by specifying <code>agent</code> inside each stage
COnly if you use <code>agent none</code>
DOnly if you use scripted pipelines
What happens if you omit the agent directive in a declarative Jenkins pipeline?
APipeline fails to run
BPipeline runs on any available agent by default
CPipeline runs on the master node
DPipeline runs without an agent
Explain the role of the agent directive in Jenkins pipelines and how it affects where your code runs.
Think about how Jenkins knows where to run your pipeline or stages.
You got /4 concepts.
    Describe how you can run different stages of a Jenkins pipeline on different agents using the agent directive.
    Consider a pipeline that needs different environments for build and test.
    You got /3 concepts.