Introduction
When running automated tasks in Jenkins, you need to tell it where to run those tasks. The agent directive tells Jenkins which machine or environment to use for running your pipeline steps.
When you want your Jenkins pipeline to run on a specific machine or container.
When you need to run different parts of your pipeline on different environments.
When you want to use a Docker container as the environment for your build.
When you want to run your pipeline on the Jenkins master node itself.
When you want to avoid running your pipeline on any node and just run it locally.