Complete Jenkins Tutorial
Jenkins is the most widely used open-source automation server for continuous integration and delivery (CI/CD). For testers, it's how automation suites run on every code change, every night and before every release — without anyone clicking "Run". This tutorial covers what you need as an automation tester: the core concepts, setting Jenkins up, running your Selenium or API tests in a pipeline, scheduling, reports and notifications — then links every Jenkins tutorial on the site in learning order.
What Is Jenkins?
Jenkins is a Java-based automation server that runs jobs: pull code from Git, build it, run tests, publish reports and deploy. Hundreds of plugins connect it to Git, Maven, Docker, Slack, test reports and almost every other tool.
CI, Continuous Delivery and Continuous Deployment
- Continuous Integration (CI) — every change is automatically built and tested, so problems are found within minutes.
- Continuous Delivery — every passing build is ready to release; a person approves the production deployment.
- Continuous Deployment — every passing build is deployed to production automatically.
Automated tests are what make all three safe. More: Jenkins Fundamentals & CI/CD Concepts.
How Jenkins is organized
- Controller (formerly "master") — the web UI, job configuration and scheduling.
- Agents (formerly "slaves") — machines or containers that actually run builds, so you can run on Linux, Windows or Docker, and in parallel.
- Jobs — Freestyle projects (configured in the UI) or Pipelines (defined in a Jenkinsfile).
- Builds — each run of a job, with its console log, test results and artifacts.
Setting Up Jenkins (the Quick Way)
For learning, run Jenkins in Docker:
docker run -d --name jenkins -p 8080:8080 -p 50000:50000 \
-v jenkins_home:/var/jenkins_home jenkins/jenkins:lts
# Get the initial admin password
docker exec jenkins cat /var/jenkins_home/secrets/initialAdminPassword
Open http://localhost:8080, paste the password, install the suggested plugins and create an admin user. For a permanent setup, use the official installers or packages from jenkins.io. Then configure JDK and Maven under Manage Jenkins → Tools.
Plugins testers use most
| Plugin | What it's for |
|---|---|
| Git / GitHub | Pull code and react to pushes and pull requests |
| Pipeline | Jenkinsfile support (installed with the suggested plugins) |
| JUnit | Test result trends from TestNG/JUnit/Newman XML reports |
| HTML Publisher | Show Extent or other HTML reports on the build page |
| Allure | Allure reports with history |
| Email Extension / Slack Notification | Tell the team when a build fails |
| Credentials Binding | Use passwords and tokens without putting them in code |
More: Plugins, Notifications & Monitoring.
Freestyle Job or Pipeline?
A Freestyle job is configured by clicking through the UI — quick for simple tasks. A Pipeline is defined in a Jenkinsfile stored in Git — versioned, reviewable, and able to run stages in parallel. For test automation, use Pipelines. Full comparison: Jenkins Freestyle vs Pipeline.
A Jenkinsfile for a Test Automation Suite
This declarative pipeline runs a Selenium + TestNG suite with a browser and environment chosen at run time, publishes results and reports, and emails the team on failure:
pipeline {
agent any
parameters {
choice(name: 'BROWSER', choices: ['chrome', 'firefox'], description: 'Browser to run on')
choice(name: 'ENV', choices: ['qa', 'staging'], description: 'Target environment')
}
triggers {
cron('H 2 * * 1-5') // weekday nightly regression
}
stages {
stage('Checkout') {
steps { checkout scm }
}
stage('Run tests') {
steps {
withCredentials([usernamePassword(credentialsId: 'app-test-user',
usernameVariable: 'APP_USER',
passwordVariable: 'APP_PASSWORD')]) {
sh "mvn clean test -Dbrowser=${params.BROWSER} -Denv=${params.ENV} -Dheadless=true"
}
}
}
}
post {
always {
junit 'target/surefire-reports/*.xml'
publishHTML(target: [
reportDir: 'target/reports',
reportFiles: 'index.html',
reportName: 'Test Report',
keepAll: true,
alwaysLinkToLastBuild: true,
allowMissing: true
])
archiveArtifacts artifacts: 'target/failures/**',
allowEmptyArchive: true
}
failure {
emailext(
subject: "FAILED: ${env.JOB_NAME} #${env.BUILD_NUMBER}",
body: "Test run failed. Details: ${env.BUILD_URL}",
to: 'qa-team@example.com'
)
}
}
}
Commit it as Jenkinsfile in the root of your test repository, then create a Pipeline job with "Pipeline script from SCM" pointing to the repo. More: Pipelines & Jenkinsfile.
Running API tests too
REST Assured suites run the same way with mvn test. Postman collections run with Newman — see Postman Newman CI/CD.
Browsers on CI agents
Agents usually have no display, so run browsers headless with a fixed window size — or point tests at a Selenium Grid running in Docker, which gives every run the same browser versions. See the Docker + Selenium Grid Guide.
Triggers: When Should Tests Run?
| Trigger | How it works | Typical use |
|---|---|---|
| Webhook | GitHub/GitLab notifies Jenkins on every push or pull request | Smoke tests on every change ⭐ |
| Build periodically (CRON) | Runs on a schedule | Nightly full regression |
| Poll SCM | Jenkins checks Git for changes on a schedule | When webhooks can't reach Jenkins |
| Upstream job | Runs after another job finishes | Tests after a deployment job |
| Manual / REST API | "Build with Parameters", or a POST to the job's build URL | On-demand runs |
CRON syntax in 30 seconds
Five fields: minute hour day-of-month month day-of-week. H spreads load by picking a consistent "random" value per job.
H 2 * * 1-5 # once between 2:00–2:59, Monday to Friday
H/15 * * * * # every 15 minutes (e.g. Poll SCM)
H 22 * * 0 # Sunday night
@daily # once a day
More: CRON Scheduling, Poll SCM & Webhooks and Git Integration & Webhooks.
A Typical Tester's CI Setup
- On every pull request: smoke tests (a few minutes) — the PR can't merge if they fail.
- After deployment to QA: a regression subset triggered by the deploy job.
- Nightly: full regression across browsers, in parallel on a Grid.
- Every run: JUnit trends, an HTML report, failure screenshots as artifacts, and a Slack or email alert on failure.
When tests pass locally but fail here, see Test Passes Locally but Fails in Jenkins.
The Learning Path
Part 1 — Foundations
- Fundamentals & CI/CD Concepts — what Jenkins is, features, CI vs CD.
- Freestyle vs Pipeline & Job Configuration — job types, configuration and build triggers.
- CRON Scheduling & Build Triggers — CRON syntax, Build Periodically, Poll SCM vs webhooks.
Part 2 — Pipelines & Integration
- Pipelines & Jenkinsfile — declarative vs scripted, stages, post and parallel.
- Git Integration & Webhooks — Git plugin, credentials and GitHub webhooks.
- Build, Deployment & Maven — Maven integration,
pom.xml, artifacts and deployment.
Part 3 — Operations
- Plugins, Notifications & Monitoring — key plugins, email/Slack alerts and monitoring.
- Security, Administration, Distributed Builds & REST API — users and roles, backup, agents and the REST API.
Part 4 — Interview Readiness
- Top 20 Jenkins Interview Questions
- Jenkins Interview Simulator and the CI/CD Test Pipeline Visualizer
How to Use This Guide
- Beginners: set up Jenkins with Docker, then follow Parts 1 → 3 in order.
- Automation testers: copy the Jenkinsfile above into your framework and get it green, then add a webhook.
- Interview prep: CI vs CD, Freestyle vs Pipeline, triggers and CRON, and how your suite runs in CI — then Part 4.
Pair this with The Complete Selenium Guide, The Complete REST Assured Tutorial and The Complete Git Tutorial.
From Real Projects
In my projects I ran Selenium and TestNG suites in batch, group, parallel and cross-browser mode. A CI server like Jenkins is the natural next step: the same suites, triggered automatically after each build or on a schedule, with results published for the whole team. On Canolog, the many forms and screens across sales, inventory, finance and service are where keeping page details in POM classes and reusable steps in a business library paid off. Start with one job that runs your smoke suite, then build from there.
Frequently Asked Questions
What is Jenkins used for?
Automating builds, tests and deployments as part of CI/CD. For testers, it runs automation suites on every change, on a schedule and before releases, and publishes the results.
What is the difference between Freestyle and Pipeline?
Freestyle jobs are configured through the UI; Pipelines are defined as code in a Jenkinsfile, which makes them version-controlled, reusable and able to run stages in parallel.
What is the difference between CI, Continuous Delivery and Continuous Deployment?
CI builds and tests every change automatically; Continuous Delivery keeps every passing build ready to release with a manual approval; Continuous Deployment releases every passing build automatically.
Should I use webhooks or Poll SCM?
Webhooks — they trigger builds immediately. Use Poll SCM only when your Git server can't reach Jenkins.
How do you run Selenium tests in Jenkins?
Add a Jenkinsfile that checks out the code and runs
mvn clean testwith headless browsers (or a Selenium Grid), then publishes the JUnit results and HTML report.How do you trigger a Jenkins job through the REST API?
Send a POST request to
/job/<name>/build(or/buildWithParameters) with a user and API token.What is the H in Jenkins CRON?
A hash that picks a consistent value per job, spreading scheduled builds out instead of starting them all at the same minute.