GitHub-hosted runners can lint and test, but they can’t reach servers in your data centre. A self-hosted runner is a small agent you install inside your network: it connects out to GitHub, picks up jobs, and runs them where your servers are reachable.
How it works
- The runner makes an outbound HTTPS connection to GitHub and polls for jobs – no inbound firewall ports needed.
- Jobs that ask for its labels (
runs-on: [self-hosted, windows, lab]) run on it. - It runs as a service under an account you choose – that account’s rights are what your jobs can do.
Install a runner on Windows
- In the repo (or organisation): Settings → Actions → Runners → New self-hosted runner → Windows.
-
GitHub shows commands with a short-lived registration token. On your runner server (PowerShell as admin):
mkdir C:\actions-runner; cd C:\actions-runner # download and extract the runner zip using the exact commands GitHub shows, then: .\config.cmd --url https://github.com/YOUR-ORG/winops-lab --token <TOKEN> ` --name RUNNER-LAB01 --labels windows,lab --runasservice - When asked for the service account, use a dedicated service account with only the rights the jobs need (not a domain admin).
The runner appears as Idle in GitHub. The service is named actions.runner.* in services.msc.
Use it in a workflow
name: Restart app pool (lab)
on:
workflow_dispatch:
inputs:
server:
description: 'Target server'
required: true
type: choice
options: [WEB-LAB01, WEB-LAB02]
jobs:
restart:
runs-on: [self-hosted, windows, lab]
environment: lab
steps:
- uses: actions/checkout@v4
- name: Recycle app pool
shell: powershell
env:
TARGET: ${{ inputs.server }}
run: |
Invoke-Command -ComputerName $env:TARGET -ScriptBlock {
Import-Module WebAdministration
Restart-WebAppPool -Name DemoAppPool
}
Notes:
- choice inputs prevent free-text typos and injection.
- Pass inputs to scripts through
env:and read$env:TARGET– don’t paste${{ inputs.x }}directly into script text.
Environments and approvals
Settings → Environments → New environment (lab, prod):
- Required reviewers – the job waits until someone approves.
- Deployment branches – only
mainmay deploy toprod. - Environment secrets – production credentials only available to production jobs.
With environment: prod, the workflow pauses and asks the reviewers – the same plan → approve → apply pattern as in Jenkins.
Security – read before you install
- Never attach self-hosted runners to public repositories: anyone could open a pull request that runs code inside your network.
- Use separate runners (and service accounts) for lab and prod, selected by labels and environments.
- Restrict which repos/workflows can use a runner with runner groups (organisation level).
- Keep the runner updated (it auto-updates by default – allow it through your proxy).
- Treat the runner server like any admin jump host: patched, monitored, minimal software.
Troubleshooting
| Problem | Check |
|---|---|
| Job stays “Queued” | Runner offline? Labels in runs-on match exactly? |
| Runner offline | Service running? Outbound HTTPS to GitHub allowed through proxy/firewall? |
| Access denied on target servers | The runner’s service account needs rights there |
| Works for you, fails in the job | The job runs as the service account, with its own profile and modules |
What’s next
Next: Docker basics for Windows admins.
Practise this topic
Test yourself with free questions on this topic – instant answers and explanations.
Start practice questionsGitHub ActionsSelf-hosted RunnerWindowsCI/CDIntermediate