Snippets

troii Software GmbH Jenkinsfile Groovy Syntax

Updated by Thomas Einwaller

File Jenkinsfile Modified

  • Ignore whitespace
  • Hide word diff
 				try {
 					bitbucketStatusNotify(buildState: "INPROGRESS")
 					sh "./gradlew clean test"
-					currentBuild.result = "SUCCESS"
 				} catch (ex) {
 					currentBuild.result = "UNSTABLE"
 				} finally {
 
 			stage("Build") {
 				sh "./gradlew assemble"
-				currentBuild.result = "SUCCESS"
 			}
 
 			stage("Publish") {
 							returnStdout: true
 					).trim()
 					sh "./gradlew publish pushDockerImage"
-					currentBuild.result = "SUCCESS"
 					slack("good", "Docker Image $dockerTag build for ${currentBuild.fullDisplayName} finished")
 				}
 			}
 		}
 
 	} finally {
-		if (currentBuild.result == "SUCCESS") {
+		if (currentBuild.result == null) {
 			bitbucketStatusNotify(buildState: "SUCCESSFUL")
 		} else if (currentBuild.result == "FAILURE" || currentBuild.result == "UNSTABLE" ) {
 			bitbucketStatusNotify(buildState: "FAILED")
Created by Thomas Einwaller

File Jenkinsfile Added

  • Ignore whitespace
  • Hide word diff
+#!/usr/bin/env groovy
+
+def slack(String color, String message) {
+	for (channel in [ "#builds", "#project-status" ]) {
+		slackSend(channel: channel, color: color, message: message)
+	}
+}
+
+node(label: "java8") {
+
+	checkout scm
+
+	try {
+
+		withCredentials([usernamePassword(credentialsId: "nexusCredentials", passwordVariable: "ORG_GRADLE_PROJECT_nexusPassword", usernameVariable: "ORG_GRADLE_PROJECT_nexusUser")]) {
+
+			stage("Test") {
+				try {
+					bitbucketStatusNotify(buildState: "INPROGRESS")
+					sh "./gradlew clean test"
+					currentBuild.result = "SUCCESS"
+				} catch (ex) {
+					currentBuild.result = "UNSTABLE"
+				} finally {
+					junit allowEmptyResults: true, testResults: "**/build/test-results/test/*.xml"
+				}
+			}
+
+			stage("Build") {
+				sh "./gradlew assemble"
+				currentBuild.result = "SUCCESS"
+			}
+
+			stage("Publish") {
+				if (BRANCH_NAME ==~ "master|release/.*|hotfix/.*") {
+					dockerTag = sh(
+							script: "./gradlew printDockerTag --quiet",
+							returnStdout: true
+					).trim()
+					sh "./gradlew publish pushDockerImage"
+					currentBuild.result = "SUCCESS"
+					slack("good", "Docker Image $dockerTag build for ${currentBuild.fullDisplayName} finished")
+				}
+			}
+
+		}
+
+	} finally {
+		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>)")
+		}
+	}
+
+}
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.