+def slack(String color, String message) {
+ for (channel in [ "#builds", "#project-status" ]) {
+ slackSend(channel: channel, color: color, message: message)
+ withCredentials([usernamePassword(credentialsId: "nexusCredentials", passwordVariable: "ORG_GRADLE_PROJECT_nexusPassword", usernameVariable: "ORG_GRADLE_PROJECT_nexusUser")]) {
+ bitbucketStatusNotify(buildState: "INPROGRESS")
+ sh "./gradlew clean test"
+ currentBuild.result = "SUCCESS"
+ currentBuild.result = "UNSTABLE"
+ junit allowEmptyResults: true, testResults: "**/build/test-results/test/*.xml"
+ sh "./gradlew assemble"
+ currentBuild.result = "SUCCESS"
+ if (BRANCH_NAME ==~ "master|release/.*|hotfix/.*") {
+ script: "./gradlew printDockerTag --quiet",
+ sh "./gradlew publish pushDockerImage"
+ currentBuild.result = "SUCCESS"
+ slack("good", "Docker Image $dockerTag build for ${currentBuild.fullDisplayName} finished")
+ if (currentBuild.result == "SUCCESS") {
+ bitbucketStatusNotify(buildState: "SUCCESSFUL")
+ } else if (currentBuild.result == "FAILURE" || currentBuild.result == "UNSTABLE" ) {
+ bitbucketStatusNotify(buildState: "FAILED")
+ slack("danger", "The pipeline ${currentBuild.fullDisplayName} failed. (<${env.BUILD_URL}|Open>)")