Operations 8 min read

How to Add Agent Nodes to a Jenkins Server Using Java Web, VM, Docker, Kubernetes, and SSH

This guide explains how to configure Jenkins agent nodes through various methods—including Java Web Start, VM execution, Docker containers, Kubernetes deployments, and SSH—providing step‑by‑step instructions, required code snippets, and tips for successful integration into a CI/CD pipeline.

DevOps Cloud Academy
DevOps Cloud Academy
DevOps Cloud Academy
How to Add Agent Nodes to a Jenkins Server Using Java Web, VM, Docker, Kubernetes, and SSH

Jenkins uses a distributed architecture consisting of a server (master) and one or more agent nodes; agents execute build tasks while the server handles scheduling, and agents can be static (fixed VM or container) or dynamic (created on demand).

1.1 Java Web Start (Launch agent by connecting it to the master) – In this method the agent runs a JNLP client that initiates a TCP connection to the Jenkins server, so the server does not need to reach the agent. After enabling the appropriate security settings, you can select the "Launch agent by connecting it to the master" option in the node configuration.

To add such an agent, go to Jenkins → Manage Nodes → New Node , choose the Java Web Start launch method, and configure the node name and other details.

1.1.1 VM method

Download agent.jar and the secret from the agent page, then run the following commands on a Linux host:

wget http://192.168.1.200:30080/jnlpJars/agent.jar</code>
<code>java -jar agent.jar -jnlpUrl http://192.168.1.200:8080/computer/test01/slave-agent.jnlp -secret d5bd27fc1dfa4c5e886b95fc98538f4a7399c5d239783f89e4502a6e56f8a512 -workDir "/var/lib/jenkins"

The connection log should show messages such as "INFO: Agent discovery successful" and "INFO: Connected".

To keep the agent running in the background, use:

nohup java -jar agent.jar -jnlpUrl http://192.168.1.200:8080/computer/test01/slave-agent.jnlp -secret d5bd27fc1dfa4c5e886b95fc98538f4a7399c5d239783f89e4502a6e56f8a512 -workDir "/var/lib/jenkins" &

1.1.2 Docker method

Pull the inbound‑agent image and run it with the appropriate URL, secret, and work directory:

docker pull jenkins/inbound-agent:alpine</code>
<code>docker run --init jenkins/inbound-agent:alpine -url http://192.168.1.200:30080 -workDir=/home/jenkins/agent d5bd27fc1dfa4c5e886b95fc98538f4a7399c5d239783f89e4502a6e56f8a512 test01

1.1.3 Kubernetes method

Create a deployment YAML that defines the agent container, resources, and environment variables, then apply it to the cluster:

kind: Deployment</code>
<code>apiVersion: apps/v1</code>
<code>metadata:</code>
<code>  labels:</code>
<code>    k8s-app: jenkinsagent-test01</code>
<code>  name: jenkinsagent-test01</code>
<code>  namespace: devops</code>
<code>spec:</code>
<code>  replicas: 1</code>
<code>  selector:</code>
<code>    matchLabels:</code>
<code>      k8s-app: jenkinsagent-test01</code>
<code>  template:</code>
<code>    metadata:</code>
<code>      labels:</code>
<code>        k8s-app: jenkinsagent-test01</code>
<code>    spec:</code>
<code>      containers:</code>
<code>        - name: jenkinsagent-test01</code>
<code>          image: jenkins/inbound-agent:alpine</code>
<code>          env:</code>
<code>            - name: JENKINS_URL</code>
<code>              value: http://192.168.1.200:30080</code>
<code>            - name: JENKINS_SECRET</code>
<code>              value: d5bd27fc1dfa4c5e886b95fc98538f4a7399c5d239783f89e4502a6e56f8a512</code>
<code>            - name: JENKINS_AGENT_NAME</code>
<code>              value: test01

Deploy with kubectl create -f jenkins.yaml and verify the pod status using kubectl get pod -n devops and kubectl logs -f <pod-name> -n devops.

1.2 Launch agents via SSH

Create a credential that stores the SSH authentication details, then add a new node in Jenkins, specifying the host, SSH port, and the credential you just created.

After saving, the SSH‑based agent will connect automatically.

1.3 Create a test pipeline

Define a simple Jenkinsfile for a pipeline project:

pipeline {</code>
<code>    agent {</code>
<code>        node { label "build"}</code>
<code>    }</code>
<code>    stages {</code>
<code>        stage('Hello') {</code>
<code>            steps {</code>
<code>                echo 'Hello World'</code>
<code>            }</code>
<code>        }</code>
<code>    }</code>
<code>}

With the agent configured, you can now run builds and explore additional Jenkins features.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

ci/cdDevOpsagentJenkinsSSH
DevOps Cloud Academy
Written by

DevOps Cloud Academy

Exploring industry DevOps practices and technical expertise.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.