Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the agent mean in jenkins?

Tags:

jenkins

I am trying to use jenkins. But when I reading the Declarative Pipeline Syntax, I confused by the agent term

  • https://jenkins.io/doc/book/pipeline/syntax/#scripted-pipeline
  1. What does the agent stand for?
  2. Is that mean I can set the pipeline runtime folder path?
  3. How to create an agent?
  4. How set a label for agent?
like image 452
Rhysol Avatar asked Dec 05 '17 10:12

Rhysol


People also ask

What does agent do in Jenkins pipeline?

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.

Where is agent in Jenkins?

It can be /var/jenkins/agent/e2e-pipeline , but it varies according to your environment. It is the working directory of the agent.

What is the difference between node and agent in Jenkins?

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.

Why do we need Jenkins agent?

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.


2 Answers

I can feel you :-D. Here are the answers:

  1. 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

  2. NO, this has nothing to do with the pipeline runtime folder path.

  3. 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 (...).

  4. You can Set a label under the Configuration of the Node. You can use a label in your pipeline like:

     pipeline {
     agent { label 'labelName' }
     (...)
     }
    
like image 148
adbo Avatar answered Sep 30 '22 20:09

adbo


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' } }

like image 20
Amit Avatar answered Sep 30 '22 19:09

Amit