The easiest method is using WinSW (Windows Service Wrapper) to connect a Windows agent to Jenkins, you can follow these steps:
Download the WinSW executable from the official website and save it in a directory on your Windows machine.
Create a new directory for the Jenkins agent on the Windows machine. This directory will be used as the "Remote FS root" when configuring the agent in Jenkins.
Create a new XML file in the directory where you saved the WinSW executable, and name it "jenkins-slave.xml". You can use any text editor to create this file.
Open the "jenkins-slave.xml" file and add the following content:
<service>
<id>jenkins-slave</id>
<name>Jenkins Slave</name>
<description>This service runs a Jenkins agent on this machine.</description>
<executable>C:\Program Files\Java\jdk1.8.0_221\bin\java.exe</executable>
<arguments>-jar C:\Path\To\slave.jar -jnlpUrl http://jenkins-server:port/computer/slave-name/slave-agent.jnlp -secret abcdef1234567890 -workDir C:\Path\To\Agent\Directory</arguments>
<logmode>rotate</logmode>
</service>
Replace "jenkins-server" and "port" with the hostname and port number of your Jenkins server, "slave-name" with the name you want to give to your Windows agent in Jenkins, "abcdef1234567890" with the secret key provided by Jenkins, and "C:\Path\To\Agent\Directory" with the path to the directory you created for the Jenkins agent.
Save the "jenkins-slave.xml" file.
Open a command prompt as an administrator and navigate to the directory where you saved the WinSW executable.
Run the following command to install the Jenkins agent as a Windows service:
winsw.exe install
Run the following command to start the Jenkins agent service:
net start "Jenkins Slave"
In the Jenkins web interface, go to "Manage Jenkins" > "Manage Nodes and Clouds" > "New Node" to create a new node for the Windows agent.
Enter a name for the node and select "Permanent Agent". Click "OK".
On the next screen, enter the following information:
Remote root directory: The directory on the Windows machine where the agent should run.
Labels: Any labels that you want to assign to the node.
Launch method: "Launch agent via Java Web Start".
Availability: "Keep this agent online as much as possible".
Click "Save" to create the node.
In the node configuration screen, click "Launch" to launch the Windows agent. You should see the agent connect to the Jenkins master and show up as online.