I am trying to use jenkins. But when I reading the Declarative Pipeline Syntax, I confused by the agent
term
The agent section specifies where the entire Pipeline, or a specific stage, will execute in the Jenkins environment depending on where the agent section is placed. The section must be defined at the top-level inside the pipeline block, but stage-level usage is optional.
It can be /var/jenkins/agent/e2e-pipeline , but it varies according to your environment. It is the working directory of the agent.
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.
It allows us to use different environments for each build project balancing the workload among multiple agents running jobs in parallel. The Jenkins controller is the original node in the Jenkins installation.
I can feel you :-D. Here are the answers:
The agent section specifies where the entire Pipeline, or a specific stage, will execute in the Jenkins environment depending on where the agent section is placed. The section must be defined at the top-level inside the pipeline block, but stage-level usage is optional. - Content copied from the agent section
NO, this has nothing to do with the pipeline runtime folder path.
You can for example Create an agent/node by the following tutorial: How to Setup Jenkins Agent/Slave Using Password and ssh Keys. - But there are many other ways to create an agent e.g. using a Docker-Container (...).
You can Set a label under the Configuration of the Node. You can use a label in your pipeline like:
pipeline {
agent { label 'labelName' }
(...)
}
While @adbo covered questions asked, Jenkins glossary describes agent really well:
typically a machine, or container, which connects to a Jenkins controller and executes tasks when directed by the controller.
You can choose to run entire pipeline on any available agent (agent any
at the top of the pipeline) or run a specific stage on the agent of choice e.g. run build stage in a specific environ by overriding agent in that stage:
agent { docker { image 'my image' } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With