What is a Jenkins agent? And creating a Jenkins SSH Agent via the GUI
A Jenkins agent is an executable, residing on a node, that is tasked by the controller to run a job. [3] An agent is usually a machine, whether that is a virtual machine, a laptop, a desktop, a server in a data center, or even a rasberry pi, it could even be a container. [5]
Jenkins agents run on a variety of different environments such as physical machines, virtual machines, Kubernetes clusters, and Docker images. [2] An agent can represent a machine on the cloud as well, such as an ec2 instance on AWS.
Agents are controlled by a Jenkins Controller. It is always better to do all your work with an agent and not to do any builds directly on your controller.
The Jenkins controller is the original node in the Jenkins installation. [1] The controller manages the connections and the tooling for agents. [5]
Node: A machine which is part of the Jenkins environment and capable of executing Pipelines or Projects. Both the Controller and Agents are considered to be Nodes. [2]
A core component of Jenkins is the job. Jobs are instances of build automation that run a defined set of tasks. [3]
Managing the different Jenkins agents is the job of the agent controller, also known as the master node. In a single Jenkins node configuration, the controller, can also act as both a Jenkin agent and run build jobs. As environments become more complex, this configuration becomes limiting. [3]
How to Create an Agent
First we will create an ssh credential for our agent to use.
Open a Powershell terminal


Windows 10 has had a built-in OpenSSH client since the April 2018 update. Windows 11 also comes with this feature built-in.
Type in the command “ssh-keygen”

It will prompt you to enter a filename/filepath.
By default it will into the user folder (usually this is on your C:\ drive, at something like: C:\Users\ashle/.ssh/id_rsa. You can see my example in the image above)
I just hit enter and it creates this directory.

Next enter a passphrase or hit the Enter key for no passphrase.

Then it will tell you the file where it put your public key as seen in the screencap above.
That’s it your keys are created, saved, and ready for use. You will see you have two files in your “.ssh” folder: “id_rsa” with no file extension and “id_rsa.pub.” The latter is the key you upload to servers to authenticate while the former is the private key that you don’t share with others. [7]
Go to the Jenkins Home Dashboard and Select “Manage Jenkins”

Scroll down to the security section and select “Manage Credentials”









Go back to the main Dashboard and select “Manage Jenkins”

Under System Configuration select “Manage Nodes and Clouds”

Alternatively you can select “Build Executor Status” on the Home page to get here as well.

Select “New Node”

Give your new node a name, I called mine “windows”. I am creating an agent (which is a node) that will basically be my agent for building on Windows.

Enable the “Permanent Agent” radio button, since this is a node that will stick around to be summoned whenever needed.

Click the OK button

Fill in a description.

Leave number of executors at 1 for most cases. In general number of executors will be the number of CPUs you have available for your machine. Since most VMS, laptops, desktop machines and so on have only one CPU, this is the most common value. In the cloud it is more common to have access to a VM with multiple CPUs but this is also not the common case.

Set your “Remote root directory” to “C:\Jenkins\nodes”

Set your labels. I just made 1 label, “windows”. You can add as many as you like here separated by spaces.

Set your “Launch Method” to “Launch agents via SSH”

Set “Host” to localhost or your IP address followed by port number.

Click the “Advanced” Button

Check your port number is 22, the default port for ssh.
In case of Broken: How to Check My Ports?
You can use netstat (in an administrator console on Windows)
netstat -tlpnsince I can’t pipe into a grep on Windows I like to output to a text file like this:
netstat -tlpn > C:\Users\ashle\Desktop\ports.txtand then just open that file in a text editor and search for the port I am interested in. In our case we would want to make sure that port 22 is open, usually this is indicated by the word “LISTENING” as in, the port is open and is “listening” for new commo. Something else could be hogging your port 22, so it doesn’t hurt to check this if stuff goes awry.

Set credentials to “jenkins (ssh key for the windows agent)

Nothing else needs to be changed, so you can click the “Save” button.

Your agent will be registered, but offline, click on it.

You will see a message that your agent is being launched, or else you will see a Launch button for launching your agent.


changed away from ssh mode to “connect to master node” mode.
Here is my output after running:
java -jar agent.jar -jnlpUrl http://localhost:8080/computer/windows/jenkins-agent.jnlp -workDir "C:\Jenkins\nodes"output:
C:\Users\ashle\Downloads>
Apr 08, 2022 7:15:46 PM org.jenkinsci.remoting.engine.WorkDirManager initializeWorkDir
INFO: Using C:\Jenkins\nodes\remoting as a remoting work directory
Apr 08, 2022 7:15:46 PM org.jenkinsci.remoting.engine.WorkDirManager setupLogging
INFO: Both error and output logs will be printed to C:\Jenkins\nodes\remoting
WARNING: A terminally deprecated method in java.lang.System has been called
WARNING: System::setSecurityManager has been called by hudson.remoting.jnlp.Main (file:/C:/Users/ashle/Downloads/agent.jar)
WARNING: Please consider reporting this to the maintainers of hudson.remoting.jnlp.Main
WARNING: System::setSecurityManager will be removed in a future release
Apr 08, 2022 7:15:46 PM hudson.remoting.jnlp.Main createEngine
INFO: Setting up agent: windows
Apr 08, 2022 7:15:46 PM hudson.remoting.jnlp.Main$CuiListener <init>
INFO: Jenkins agent is running in headless mode.
Apr 08, 2022 7:15:46 PM hudson.remoting.Engine startEngine
INFO: Using Remoting version: 4.7
Apr 08, 2022 7:15:46 PM org.jenkinsci.remoting.engine.WorkDirManager initializeWorkDir
INFO: Using C:\Jenkins\nodes\remoting as a remoting work directory
Apr 08, 2022 7:15:47 PM hudson.remoting.jnlp.Main$CuiListener status
INFO: Locating server among [http://localhost:8080/]
Apr 08, 2022 7:15:47 PM org.jenkinsci.remoting.engine.JnlpAgentEndpointResolver resolve
INFO: Remoting server accepts the following protocols: [JNLP4-connect, Ping]
Apr 08, 2022 7:15:47 PM hudson.remoting.jnlp.Main$CuiListener status
INFO: Agent discovery successful
Agent address: localhost
Agent port: 22
Identity: c1:07:b2:df:96:2f:d7:f3:d9:22:a1:f5:9c:03:f2:0d
Apr 08, 2022 7:15:47 PM hudson.remoting.jnlp.Main$CuiListener status
INFO: Handshaking
Apr 08, 2022 7:15:47 PM hudson.remoting.jnlp.Main$CuiListener status
INFO: Connecting to localhost:22
Apr 08, 2022 7:15:47 PM hudson.remoting.jnlp.Main$CuiListener status
INFO: Trying protocol: JNLP4-connect
Apr 08, 2022 7:15:47 PM hudson.remoting.jnlp.Main$CuiListener status
INFO: Remote identity confirmed: c1:07:b2:df:96:2f:d7:f3:d9:22:a1:f5:9c:03:f2:0d
Apr 08, 2022 7:15:47 PM hudson.remoting.jnlp.Main$CuiListener status
INFO: ConnectedPossible Error Messages
Your agent will show an error like this:

Click the “Go to security screen and change it” link.
Find the section labelled “Agents”

And change the Radio button from “Disable” to “Random”

Click the “Save” button at the bottom.

References
[1] Using Jenkins Agents. https://www.jenkins.io/doc/book/using/using-agents/#:~:text=The%20Jenkins%20controller%20is%20the,either%20local%20or%20cloud%20computers.
[2] Node. Jenkins Glossary. https://www.jenkins.io/doc/book/glossary/#:~:text=synonymous%20with%20Controller.-,Node,a%20piece%20of%20software%2C%20etc.
[3] How to Set Up a New Jenkins Build Agent. https://adamtheautomator.com/jenkins-agent/#Prerequisites
[5] Cloud Bees. Video. What is a Jenkins Agent. https://www.youtube.com/watch?v=4KghHJEz5no
[6] Cloud Bees. Video. How to Create an Agent Node in Jenkins. https://www.youtube.com/watch?v=99DddJiH7lM
[7] How to Generate SSH keys in Windows 10 and Windows 11. https://www.howtogeek.com/762863/how-to-generate-ssh-keys-in-windows-10-and-windows-11/
[8]Jenkins Pipeline Syntax. Agent. https://www.jenkins.io/doc/book/pipeline/syntax/#agent
