What does a production Jenkinsfile for a Java service look like?
IntermediateProductionJenkins in Production
Answer
@Library('[email protected]') _
pipeline {
agent { kubernetes { inheritFrom 'maven-build' } }
options {
timeout(time: 30, unit: 'MINUTES')
buildDiscarder(logRotator(numToKeepStr: '25'))
disableConcurrentBuilds(abortPrevious: true)
}
stages {
stage('Build & Test') {
steps { container('maven') { sh 'mvn -B -ntp verify' } }
post { always { junit 'target/surefire-reports/*.xml' } }
}
stage('Quality Gate') {
steps {
withSonarQubeEnv('sonar') { container('maven') { sh 'mvn -B sonar:sonar' } }
timeout(time: 10, unit: 'MINUTES') { waitForQualityGate abortPipeline: true }
}
}
stage('Image') {
when { branch 'main' }
steps { buildAndScanImage(name: 'shop/api', tag: env.GIT_COMMIT.take(8)) }
}
stage('Deploy staging') {
when { branch 'main' }
steps { deployHelm(env: 'staging', tag: env.GIT_COMMIT.take(8)) }
}
}
}
The business logic of scanning and deploying lives in the shared library, so this file stays short.
More on Jenkins in Production
How do you run Jenkins for high availability and scale?AdvancedHow do you tune the Jenkins controller JVM and avoid out-of-memory crashes?AdvancedHow do you back up and restore Jenkins?IntermediateHow do you upgrade Jenkins and its plugins safely?IntermediateHow do you harden a Jenkins controller?AdvancedHow do you configure dynamic Kubernetes agents in Jenkins for production use?Intermediate