DevOps Intermediate
Jenkins — Modern Pipeline Patterns¶
JenkinsCI/CDPipelineAutomation 5 min read
Jenkins shared libraries, declarative pipeline, parallel stages and Kubernetes-based agents.
Shared Libraries¶
// vars/standardPipeline.groovy
def call(Map config = [:]) {
pipeline {
agent { kubernetes { yaml agentPod() } }
stages {
stage('Build') {
steps { sh "docker build -t ${config.image}:${env.BUILD_NUMBER} ." }
}
stage('Test') {
parallel {
stage('Unit') { steps { sh 'make test-unit' } }
stage('Integration') { steps { sh 'make test-integration' } }
stage('Lint') { steps { sh 'make lint' } }
}
}
stage('Deploy') {
when { branch 'main' }
steps { sh "kubectl set image ..." }
}
}
}
}
// Jenkinsfile
@Library('shared-pipeline') _
standardPipeline(image: 'registry/myapp', app: 'myapp')
Kubernetes Agents¶
pipeline {
agent {
kubernetes {
yaml '''
apiVersion: v1
kind: Pod
spec:
containers:
- name: golang
image: golang:1.22
command: [sleep]
args: [infinity]
- name: docker
image: docker:24-dind
securityContext:
privileged: true
'''
}
}
stages {
stage('Build') {
steps { container('golang') { sh 'go build ./...' } }
}
}
}
Best Practices¶
- Declarative pipeline > scripted
- Shared libraries for repeating patterns
- Parallel stages for faster feedback
- K8s agents for isolation and scalability
- Credentials plugin for secrets
Summary¶
Modern Jenkins with shared libraries and K8s agents is still a powerful CI/CD tool. The key is standardization.
Need Help with Implementation?¶
Our team has experience designing and implementing modern architectures. We’re happy to help.