Jenkins Windows Agent on a VPS: Inbound Setup as a Service

Turn a Windows VPS into a Jenkins build agent: create the node, connect agent.jar over WebSocket, and run it as a service that survives reboots.

dns WindowsVPS Team calendar_today schedule5 min read
Jenkins Windows Agent on a VPS: Inbound Setup as a Service
tocOn this page 8 sections
  1. Why an inbound agent suits a VPS
  2. Step 1: Create the node on the controller
  3. Step 2: Prepare the VPS
  4. Step 3: Test the connection by hand
  5. Step 4: Run the agent as a Windows service
  6. Step 5: Target the agent from a pipeline
  7. Keep builds healthy
  8. FAQ

To make a Windows VPS a Jenkins build agent, create a permanent node on the controller with the launch method Launch agent by connecting it to the controller, install a JDK on the VPS, and run agent.jar with the node's secret over WebSocket. The agent then needs only outbound HTTPS. Wrap that command in a Windows service that runs as a dedicated local account, and the agent reconnects on its own after every reboot.

Why an inbound agent suits a VPS

With an inbound agent, the VPS dials out to the controller, so you don't open any inbound port on the VPS. The -webSocket flag carries agent traffic over the same HTTPS port as the Jenkins web UI. This means you don't have to expose the controller's separate inbound TCP port either. SSH launching works on Windows through OpenSSH Server, but the inbound method has fewer moving parts. It also fits the way you already manage the box over RDP and PowerShell.

Step 1: Create the node on the controller

  1. In Jenkins, open Manage Jenkins > Nodes > New Node, enter a name such as win-vps-01, choose Permanent Agent.
  2. Set Remote root directory to a short path: C:\jenkins. Short roots keep you clear of path-length limits in deep workspaces.
  3. Set Labels to something pipelines can target, for example windows dotnet.
  4. Set Number of executors to 1 or 2 to start. Raise it only after you have watched CPU and disk during real builds.
  5. Under Launch method, pick Launch agent by connecting it to the controller and save.

Open the new node's page. It shows the agent command and the secret. Copy the secret; you need it on the VPS.

Step 2: Prepare the VPS

Connect over RDP and open an elevated PowerShell. Create a dedicated account and the agent root folder. Builds should not run as Administrator or LocalSystem.

New-LocalUser -Name jenkins -Password (Read-Host -AsSecureString) -PasswordNeverExpires
New-Item -Path C:\jenkins -ItemType Directory
icacls C:\jenkins /grant "jenkins:(OI)(CI)M"

Next, install a JDK and Git. Use the same Java major version your controller runs, which is listed under Manage Jenkins > System Information as java.version. Adjust the package ID to match that version:

winget install --id EclipseAdoptium.Temurin.21.JDK -e
winget install --id Git.Git -e
git config --system core.longpaths true
New-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem -Name LongPathsEnabled -Value 1 -PropertyType DWord -Force

Then add whatever your builds call: .NET SDK, Visual Studio Build Tools, Node.js, signing tools. If you need a full IDE on the same box for debugging, the Visual Studio remote dev box guide covers that setup.

Step 3: Test the connection by hand

Open a new PowerShell window so the updated PATH is picked up. Download the agent from your controller and store the secret in a file that only the agent account can read:

Invoke-WebRequest https://jenkins.example.com/jnlpJars/agent.jar -OutFile C:\jenkins\agent.jar
Set-Content C:\jenkins\secret.txt '<secret-from-node-page>' -NoNewline
icacls C:\jenkins\secret.txt /inheritance:r /grant "jenkins:R" /grant "Administrators:F"

java -jar C:\jenkins\agent.jar -url https://jenkins.example.com/ -secret @C:\jenkins\secret.txt -name win-vps-01 -webSocket -workDir C:\jenkins

The @ prefix tells the agent to read the secret from the file, so the secret never shows up in process listings. Wait for Connected in the output and check that the node shows as online in Jenkins. Then press Ctrl+C to stop the test.

Step 4: Run the agent as a Windows service

Running the agent from an RDP window ties it to your session. A service keeps it running with no one signed in. NSSM is a simple wrapper for this; the NSSM service guide explains the tool in more depth.

$java = (Get-Command java).Source
nssm install JenkinsAgent $java "-jar C:\jenkins\agent.jar -url https://jenkins.example.com/ -secret @C:\jenkins\secret.txt -name win-vps-01 -webSocket -workDir C:\jenkins"
nssm set JenkinsAgent AppDirectory C:\jenkins
nssm set JenkinsAgent ObjectName .\jenkins "<password>"
nssm set JenkinsAgent AppStdout C:\jenkins\agent-service.log
nssm set JenkinsAgent AppStderr C:\jenkins\agent-service.log
nssm set JenkinsAgent Start SERVICE_DELAYED_AUTO_START
Start-Service JenkinsAgent

The service may fail to start with error 1069. If it does, grant the account the logon right in secpol.msc > Local Policies > User Rights Assignment > Log on as a service. Agent-side logs are written to C:\jenkins\remoting\logs. Reboot the VPS once to confirm that the node comes back online without you.

Step 5: Target the agent from a pipeline

pipeline {
  agent { label 'windows' }
  stages {
    stage('Build') {
      steps {
        bat 'dotnet build -c Release'
        powershell 'Get-ChildItem -Recurse -Filter *.dll | Measure-Object'
      }
    }
  }
}

Use bat for cmd syntax and powershell for Windows PowerShell scripts. On the controller, set the built-in node's executors to 0 so that jobs only ever run on agents.

Keep builds healthy

  • Disk: Workspaces grow quickly. Enable Discard old builds on jobs and call cleanWs() from the Workspace Cleanup plugin at the end of pipelines.
  • Antivirus: Real-time scanning slows compiles noticeably. If you trust your sources, Add-MpPreference -ExclusionPath C:\jenkins helps. Weigh that against the risk of building untrusted pull requests.
  • Updates: Set active hours under Settings > Windows Update so that reboots land outside build windows. The service reconnects afterward.
  • Exposure: RDP is the main attack surface on a build box that holds signing keys. Work through the Windows Server VPS hardening checklist.

For sizing and plan options for CI workloads, see our Windows VPS for development and testing page.

FAQ

Do I need to open a firewall port on the VPS?

No. The inbound agent only makes outbound connections. With -webSocket, it uses the controller's normal HTTPS port, so the only requirement is that the controller is reachable on that port.

Why do UI tests fail when the agent runs as a service?

Services run in session 0, which has no interactive desktop. For tests that drive a GUI, run the agent as a scheduled task at logon for an account that is signed in, rather than as a service.

Can the same VPS host the Jenkins controller?

Yes. Jenkins ships a Windows installer. Keeping the controller on a separate server is still the better design: a runaway build can then fill the disk or max out the CPU without taking the Jenkins UI down with it.

Run this on your own Windows VPS

Get a Windows VPS from WindowsVPS in about 60 seconds, with full Administrator access over RDP, NVMe storage and the Windows license included.

Buy a Windows VPS →

dns

Written by the WindowsVPS Team

We run Windows Server VPS hosting and write these guides from the same setups our customers use: RDP, PowerShell, trading terminals and always-on bots. Questions about a guide? Contact us.

About WindowsVPS Windows VPS guides All articles

Ready to deploy your server?

Windows or Linux VPS — up and running in under 60 seconds.