#!/usr/bin/env groovy pipeline { agent any options { timeout(time: 2, unit: 'HOURS') } environment { REVISION = '' CUSTOM_SCM_INFO = '' } stages { stage('Build') { steps { sh "./gradlew -Pversion='${REVISION}' testClasses" } script { def commitId = sh(returnStdout: true, script: 'git rev-parse --short HEAD').trim() def commitDate = sh(returnStdout: true, script: 'git --no-pager show -s --format=%cd --date=short HEAD').trim() REVISION = "${env.BRANCH_NAME}-${commitDate}.${commitId}" } } stage('Test') { steps { sh "./gradlew --no-build-cache -Pversion='${REVISION}' -Dtestlogger.theme=plain-parallel test" } post { always { junit '**/build/test-results/test/TEST-*.xml' } } } stage('Package') { steps { sh "./gradlew -Pversion='${REVISION}' bootJar -x test" } } } post { always { script { def commit = sh(returnStdout: true, script: 'git rev-parse HEAD') def author = sh(returnStdout: true, script: "git --no-pager show -s --format='%an' ${commit}").trim() def commitLog = sh(returnStdout: true, script: 'git log -1 --pretty=%B').trim() CUSTOM_SCM_INFO = "Latest Commit (${author}):```${commitLog}```" } deleteDir() } success { bitbucketStatusNotify( buildState: 'SUCCESSFUL' ) office365ConnectorSend color: 'good', message: "Build ${currentBuild.fullDisplayName} completed *successfully* (<${env.BUILD_URL}|Open>).\n\n\n${CUSTOM_SCM_INFO}", webhookUrl: "" } failure { bitbucketStatusNotify( buildState: 'FAILED' ) office365ConnectorSend color: 'danger', message: "Build ${currentBuild.fullDisplayName} *failed* (<${env.BUILD_URL}|Open>).\n\n\n${CUSTOM_SCM_INFO}" } unstable { office365ConnectorSend color: 'warning', message: "Build ${currentBuild.fullDisplayName} was *unstable* (<${env.BUILD_URL}|Open>).\n\n\n${CUSTOM_SCM_INFO}" } } }