What is the difference between an agent and a node in a jenkins pipeline?
I've found those definitions:
So both are used for executing pipeline steps. But when to use which one?
The simple answer is, Agent is for declarative pipelines and node is for scripted pipelines.
In declarative pipelines the agent directive is used for specifying which agent/slave the job/task is to be executed on. This directive only allows you to specify where the task is to be executed, which agent, slave, label or docker image.
On the other hand, in scripted pipelines the node step can be used for executing a script/step on a specific agent, label, slave. The node step optionally takes the agent or label name and then a closure with code that is to be executed on that node.
declarative and scripted pipelines (edit based on the comment):