pipeline { agent { node { label: 'docker' } } } parameters { booleanParam( name: 'SNYK_TEST', defaultValue: true, description: 'Do you want to run Snyk tests?' ) booleanParam( name: 'RELEASE_INPUT', defaultValue: false, description: 'Do you want to release this version? (Only relevant if branch is master or release/*)' ) } options { timeout(time: 1, unit: 'HOURS') buildDiscarder( logRotator( numToKeepStr: '10', artifactNumToKeepStr: '3' ) ) ansiColor('xterm') } triggers { cron('@weekly') } stages { stage('Checkout') { agent { label 'docker' } steps { checkout scm sh 'git fetch --prune --tags' } } stage('Verify') { agent { label 'docker' } steps { sh 'mvn clean verify' } } stage('Snyk test') { agent { label 'docker' } when { expression { return params.SNYK_TEST } } steps { sh 'mvn snyk:test' } } stage('Deploy') { agent { label 'docker' } when { anyOf { branch 'master' branch pattern: 'release/*' } not { expression { return params.RELEASE_INPUT } } } steps { sh 'mvn deploy' } } stage('Snyk monitor') { agent { label 'docker' } when { anyOf { branch 'master' branch pattern: 'release/*' } expression { return params.SNYK_TEST } } steps { sh 'mvn snyk:monitor' } } stage('Release') { agent { label 'docker' } when { allOf { anyOf { branch 'master' branch pattern: 'release/*' } expression { return params.RELEASE_INPUT } } } environment { RELEASE_VERSION = sh( returnStdout: true, script: 'mvn help:evaluate -Dexpression=project.version -q -DforceStdout' ).trim().replace('-SNAPSHOT','') } steps { sh "git checkout ${BRANCH_NAME}" sh 'mvn release:prepare release:perform -V' script { currentBuild.description = "Release ${RELEASE_VERSION}" currentBuild.keepLog = true } } } } }