Stages in Jenkins pipelines
pipeline {
agent any
stages {
stage('Checkout') {
steps {
git 'https://github.com/org/repo.git'
}
}
stage('Build') {
steps {
// compile code
// save build artifacts to S3 bucket
}
}
stage('Test') {
steps {
// download artifacts from S3
// load test data into Postgres DB
// run integration tests
// continue only if all tests pass
}
}
stage('Deploy') {
steps {
// download artifacts from S3
// deploy to Kubernetes cluster
}
}
}
}
Here is a more detailed explanation of each of the 4 stages in the pipeline:
- Get latest code: Uses the git step to check out code from a Git repository. Provides the URL to the repo as a parameter. Clones the latest commit to the local workspace. Ensures all subsequent steps have access to the freshest source code.
- Build code: Compiles the application source code into executables/packages. Saves the build artifacts like JARs, containers, etc to cloud storage. Uses S3 or an equivalent object store for storing the outputs. Makes the build outputs available for later stages.
- Test code: Fetches the build artifacts from the storage location. Loads test data and schemas into a Postgres database. Executes automated integration tests against the application. Continues only if all test cases pass as expected. Gates deployment on successfully passing tests.
- Deploy code: Downloads the vetted build artifacts for deployment. Deploys the application to a Kubernetes cluster. Pushes the containers to the target runtime environment. Makes the built and tested application available to users. This pipeline has discrete steps for each major phase of the CD process – repo checkout, build, test, and deploy. Each stage focuses on one concern and uses standard tools. This modular design enables extensibility and maintainability.
Understanding Jenkins CI/CD Pipeline And Its Stages
Jenkins is an open-source automation server that enables developers to reliably build, test, and deploy applications. It supports continuous integration and continuous delivery (CI/CD) workflows that allow teams to frequently deliver high-quality software. Jenkins is extremely popular, with over 100,000 installations worldwide.
At its core, Jenkins provides an automation engine with an extensive plugin ecosystem that offers integrations for practically any DevOps toolchain. This allows Jenkins to fit into diverse infrastructure setups and support all types of development processes.