What Is Jenkins?
Jenkins is a free, open-source automation server. It runs jobs that build, test and deploy software. It is self-hosted, very flexible and has thousands of plugins. You will meet it in many companies, so it is an important DevOps skill.
Architecture
- Controller (formerly master): the web UI, scheduling and configuration. Do not run builds on it
- Agents (nodes): machines, containers or Pods that run the builds
- Executors: slots on an agent for parallel builds
- Jobs/Pipelines: work definitions. Modern Jenkins uses Pipeline jobs defined in a
Jenkinsfile
Install Jenkins with Docker
Useful plugins: Pipeline, Git, GitHub Branch Source, Credentials Binding, Docker Pipeline, Kubernetes, Blue Ocean (optional), Pipeline Utility Steps, Warnings Next Generation, Configuration as Code (JCasC).
Your First Pipeline
Create a repository with a file named Jenkinsfile. In Jenkins: New Item, Pipeline (or Multibranch Pipeline), point to the repository.
Declarative Pipeline Syntax Reference
| Block | Purpose |
|---|---|
pipeline { } | Root of a declarative pipeline |
agent | Where to run: any, none, label 'linux', docker { image '...' }, kubernetes { ... } |
stages / stage | Named steps of the process |
steps | Commands such as sh, bat, echo, junit |
environment | Environment variables and credentials |
parameters | User inputs when starting a build |
options | Timeout, retry, build discarder, timestamps |
triggers | Poll SCM, cron, upstream |
when | Run a stage only on a condition (branch, tag, expression) |
post | Actions after the run: always, success, failure, unstable, cleanup |
A Realistic CI/CD Pipeline (Docker and Kubernetes)
'...' do not interpolate variables in Groovy, double quotes "..." do. For secrets, use single-quoted sh strings (as above) so the shell expands them and Groovy never prints them.
Credentials
Store secrets in Manage Jenkins, Credentials. Types: username and password, secret text, SSH private key, secret file, certificate. Use them only through withCredentials or the credentials() helper, which masks values in logs.
Triggers: Webhooks and Multibranch
- GitHub webhook: in the repo add webhook
http://JENKINS_URL/github-webhook/(push events). Faster than polling - Multibranch Pipeline: Jenkins scans a repository and creates a pipeline for every branch and pull request that contains a
Jenkinsfile - Cron:
triggers { cron('H 2 * * *') } - The
Hsymbol spreads load by hashing the job name
Agents: Docker and Kubernetes
Shared Libraries
A shared library is a Git repository of reusable Groovy functions so that many pipelines share the same logic.
Security and Operations
- Use a reverse proxy with HTTPS, enable security (no anonymous admin), and use SSO or role-based strategy
- Keep Jenkins and plugins updated, and remove unused plugins (frequent source of vulnerabilities)
- Define configuration as code with the JCasC plugin and keep it in Git
- Back up
JENKINS_HOME(or use volume snapshots) - Limit script approvals in the Script Security plugin
- Monitor disk usage and clean old builds with
buildDiscarder
Common Problems
| Problem | Fix |
|---|---|
docker: command not found in a build | Agent has no Docker. Use a Docker-enabled agent or the Docker Pipeline plugin |
Permission denied on the Docker socket | Add the Jenkins user to the docker group (understand the security risk) or use Kaniko, Buildah or BuildKit builders |
Pipeline cannot find Jenkinsfile | Check branch and script path in the job configuration |
| Builds are slow | Use caching, parallel stages and more agents |
| Secret appears in log | Use withCredentials, avoid double-quoted sh interpolation |
Practice Tasks
- Run Jenkins in Docker and create a Pipeline from a Jenkinsfile in GitHub
- Add a test stage that publishes JUnit results
- Use
withCredentialsto log in to a registry without exposing the password - Add a GitHub webhook and trigger builds on push
- Create a shared library with a
notifySlackordeployAppstep
Conclusion
Jenkins runs pipelines defined in a Jenkinsfile on ephemeral agents. Use declarative syntax, credentials binding, parallel stages, multibranch pipelines and shared libraries, and keep the controller secured and updated.

