Jenkins is an open-source automation server used to automate software building, testing, delivery, deployment, and other repetitive DevOps tasks.
It can work as a basic Continuous Integration server or as the central automation platform for a complete CI/CD pipeline. Jenkins supports integrations through a large plugin ecosystem.
Jenkins vs. CI/CD
Jenkins and CI/CD are related, but they are not the same.
- CI/CD is a software delivery practice.
- Jenkins is a tool used to implement and automate that practice.
Jenkins can automate this workflow:
Developer commits code → Jenkins triggers → Build → Test → Scan → Package → Deploy → Monitor
Why Jenkins Is Used
Without automation, developers may wait for nightly or weekly builds before discovering integration problems.
Jenkins can start a pipeline whenever code changes, allowing teams to detect build, testing, dependency, and integration problems earlier.
Jenkins is commonly used to:
- Build applications
- Run automated tests
- Perform code-quality checks
- Create deployable artifacts
- Build Docker images
- Deploy applications
- Schedule recurring jobs
- Send build notifications
- Maintain build logs and history
Jenkins Workflow
A typical Jenkins CI/CD workflow follows these steps:
1. Developer Commits Code
A developer pushes code to a source-code repository such as GitHub.
Jenkins can receive the repository event through a webhook or check the repository for changes using SCM polling. The Jenkins Git plugin can fetch, checkout, merge, tag, and manage Git repositories.
2. Jenkins Starts the Pipeline
Jenkins reads the pipeline instructions from the job configuration or a Jenkinsfile stored in the repository.
3. Application Is Built
Jenkins sends the source code to a build tool such as:
- Maven
- Gradle
- npm
- Ant
The build process compiles the code and creates a deployable package.
4. Automated Tests Run
Jenkins can run:
- Unit tests
- Integration tests
- API tests
- Selenium tests
- Regression tests
When an important test fails, the pipeline should stop.
5. Quality and Security Checks Run
Jenkins can integrate with tools such as:
- SonarQube
- Trivy
- Snyk
- Checkmarx
- OWASP dependency scanners
These tools help detect code-quality problems, vulnerable dependencies, exposed secrets, and insecure container images.
6. Artifact Is Stored
The successful build output can be stored in:
- JFrog Artifactory
- Nexus Repository
- Amazon ECR
- Docker Hub
- GitHub Container Registry
Common artifacts include JAR files, WAR files, ZIP packages, binaries, and Docker images.
7. Application Is Deployed
Jenkins can trigger deployment scripts or integrate with:
- Tomcat
- Ansible
- Docker
- Kubernetes
- AWS CodeDeploy
- Terraform
- Argo CD
Jenkins coordinates the workflow, while the connected deployment tools perform the required actions.
Jenkins Architecture
Jenkins uses a controller-agent architecture.
Jenkins Controller
The controller:
- Stores Jenkins configuration
- Manages jobs and pipelines
- Schedules work
- Manages plugins and credentials
- Displays results and logs
- Assigns work to available agents
Jenkins Agent
An agent is a machine or environment that executes the assigned build or pipeline work.
Agents allow organizations to:
- Run multiple jobs simultaneously
- Use different operating systems
- Separate workloads
- Scale build capacity
- Protect the Jenkins controller
Official Jenkins guidance recommends running build workloads on agents instead of the controller’s built-in node.
Node
A node is a machine registered with Jenkins that can execute work.
Executor
An executor represents one available job-execution slot on a node.
Label
A label identifies an agent capability.
Examples:
linuxwindowsdockerjava21production-deploy
A pipeline can use a label to run on the correct agent.
Important Jenkins Terminology
| Term | Meaning |
|---|---|
| Job | A configured Jenkins task |
| Pipeline | A sequence of automated stages |
| Build | One execution of a job |
| Stage | A major pipeline section such as Build or Test |
| Step | A command performed inside a stage |
| Workspace | Directory where Jenkins stores files for a job |
| Artifact | Deployable output created by a build |
| Plugin | Extension that adds Jenkins functionality |
| Jenkinsfile | Text file containing the pipeline definition |
| Upstream job | Job that triggers another job |
| Downstream job | Job triggered by another job |
Jenkins Job Types
Freestyle Job
A Freestyle job is configured primarily through the Jenkins web interface.
It is useful for:
- Simple learning exercises
- Small automation tasks
- Basic builds
However, large UI-configured jobs can become difficult to version, review, reproduce, and maintain.
Pipeline Job
A Pipeline job defines multiple stages such as:
Checkout → Build → Test → Scan → Package → Deploy
Pipeline jobs provide better control, visibility, and maintainability than large Freestyle jobs.
Multibranch Pipeline
A Multibranch Pipeline automatically discovers branches containing a Jenkinsfile and creates the required branch pipelines.
This is useful for:
- Feature branches
- Pull requests
- Development branches
- Release branches
Jenkins can automatically discover and execute Jenkinsfiles for different repository branches.
What Is a Jenkinsfile?
A Jenkinsfile is a text file containing the Jenkins Pipeline definition.
It should normally be stored with the application code in source control.
This approach is called Pipeline as Code.
Benefits include:
- Version control
- Code reviews
- Change history
- Reusability
- Easier recovery
- Consistent pipelines across environments
Jenkins officially supports storing pipeline definitions in source repositories through Jenkinsfiles.
Declarative vs. Scripted Pipeline
| Declarative Pipeline | Scripted Pipeline |
|---|---|
| Structured syntax | Flexible Groovy-based syntax |
| Easier to learn | Better for complex custom logic |
| Easier to read | Requires stronger programming knowledge |
| Recommended for most beginners | Used for advanced requirements |
⭐ Best Choice for beginners: Declarative Pipeline
Sample Declarative Jenkins Pipeline
pipeline {
agent any
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Build') {
steps {
sh 'mvn clean compile'
}
}
stage('Test') {
steps {
sh 'mvn test'
}
}
stage('Package') {
steps {
sh 'mvn package -DskipTests'
archiveArtifacts artifacts: 'target/*.war',
fingerprint: true
}
}
stage('Deploy') {
steps {
sh './deploy.sh'
}
}
}
post {
success {
echo 'Pipeline completed successfully.'
}
failure {
echo 'Pipeline failed. Review the console logs.'
}
}
}
The Jenkins Pipeline plugin supports continuous-delivery pipelines, stages, steps, agents, and Pipeline-as-Code workflows.
Jenkins Plugins
Plugins extend Jenkins and connect it with other tools.
Common plugin categories include:
- Source-control plugins
- Pipeline plugins
- Build-tool plugins
- Docker and Kubernetes plugins
- Notification plugins
- Authentication plugins
- Cloud-provider plugins
- Testing and reporting plugins
Only install plugins that are necessary. Every additional plugin adds compatibility, upgrade, maintenance, and security responsibility. Jenkins provides centralized plugin management and update controls.
Poll SCM vs. Build Periodically
Poll SCM
Jenkins checks the repository according to a schedule.
A build starts only when Jenkins detects a source-code change.
Build Periodically
Jenkins starts the job on a schedule whether the code changed or not.
Webhook
A webhook notifies Jenkins immediately after a repository event.
✅ Preferred for normal CI: Webhook
✅ Useful for recurring maintenance: Build Periodically
⚠️ Use Poll SCM when webhooks are unavailable
Jenkins Credentials and Security
Jenkins frequently needs credentials for GitHub, Docker registries, cloud platforms, servers, and deployment tools.
Credentials should be stored in Jenkins Credentials rather than written directly inside Jenkinsfiles.
Important controls include:
- Authentication
- Role-based authorization
- Least-privilege permissions
- HTTPS
- Restricted administrator access
- Protected credentials
- Regular plugin updates
- Isolated build agents
- Tested backups
Jenkins separates authentication from authorization and provides credential-management and security controls for administrators.
Jenkins Installation Basics
Jenkins can run on Linux, Windows, macOS, Docker, Kubernetes, and other Java-supported platforms.
For new installations:
- Choose a Jenkins LTS release.
- Install a Java version supported by that Jenkins release.
- Install and start Jenkins.
- Access the web interface.
- Unlock Jenkins.
- Create an administrator.
- Install only required plugins.
- Configure agents, tools, credentials, and security.
A separate external web server is normally unnecessary because standalone Jenkins includes its own embedded servlet-container environment. Always verify the current Java support policy before installing or upgrading Jenkins.
Real Jenkins Responsibilities
A DevOps engineer may be responsible for:
- Creating and maintaining Jenkins pipelines
- Writing Jenkinsfiles
- Managing controllers and agents
- Configuring Git, Maven, Docker, and Ansible integrations
- Managing credentials and user permissions
- Troubleshooting failed builds
- Monitoring pipeline health
- Updating Jenkins and plugins
- Maintaining backups
- Scheduling automation jobs
- Resolving Jenkins-related Jira tickets
- Documenting pipeline standards
- Helping developers understand build failures
These responsibilities were consolidated from the operational tasks, errors, integrations, and interview questions in the original draft.
Common Jenkins Problems
| Problem | First Check |
|---|---|
| Jenkins service does not start | Service logs and Java compatibility |
| Repository checkout fails | URL, credentials, permissions, and network |
| Maven command fails | Maven installation, PATH, tool configuration, and goals |
| Pipeline syntax fails | Jenkinsfile braces, stages, steps, and quotes |
| Agent is offline | Network, Java, credentials, disk, and connection method |
| Plugin fails after upgrade | Plugin dependencies and Jenkins compatibility |
| Deployment fails | Target credentials, network, permissions, and deployment logs |
| Job does not trigger | Webhook delivery, trigger configuration, and repository mapping |
Jenkins Best Practices
- Store Jenkinsfiles in source control.
- Prefer Pipeline jobs over large Freestyle configurations.
- Use webhooks instead of frequent SCM polling.
- Run builds on agents, not the controller.
- Store secrets in Jenkins Credentials.
- Apply least-privilege access.
- Keep Jenkins and plugins updated.
- Install only required plugins.
- Back up Jenkins configuration and test restoration.
- Use reusable Shared Libraries for repeated pipeline logic.
- Archive important artifacts and test reports.
- Monitor pipeline duration, failure rate, and agent capacity.
Jenkins supports Shared Libraries for reducing repeated Pipeline code and official backup guidance for protecting Jenkins configuration and secrets.
Advantages of Jenkins
- Open source
- Highly customizable
- Large plugin ecosystem
- Supports many platforms and tools
- Works with cloud and on-premises environments
- Supports distributed builds
- Provides Pipeline as Code
- Strong enterprise adoption and community support
Jenkins Limitations
- Jenkins infrastructure must be maintained
- Plugin dependencies can become complex
- Upgrades require planning and testing
- Poorly designed pipelines become difficult to manage
- Controllers and agents require monitoring
- Security depends heavily on correct configuration
- Scaling large Jenkins environments requires architectural planning
Jenkins is powerful because of its flexibility, but that flexibility also creates operational and governance responsibility.
Jenkins Interview Questions
What is Jenkins?
Jenkins is an open-source automation server used to automate building, testing, delivery, deployment, and other DevOps tasks.
Is Jenkins a CI/CD tool?
Jenkins is an automation server that can implement CI and CD pipelines. CI/CD is the practice; Jenkins is the automation tool.
What is a Jenkins Pipeline?
A Jenkins Pipeline is a sequence of automated stages and steps used to build, test, package, and deploy software.
What is a Jenkinsfile?
A Jenkinsfile is a version-controlled text file that contains the Jenkins Pipeline definition.
What is the difference between a controller and an agent?
The controller manages Jenkins and schedules work. Agents execute the assigned pipeline stages and jobs.
What is the difference between Poll SCM and Build Periodically?
Poll SCM starts a build only when a source-code change is detected. Build Periodically starts a job on schedule regardless of code changes.
How do you troubleshoot a failed Jenkins build?
First, identify the failed stage and review the console logs. Then check the code, tests, dependencies, credentials, tools, agent, network, permissions, and deployment target.
What is the difference between Declarative and Scripted Pipeline?
Declarative Pipeline uses a structured and beginner-friendly syntax. Scripted Pipeline provides greater Groovy flexibility for complex workflows.
Interview Answer to Memorize
“Jenkins is an open-source automation server used to implement CI/CD pipelines. It integrates with tools such as Git, Maven, SonarQube, Docker, Ansible, Kubernetes, and artifact repositories. A Jenkinsfile defines Pipeline-as-Code stages such as checkout, build, test, scan, package, and deployment. The Jenkins controller manages pipelines, while agents execute the workloads.”
Final Summary
Remember these five points:
- Jenkins is an automation server.
- CI/CD is the practice Jenkins helps automate.
- A Jenkinsfile stores the pipeline as code.
- The controller manages work, and agents execute it.
- A normal pipeline follows:
Checkout → Build → Test → Scan → Package → Deploy