

TL;DR
- What it is: Jenkins is an open-source automation server that orchestrates building, testing, and deploying code using a distributed controller-agent architecture.
- Declarative over scripted: Modern Jenkins pipelines should default to declarative syntax via a version-controlled Jenkinsfile committed alongside your application source code.
- Core best practices: Treat pipelines as code, never run build workloads on your controller, manage secrets exclusively through the Jenkins Credentials Store, and carefully audit and test plugin dependencies.
- The missing link: Speed without validation only delivers defects faster. Integrating continuous testing directly into your Jenkins stages—using platforms like Tricentis—shifts quality left, eliminates manual QA bottlenecks, and ensures reliable deployments.
In software engineering, speed without reliability is a liability.
As releases transform from quarterly milestones to daily events, organizations can’t afford manual handoffs, inconsistent environments, or reactive debugging sessions. Teams need a predictable, automated pipeline that delivers deployable, production-ready software.
This guide walks you through building your first production-grade Jenkins CI/CD pipeline.
You’ll learn how Jenkins bridges code integration and deployment, how to configure triggers from source control, and why continuous testing is the gatekeeper that keeps fast workflows from breaking production.
What is Jenkins?
Jenkins is an open-source automation server that builds, tests, and deploys code. It boasts a plugin-driven ecosystem that has allowed it to stay relevant since 2004.
Kohsuke Kawaguchi created Hudson in 2004, renaming it to Jenkins in 2011. It remains one of the most widely used automation engines in IT. It’s also hosted by the Linux Foundation’s Continuous Delivery Foundation.
Jenkins is a centralized workflow orchestrator. It takes the burden of compiling code, running tests, packaging binaries, and deploying code off of developers’ hands.
A central Jenkins controller manages configuration, schedules jobs, monitors builds, and serves a web interface to users.
Controller-agent topology
A central Jenkins controller manages configuration, schedules jobs, monitors builds, and serves a web interface to users. It passes compilation and tests to agents that can run on the same system, virtual machines, or in containers. This topology prevents resource conflicts and makes horizontal scaling possible.
Extensibility
Plugins have been a key factor in its widespread adoption. With over 2000 extensions contributed by the community, they allow Jenkins to interface with nearly any dev tool.
Pipelines as code
The Pipeline plugin makes it possible for pipeline configurations to receive the same rigor as application source code, including versioning, peer review, and linting.
What is CI/CD?
Continuous integration and continuous delivery (CI/CD) is a practice where code changes are frequently merged, validated with automated testing, and packaged for release to environments.
Agile frameworks place work into sprints, establish cross-functional teams, and define user stories. CI/CD provides the technical tools that make this work possible.
Agile encourages teams to build and release in batches. Without automated pipelines, they quickly hit a wall where testing, packaging, and provisioning fail to keep up with this regular delivery.
CI/CD bridges the gap between agile planning and physical software delivery.
Continuous integration (CI)
Developers regularly commit and merge code into a shared repository. Each push triggers an automated build and test. This shifts testing left, to when the code is written, and provides developers with the instant feedback that agile wants.
Software remains in a releasable state, so the decision to release is a business decision rather than a moving target or a risky proposition.
Continuous delivery (CD)
CD automates packaging and staging. Software remains in a releasable state, so the decision to release is a business decision rather than a moving target or a risky proposition.
Continuous deployment (CD)
A mature pipeline deploys software without manual gates. It deploys code after automated verification, security, and quality checks. Agile teams deliver value continuously and receive instant feedback.
How Jenkins powers a CI/CD pipeline
Orchestration sits at the center of a pipeline. Jenkins is that orchestrator, connecting your version control, test runners, container and package registries, and deployment targets together.

Event-driven automation
You can think of a Jenkins pipeline as an event-driven feedback loop.
1. Source control triggers
A developer pushes a branch or opens a pull request in Git, triggering a webhook that pings the Jenkins controller.
2. Workload scheduling
The controller evaluates the event, using the project configuration to decide where and how to allocate tasks to an agent.
3. Execution & feedback
The agent executes its assigned tasks: it checks out code, executes a build, runs tests, and publishes reports. Logs and status stream back to the controller, alerting developers right away if their push or PR introduced an error.
Controllers and agents
Jenkins’ controller-agent topology is one of the reasons why it’s an industry standard. It provides your pipelines with scalability, stability, and security.
Controller
The controller manages the user interface, stores configurations, manages plugin updates, stores credentials, and coordinates jobs. In production environments, the controller does not execute build scripts.
Agents
Agents are the workers that accept tasks from the controller. They can be:
- Static instances running on physical servers or virtual machines configured for specific OS platforms.
- Dynamic and ephemeral containers run on demand within Kubernetes clusters or Docker hosts. When a job completes, the container terminates.
Pipeline as code
Teams write their pipelines in text files called Jenkinsfiles. They live with the application code, bringing development and engineering discipline to continuous delivery.
Version control
This uses the same Git tracking as branches and pull requests for the build and deploy scripts. You can also roll back a breaking change, the same way you do with breaking code.
Peer review
Infrastructure and pipeline changes undergo the same workflow as production features.
Jenkins’ flexibility has helped make it a leading choice for driving CI/CD pipelines.
Declarative vs. scripted pipelines
Jenkins’ flexibility has helped make it a leading choice for driving CI/CD pipelines. One key option is whether you define your pipelines using declarative or imperative syntax.
Declarative pipelines
Declarative syntax uses a subset of the Groovy scripting language. It’s designed to be a simple and readable syntax for defining workflows.
It accomplishes these goals with a predefined hierarchy that wraps the script with a single pipeline { … } block with designated sections for stages, steps, and post execution actions.
While the declarative syntax enforces a strict structure, you can still insert procedural logic inside script { … } blocks.
// Example: Minimal Declarative Pipeline
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Hello world ...'
}
}
}
}
Scripted (imperative) pipelines
Scripted syntax was the original Pipeline as Code implementation in Jenkins. It provides a general-purpose, imperative programming environment inside a node { … } block.
These pipelines are fully-featured Groovy scripts. You can use loops, conditional logic, exceptions, and even custom object models.
But pipelines aren’t a place for complexity. In an ideal situation, you don’t look at them very often. If you do need to make a change, you don’t want to spend a lot of time remembering how they work.
node {
stage('Example') {
if (env.BRANCH_NAME == 'main') {
echo 'Hello main world'
} else {
echo 'Otherworldy hello'
}
}
}
| Feature | Declarative pipeline | Scripted pipeline |
| Core philosophy | Opinionated, structured, focused on configuration | Imperative, free-form, programs |
| Learning curve | Low; accessible to developers and DevOps newcomers | High; requires knowledge of Apache Groovy |
| Syntax validation | Validated before execution | Validated at runtime as the script executes. |
| Error & post handling | Built-in post conditions (always, success, failure, cleanup) | Requires Groovy try-catch-finally blocks |
Which should you choose?
The short answer is to default to declarative. For most teams, declarative pipeline scripting is the standard and recommended approach. It has uniform readability, integrates with Jenkins visualization tools, offers clean error handling, and simplifies onboarding.
Scripted pipelines are only the right choice if your workflow calls for logic that doesn’t fit well into a declarative model. For example, dynamically generating stages at runtime based on external inputs or executing complex algorithms during builds.
Tutorial: Build your first Jenkins CI/CD pipeline
In this tutorial, you’ll create a declarative pipeline that pulls source code from Git and simulates a complete pipeline.
Prerequisites
Before building the pipeline, ensure the following environments and access rights are in place:
- Jenkins controller: An operational Jenkins instance (version 2.568.x or newer recommended) accessible via browser.
- Core plugins: The Jenkins setup wizard will offer to install the “suggested plugins.” Accept that option.
- Pipeline (workflow-aggregator)
- Git plugin
- Pipeline: stage view
- Source control repository: A GitHub, GitLab, or Bitbucket account with personal access tokens (PATs).
Step 1: Install and verify essential plugins
- Open the Jenkins dashboard and click the gear icon in the upper right-hand corner.

- This will open the Manage Jenkins page. Click on the Plugins option in the System Configuration section.

- Select the Installed plugins option on the left. Use the search bar to confirm that Pipeline and Git are installed and enabled.

- If either is missing, switch to the Available plugins tab. Check the boxes next to them, and click Install without restart.
Step 2: Configure version control credentials
Rather than hard-coding Git credentials or tokens into scripts, Jenkins stores them so you can access them in scripts. This tutorial will demonstrate how to configure your pipeline for GitHub. But we’ll explain how to adjust for other options.
- First, get your GitHub token. Start by going to your GitHub settings and selecting Credentials.

- Select Fine-grained personal access tokens.
- Click the Generate new token button.
- Give your token a name, an optional description, and specify the repository(s) you want to give the token access to.

- Click the Generate Token button. After confirming when your token will expire, GitHub will display the token. Copy and save it for use below.
Now, it’s time to add credentials to Jenkins.
- Use the gear or breadcrumbs to get back to Manage Jenkins, then select Credentials in the Security section.
- Click Add Credentials.

- Select Username and Password, then click Next.

- If you’re using a GitHub PAT, enter a placeholder for the user and the PAT as the password.
- If you’re using a Git server that requires a username and password, enter them instead.
- Click Create.
Step 3: Create a new pipeline project in Jenkins
Now, let’s create the project.
- Head back to the Jenkins dashboard and click New Item.

- Give your project a name and select Pipeline. Then, click OK.

- Select Triggers on the next page. Then, check GitHub hook trigger for GITScm polling. This tells Jenkins to listen for push events sent by your Git service.
Step 4: Create the Jenkinsfile
Create a text file named Jenkinsfile in the root directory of your Git project.
pipeline {
agent any
environment {
APP_NAME = 'sample-app'
DEPLOY_ENV = 'staging'
}
stages {
stage('Checkout') {
steps {
echo 'Checking out source code from repository...'
checkout scm
}
}
stage('Build') {
steps {
echo "Compiling and packaging ${env.APP_NAME}..."
// Example for Node.js: sh 'npm ci'
// Example for Java/Maven: sh './mvnw clean compile'
sh 'echo "Simulating build phase... Compile complete."'
}
}
stage('Test') {
steps {
echo 'Executing unit and static analysis test suites...'
// Example: sh 'npm test' or './mvnw test'
sh 'echo "Running test suite... All 42 tests passed."'
}
}
stage('Package') {
steps {
echo "Creating release artifact: ${env.APP_NAME}-build-${BUILD_NUMBER}..."
// Example: sh 'docker build -t myorg/sample-app:${BUILD_NUMBER} .'
sh 'echo "Artifact packaged successfully."'
}
}
stage('Deploy to Staging') {
steps {
echo "Deploying build #${BUILD_NUMBER} to ${env.DEPLOY_ENV} environment..."
// Example: sh 'kubectl apply -f k8s/staging/'
sh 'echo "Deployment step completed successfully."'
}
}
}
post {
always {
echo 'Cleaning workspace...'
cleanWs()
}
success {
echo "Build #${BUILD_NUMBER} succeeded! Artifact ready for review."
}
failure {
echo "Build #${BUILD_NUMBER} failed. Sending notification to team..."
}
}
}
Here’s an overview of the pipeline script:
- pipeline { … }: The top-level block enclosing the pipeline.
- Agent any: Directs Jenkins to use any available agent/executor to run this pipeline. Some scripts need a specific type of agent for their job, such as a Windows build server.
- environment: Defines environment variables.
- stages & stage(‘…’): Breaks the workflow into blocks in the Jenkins UI.
- steps: The block with shell commands (sh), tool invocations, or script steps.
- post: Condition blocks (always, success, failure) that run after the script.
Commit and push your Jenkinsfile to source control.
Step 5: Connect Jenkins to source control
- Go back to the Jenkins UI and your project’s configuration screen. Scroll down to the Pipeline section. In the Definition dropdown, switch from Pipeline script to Pipeline script from SCM.

- Under SCM, choose Git.

- Enter your Repository URL
- In the Credentials dropdown, select the credential ID created in Step 2 (eg. Jenkins Tutorial).
- Set the Branch Specifier to target your release branch (e.g., */main).
- Confirm that the Script Path is set to Jenkinsfile.
- Click Save.
Step 6: Trigger the build and inspect results
You’re currently at your project page.

- Click Build Now in the sidebar to run the pipeline.
- Under Build History (bottom left), click build #1.
- Select Console Output to monitor the build log as it executes.

- Once it’s done, return to the project landing page to view the Stages:

Each green check corresponds to a stage() in the Jenkinsfile. If one fails, Jenkins displays a red icon and immediately halts the script. We’ll see how that looks below.
Step 7: automatic builds on code commits
Running manual builds works for initial testing, but CI/CD requires automation: pushing code should kick off the pipeline. How you configure this depends on where your Jenkins controller lives.
In an environment where your Jenkins controller is publicly reachable or sits on a network accessible by Git, webhooks are the standard.
Production standard: Git webhooks
In an environment where your Jenkins controller is publicly reachable or sits on a network accessible by Git, webhooks are the standard.
When you push a commit, GitHub sends an HTTP POST payload to your Jenkins webhook endpoint:
- In your GitHub repository, navigate to Settings > Webhooks > Add webhook.
- Set the Payload URL to:
http://<your-jenkins-domain-or-ip-and-port>/Github-webhook/ - Set Content type to application/json and select Just the push event.
- Click Add webhook.
Local/internal: SCM polling
If you are running Jenkins locally (localhost), in a private home lab, or behind a firewall, GitHub or any other public SCM can’t reach your controller.
For local experimentation without configuring reverse proxies or tunneling tools, configure SCM Polling—where Jenkins periodically queries GitHub to check for new commits:
- Return to your project dashboard in Jenkins and click Configure in the left sidebar.
- Scroll to the Build Triggers section.
- Check the box for Poll SCM.
- In the Schedule field, enter the following cron expression:
H/2 * * * *
This tells Jenkins to poll your repository every two minutes.
Verifying the automatic trigger
Confirm polling is working:
- Make a minor edit to your project (for example, adding a README.md).
- Commit and push the change to your remote repository:
touch README.md git add README.md git commit -m "docs: test automated trigger" git push origin main - Open your Jenkins project dashboard. Within two minutes, build #2 appears in the Build History queue.

- Click into build #2 and select Changes in the sidebar. You’ll see your commit message, confirming that your pipeline executes on every push and that you can see why a new build ran from the dashboard.

Step 8: A failed build
Let’s force a build to fail.
- Open your Jenkinsfile in your favorite editor and modify the Test stage to look like this:
stage('Test') { steps { echo 'Executing unit and static analysis test suites...' // Example: sh 'npm test' or './mvnw test' error("A test failed!") sh 'echo "Running test suite... All 42 tests passed."' } }The error() function forces the script to fail and prints the message in quotes.
- Commit the change and push it to Git.
- After a couple of minutes, the build will begin and quickly fail.

- Click on the arrow next to Build #3 and select Pipeline Steps. Scroll down, and you’ll see the failed step, highlighted in red.

Jenkins CI/CD best practices
Keeping a Jenkins system running requires proper processes. Without rules, it quickly turns into a liability. Here are a few best practices to keep your pipelines healthy.
1. Treat pipelines as code
Even though Jenkins still has tools for building a pipeline in the web UI, stick with a script that lives with your code.
Define your workflow in a Jenkinsfile and keep it with your source code. This ensures changes are peer-reviewed, auditable through Git history, and rolled back if a pipeline change fails.
2. Don’t run builds on your controller
Your Jenkins controller should serve strictly as an orchestrator—managing job queues, dispatching workloads, handling webhooks, and serving the UI. Running builds on the controller creates security risks and invites issues that can take down the entire automation server.
3. Manage secrets in your Jenkins Credentials Store
Hardcoding passwords, API tokens, or SSH keys inside a Jenkinsfile is a security vulnerability. Store your keys and credentials in the Jenkins Credential Store and reference them in scripts with the credentials() helper or withCredentials() block.
withCredentials([
string(
credentialsId: 'my-api-token',
variable: 'API_TOKEN'
)
]) {
sh 'curl -H "Authorization: Bearer $API_TOKEN" https://api.example.com/deploy'
}
4. Watch plugin versions and audit dependencies
Jenkins’ vast plugin ecosystem is one of its greatest strengths and vulnerabilities.
- Avoid automatic plugin updates on production controllers.
- Test upgrades in a staging environment before rolling them out.
- Periodically audit your plugins and remove unused extensions. This reduces memory consumption, speeds up startup times, and avoids vulnerabilities.
Without automated testing embedded into your Jenkins stages, quality checks become a bottleneck, defeating the purpose of an automated pipeline.
How automated testing strengthens Jenkins CI/CD
Pipelines only solve part of the delivery equation. Orchestrating checkouts, container builds, and deployments via Jenkins gives you speed and reproducibility. But without reliable testing, they just help defects reach production faster. A pipeline is only as reliable as the quality checks inside it.
Basic unit testing isn’t enough to guarantee resilience, especially as your software grows. Cloud architectures and distributed APIs need a shift-left strategy. Your functional testing, API validation, and regression suites need to run continuously.
According to Google’s DevOps Research and Assessment (DORA) team:
“By creating rapid feedback loops and ensuring that developers work in small batches, CI enables teams to produce high-quality software, to reduce the cost of ongoing software development and maintenance, and to increase the productivity of the teams.”
— DORA Capabilities: Continuous integration
Without automated testing embedded into your Jenkins stages, quality checks become a bottleneck, defeating the purpose of an automated pipeline. Furthermore, brittle test suites that break with every minor UI update create friction, leading teams to bypass testing.
Enterprise use case: how Experian embedded continuous testing into CI/CD
Global information services leader Experian saw the impact of integrating automated, model-based testing directly into Jenkins pipelines:
The problem
Experian relied on customized enterprise platforms, including Salesforce and Oracle E-Business Suite, with internal web applications.
Their testing was bogged down with brittle scripts. Routine updates frequently broke tests, requiring endless rework. As a result, a typical regression cycle ballooned to nine weeks.
The solution
Experian shifted to Tricentis Tosca’s codeless, model-based test automation. It allowed them to run tests in their Jenkins CI/CD pipelines. This enabled non-technical testers and engineers to build end-to-end scenarios that ran in parallel in routine pipeline builds.
The outcome
By shifting testing left into their CI/CD workflow, Experian replaced nine-week regressions with continuous, on-demand testing. The team boosted overall test automation to 85%, achieved 95% requirements coverage, and dropped script maintenance overhead across release cycles.
By pairing Jenkins with robust testing engines—such as Tricentis—teams can add test automation across SAP, web, mobile, and API layers directly into their Jenkinsfile.
This transforms Jenkins from a simple task runner into an automated governance engine, validating each artifact before it reaches a production environment.
Explore how Tricentis helps teams implement continuous testing throughout Jenkins CI/CD pipelines.
This post was written by Eric Goebelbecker. Eric has worked in the financial markets in New York City for 25 years, developing infrastructure for market data and financial information exchange (FIX) protocol networks. He loves to talk about what makes teams effective (or not so effective!).
