- Continuous Integration (CI): CI is a development practice where developers frequently merge code changes into a shared repository, often multiple times per day. Each merge triggers an automated build and test sequence to detect integration errors early. Jenkins provides a reliable platform for scheduling these builds and reporting results.
- Continuous Delivery (CD): CD extends CI by ensuring that every change passing automated builds and tests is automatically prepared for release to production. The deployment itself may still require manual approval, but the release process is automated and repeatable. Jenkins pipelines model these delivery workflows as code.
- Pipeline as Code: Jenkins pipelines are defined in a Jenkinsfile, a text file describing the entire build, test, and deploy process. Stored in the source repository alongside application code, the Jenkinsfile promotes version control and collaboration on the delivery process itself.
- Declarative vs Scripted Pipelines: Jenkins supports two pipeline syntaxes. Declarative pipelines offer a simpler, structured syntax with predefined sections, ideal for most CI/CD scenarios. Scripted pipelines use full Groovy programming capabilities for complex, conditional workflows requiring fine-grained control.
- Agent Nodes: Jenkins pipelines run on agents, which are worker machines executing the steps defined in the pipeline. The
agentdirective specifies where the pipeline or individual stages execute, such as a dedicated build server or a Docker container. - Stages and Steps: A pipeline is composed of stages representing distinct phases like Build, Test, and Deploy. Within each stage, steps define actual actions, such as running shell commands, invoking build tools, or executing tests. Stages run sequentially by default.
- Triggers and Events: Pipelines can be triggered by various events including code commits via webhooks, scheduled cron jobs, upstream pipeline completion, or manual initiation. Proper trigger configuration ensures pipelines start at the right time and respond to changes automatically.
- Benefits of Automated Pipelines: Automated pipelines reduce manual errors, enforce consistency across environments, provide fast feedback to developers, and enable teams to release software more frequently and reliably. Jenkins integrates with hundreds of plugins to extend pipeline capabilities.
- Environment Variables: Jenkins pipelines can access environment variables provided by the system or defined within the pipeline itself. The environment directive allows setting variables at the pipeline or stage level, enabling configuration of paths, credentials, or build parameters. These variables can be referenced in steps, making pipelines adaptable to different environments without hardcoding values.
- Post Actions: The post section in a declarative pipeline defines actions executed after all stages complete, regardless of success or failure. Common post conditions include always, success, failure, and unstable. This section is useful for sending notifications, cleaning up resources, archiving artifacts, or triggering downstream pipelines based on the final outcome.
- Parallel Execution: Pipelines can run stages in parallel using the parallel directive inside a stage. This speeds up execution by running independent tasks simultaneously, such as testing across multiple operating systems or building different configurations. Declarative pipelines support parallel execution within a stage containing multiple branches, each defined as a separate step block.
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building...'
}
}
stage('Test') {
steps {
echo 'Testing...'
}
}
stage('Deploy') {
steps {
echo 'Deploying...'
}
}
}
}This minimal declarative pipeline defines three stages: Build, Test, and Deploy. Each stage contains a single step that prints a message. In a real pipeline, these steps would invoke actual build tools, test runners, and deployment scripts.
- Continuous Integration merges code frequently and runs automated builds and tests.
- Continuous Delivery automates the release process up to production deployment.
- Jenkins pipelines are defined as code in a Jenkinsfile stored in the repository.
- Declarative pipelines use a structured syntax; scripted pipelines offer full Groovy flexibility.
- Pipelines run on agents and are composed of stages and steps.
- Triggers automate pipeline execution based on events or schedules.
- Automated pipelines improve reliability, consistency, and release frequency.