jenkins pipeline: agent vs node?

老子叫甜甜 提交于 2019-11-26 11:55:11

问题


What is the difference between an agent and a node in a jenkins pipeline?

I\'ve found those definitions:

  • node: Most work a Pipeline performs is done in the context of one or more declared node steps.
  • agent: The agent directive specifies where the entire Pipeline, or a specific stage, will execute in the Jenkins environment depending on where the agent directive is placed.

So both are used for executing pipeline steps. But when to use which one?


回答1:


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):

  • declarative pipelines is a new extension of the pipeline DSL (it is basically a pipeline script with only one step, a pipeline step with arguments (called directives), these directives should follow a specific syntax. The point of this new format is that it is more strict and therefore should be easier for those new to pipelines, allow for graphical editing and much more.
  • scripted pipelines is the fallback for advanced requirements.


来源:https://stackoverflow.com/questions/42050626/jenkins-pipeline-agent-vs-node

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!