def version = "" pipeline { environment { registry = "hftstuttgart/modocot-backend" registryCredential = 'Dockerhub' dockerImage = '' } agent any tools { jdk 'Java11' maven 'Maven_Home' } stages { stage('prepare') { steps { checkout ([ $class: 'GitSCM', branches: scm.branches, extensions: scm.extensions + [[$class: 'CloneOption', noTags: false, reference: '', shallow: false]], userRemoteConfigs: scm.userRemoteConfigs ]) script { version = sh(script: 'git describe --tags --always', returnStdout: true).trim() echo sh(script: 'env|sort', returnStdout: true) } } } stage('compile') { steps { sh 'mvn clean package' } } stage('build Docker image') { steps { script { dockerImage = docker.build registry } } } stage('push development image') { steps { script { docker.withRegistry( '', registryCredential ) { dockerImage.push("${env.GIT_BRANCH}") } } } } stage('release') { when { expression { version ==~ /[0-9]+.[0-9]+.[0-9]+/ } } steps { script { docker.withRegistry( '', registryCredential ) { dockerImage.push("latest") dockerImage.push("${version}") } } } } } }