Learn › Jenkins

Jenkins for Windows Admins: Install Jenkins and Run Your First Pipeline from Git

Jenkins basics: install it on Ubuntu, connect a private GitHub repo, and write a first Jenkinsfile that checks your PowerShell scripts. Step by step.

Beginner 15 min read Part 2 of 3
By Gopinath Karthikeyan · 29 Nov 2026

In Part 1 you put your scripts in a Git repo called winops-lab. Now we’ll give them a robot.

Jenkins is a server that runs jobs for you – on a schedule, on a button click, or every time someone pushes a change to Git. Instead of “log in, open PowerShell, run the script, copy the output into an email”, you get a web page with a Build button, a full log of every run and a record of who ran what.

By the end of this guide Jenkins will pull your winops-lab repo and check every PowerShell script for syntax errors – automatically, before a broken script can ever reach a server.

What you need: the winops-lab repo from Part 1, and an Ubuntu 22.04, 24.04 or 26.04 machine with 2 GB+ RAM: a VM (Hyper-V, VirtualBox, VMware) or WSL2 on your laptop. About 60 minutes.

How Jenkins thinks – 6 words

Word What it means
Controller The Jenkins server itself: web page, settings, job history
Agent A machine that runs the actual work. In this lab the controller does it; in real setups you add separate agents
Job A task Jenkins can run. We’ll use the Pipeline type
Jenkinsfile A text file in your Git repo that describes the pipeline’s steps. Your job definition lives with your scripts, versioned
Build One run of a job, with its own number, log and result (green = passed, red = failed)
Credentials Passwords, tokens and keys stored safely inside Jenkins, so they never appear in scripts or logs

The flow you’re building:

You push to GitHub  →  Jenkins pulls winops-lab  →  runs jenkins/Jenkinsfile  →  green or red build + log

Why Ubuntu and not Windows?

Jenkins runs on Windows too, but in Part 3 we add Ansible, which only runs on Linux. Putting Jenkins on Ubuntu now means one lab machine for the whole path. You’ll still manage Windows servers from it – that’s the point of Part 3.

New to Linux? Every command below is copy-paste. sudo means “run as administrator”.

Step 1: install Java

Jenkins is a Java application. Current Jenkins LTS needs Java 21. Install Java before Jenkins:

sudo apt update
sudo apt install -y fontconfig openjdk-21-jre
java -version

You should see openjdk version "21....

Step 2: install Jenkins (LTS)

Add the official Jenkins repository and install the LTS (long-term support) version – the stable one you want for anything real:

sudo wget -O /etc/apt/keyrings/jenkins-keyring.asc \
  https://pkg.jenkins.io/debian-stable/jenkins.io-2026.key
echo "deb [signed-by=/etc/apt/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian-stable binary/" \
  | sudo tee /etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt update
sudo apt install -y jenkins

Check that it’s running:

sudo systemctl status jenkins --no-pager

Look for active (running). Jenkins listens on port 8080.

On WSL2, systemctl needs systemd. Recent Ubuntu on WSL has it on by default; if you get “System has not been booted with systemd”, add [boot] and systemd=true to /etc/wsl.conf, then run wsl --shutdown in Windows and reopen Ubuntu.

Step 3: first-time setup

  1. Open http://localhost:8080 in your browser (or http://<VM-IP>:8080 for a VM – find the IP with ip a).
  2. Jenkins asks for an unlock password. Print it:

    sudo cat /var/lib/jenkins/secrets/initialAdminPassword
    
  3. Paste it, choose Install suggested plugins and wait a few minutes.
  4. Create your admin user. Use a real password – this account can run anything on the machine.
  5. Keep the Jenkins URL it suggests and click Start using Jenkins.

Step 4: install PowerShell on the Jenkins machine

Our pipeline checks PowerShell scripts, so the machine running the build needs PowerShell 7. These are Microsoft’s commands for Ubuntu:

sudo apt-get install -y wget apt-transport-https software-properties-common
source /etc/os-release
wget -q https://packages.microsoft.com/config/ubuntu/$VERSION_ID/packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb
sudo apt-get update
sudo apt-get install -y powershell
pwsh -Version

Yes – PowerShell runs on Linux. Windows-only cmdlets (like Get-CimInstance Win32_*) won’t, but parsing and testing scripts works fine.

Step 5: add the syntax-check script to your repo

On your Windows laptop, in C:\Lab\winops-lab, create scripts\Test-ScriptSyntax.ps1:

# Checks every .ps1 file under a folder for syntax errors. Exit code 1 = at least one broken script.
param([string]$Path = 'scripts')

$failed = 0
Get-ChildItem -Path $Path -Recurse -Filter *.ps1 | ForEach-Object {
    $tokens = $null; $errors = $null
    [System.Management.Automation.Language.Parser]::ParseFile($_.FullName, [ref]$tokens, [ref]$errors) | Out-Null
    if ($errors) {
        $failed++
        Write-Host "FAIL  $($_.Name)"
        $errors | ForEach-Object { Write-Host "      line $($_.Extent.StartLineNumber): $($_.Message)" }
    } else {
        Write-Host "OK    $($_.Name)"
    }
}

if ($failed) { Write-Host "$failed script(s) have syntax errors"; exit 1 }
Write-Host 'All scripts passed'

Test it on your laptop: .\scripts\Test-ScriptSyntax.ps1 should print OK for each script.

Step 6: write your first Jenkinsfile

Create jenkins\Jenkinsfile (no file extension) in the repo:

pipeline {
    agent any

    options {
        timestamps()
        buildDiscarder(logRotator(numToKeepStr: '10'))   // keep the last 10 builds
    }

    triggers {
        pollSCM('H/15 * * * *')   // check GitHub for new commits about every 15 minutes
    }

    stages {
        stage('Show what we are building') {
            steps {
                sh 'git log -1 --oneline'
                sh 'ls -R scripts'
            }
        }
        stage('Check PowerShell syntax') {
            steps {
                sh 'pwsh -NoProfile -File scripts/Test-ScriptSyntax.ps1 -Path scripts'
            }
        }
    }

    post {
        success { echo 'All scripts are valid.' }
        failure { echo 'A script has a syntax error – see the log above.' }
    }
}

Read it top to bottom – it’s almost plain English:

  • agent any – run on any available machine (here, the controller)
  • options – add timestamps to the log and keep only the last 10 builds
  • triggers – poll GitHub for new commits (a webhook is faster, but GitHub can’t reach a lab machine on your laptop)
  • stages – the steps, shown as boxes on the job page
  • post – what to do when the build passes or fails

Commit and push, the Part 1 way:

git switch -c add-jenkins-pipeline
git add scripts\Test-ScriptSyntax.ps1 jenkins\Jenkinsfile
git commit -m "Add syntax check script and first Jenkins pipeline"
git push -u origin add-jenkins-pipeline

Open a pull request on GitHub and merge it into main.

Step 7: give Jenkins read access to your private repo

Your repo is private, so Jenkins needs a key. Use a fine-grained token that can only read this one repo:

  1. On GitHub: your photo → Settings → Developer settings → Personal access tokens → Fine-grained tokens → Generate new token.
  2. Name it jenkins-winops-lab, set an expiry, and under Repository access choose Only select repositories → winops-lab.
  3. Under Permissions → Repository permissions, set Contents to Read-only. Generate and copy the token.

Now store it in Jenkins:

  1. Manage Jenkins → Credentials → System → Global credentials → Add Credentials.
  2. Kind: Username with password. Username: your GitHub username. Password: the token.
  3. ID: github-winops-lab. Click Create.

Never paste tokens into a Jenkinsfile or script. Jenkins masks credentials in logs, and you can revoke this token on GitHub at any time without touching your password.

Step 8: create the pipeline job

  1. Jenkins home → New Item → name winops-lab-checks → Pipeline → OK.
  2. Scroll to Pipeline. Definition: Pipeline script from SCM.
  3. SCM: Git. Repository URL: https://github.com/YOUR-USER/winops-lab.git. Credentials: github-winops-lab.
  4. Branch Specifier: */main.
  5. Script Path: jenkins/Jenkinsfile.
  6. Save, then click Build Now.

Click the build number (#1) → Console Output. You should see your commit, the file list, OK for each script and Finished: SUCCESS.

Step 9: watch it catch a mistake

This is the moment Jenkins earns its place. On a new branch, break a script on purpose – delete a closing } in scripts\Get-DiskReport.ps1 – then commit, push and merge it.

Within 15 minutes (or click Build Now) the build goes red, and the log shows exactly which file and line is broken. Fix it, push again, and it turns green.

That’s continuous integration: every change is checked automatically, so broken scripts are caught in Jenkins, not on a production server at 2 a.m.

Common errors

  • Jenkins won’t start, “failed to find a valid Java installation” – Java wasn’t installed first, or it’s the wrong version. Run Step 1, then sudo systemctl restart jenkins.
  • Page doesn’t open on port 8080 – check sudo systemctl status jenkins; on a VM, make sure you’re using the VM’s IP and no firewall blocks 8080.
  • Couldn't find any revision to build – the branch name is wrong. Your repo uses main, so the Branch Specifier must be */main, not */master.
  • Authentication failed when Jenkins fetches the repo – the token expired, doesn’t include winops-lab, or Contents isn’t set to Read-only. Make a new token and update the credential.
  • pwsh: not found – PowerShell isn’t installed on the machine running the build. Repeat Step 4.

Keep your lab Jenkins safe

  • Don’t expose port 8080 to the internet. Jenkins can run commands on its machine.
  • Update it regularly: sudo apt update && sudo apt upgrade jenkins.
  • Install only the plugins you use – each one is extra code to patch.
  • Put every secret in Credentials, never in the repo.

FAQ

Freestyle job or Pipeline? Start with Pipeline. A Jenkinsfile lives in Git, gets reviewed in pull requests like any script, and can be rebuilt from scratch if Jenkins dies. Freestyle jobs live only in Jenkins’ settings.

Can Jenkins run scripts on my Windows servers? Yes – either with a Windows agent, or (as in Part 3) through Ansible, which connects to many servers at once and is easier to control.

Is Jenkins still worth learning when GitHub Actions exists? Yes. Many companies run Jenkins on-premises, especially where servers can’t be reached from the cloud. The ideas – pipelines in Git, stages, credentials, triggers – carry straight over to GitHub Actions and Azure DevOps.

What’s next

In Part 3 you’ll install Ansible next to Jenkins, connect it to a Windows Server, and have this same pipeline run a playbook from winops-lab against your Windows machines – with a parameter to choose the servers and a report at the end.

Practise this topic

Test yourself with free questions on this topic – instant answers and explanations.

Start practice questions

JenkinsCI/CDGitPowerShellAutomationBeginnerWindows Admin

Gopinath Karthikeyan

Gopinath Karthikeyan – Windows Site Reliability Engineer with about 12 years in enterprise Windows Server infrastructure, and founder of WinOps Academy. YouTube · LinkedIn