DevOps Pokročilý
Jenkins — Moderní Pipeline Patterns¶
JenkinsCI/CDPipelineAutomatizace 5 min čtení
Jenkins shared libraries, deklarativní pipeline, parallel stages a 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¶
- Deklarativní pipeline > skriptovací
- Shared libraries pro opakující se patterny
- Parallel stages pro rychlejší feedback
- K8s agents pro izolaci a škálovatelnost
- Credentials plugin pro secrets
Shrnutí¶
Moderní Jenkins s shared libraries a K8s agents je stále silný CI/CD nástroj. Klíč je standardizace.
Potřebujete pomoct s implementací?¶
Náš tým má zkušenosti s návrhem a implementací moderních architektur. Rádi vám pomůžeme.