1#!groovy 2 3/* 4 * 5 * Licensed to the Apache Software Foundation (ASF) under one or more 6 * contributor license agreements. See the NOTICE file distributed with 7 * this work for additional information regarding copyright ownership. 8 * The ASF licenses this file to You under the Apache License, Version 2.0 9 * (the "License"); you may not use this file except in compliance with 10 * the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 * 20 */ 21pipeline { 22 agent { 23 node { 24 label 'ubuntu' 25 } 26 } 27 28 tools { 29 maven 'Maven 3 (latest)' 30 jdk 'JDK 1.8 (latest)' 31 } 32 33 stages { 34 stage('Build') { 35 steps { 36 sh 'mvn' 37 } 38 post { 39 always { 40 junit(testResults: '**/surefire-reports/*.xml', allowEmptyResults: true) 41 } 42 } 43 } 44 stage('Deploy') { 45 when { 46 branch 'master' 47 } 48 steps { 49 sh 'mvn deploy' 50 } 51 } 52 } 53 54 // Send out notifications on unsuccessful builds. 55 post { 56 // If this build failed, send an email to the list. 57 failure { 58 script { 59 if(env.BRANCH_NAME == "master") { 60 def state = (currentBuild.previousBuild != null) && (currentBuild.previousBuild.result == 'FAILURE') ? "Still failing" : "Failure" 61 emailext( 62 subject: "[Lang] Change on branch \"${env.BRANCH_NAME}\": ${env.JOB_NAME} - Build # ${env.BUILD_NUMBER} - $state", 63 body: """The Apache Jenkins build system has built ${env.JOB_NAME} (build #${env.BUILD_NUMBER}) 64 65Status: ${currentBuild.result} 66 67Check console output at <a href="${env.BUILD_URL}">${env.BUILD_URL}</a> to view the results. 68""", 69 to: "[email protected]", 70 recipientProviders: [[$class: 'DevelopersRecipientProvider']] 71 ) 72 } 73 } 74 } 75 76 // If this build didn't fail, but there were failing tests, send an email to the list. 77 unstable { 78 script { 79 if(env.BRANCH_NAME == "master") { 80 def state = (currentBuild.previousBuild != null) && (currentBuild.previousBuild.result == 'UNSTABLE') ? "Still unstable" : "Unstable" 81 emailext( 82 subject: "[Lang] Change on branch \"${env.BRANCH_NAME}\": ${env.JOB_NAME} - Build # ${env.BUILD_NUMBER} - $state", 83 body: """The Apache Jenkins build system has built ${env.JOB_NAME} (build #${env.BUILD_NUMBER}) 84 85Status: ${currentBuild.result} 86 87Check console output at <a href="${env.BUILD_URL}">${env.BUILD_URL}</a> to view the results. 88""", 89 to: "[email protected]", 90 recipientProviders: [[$class: 'DevelopersRecipientProvider']] 91 ) 92 } 93 } 94 } 95 96 // Send an email, if the last build was not successful and this one is. 97 success { 98 script { 99 if ((env.BRANCH_NAME == "master") && (currentBuild.previousBuild != null) && (currentBuild.previousBuild.result != 'SUCCESS')) { 100 emailext ( 101 subject: "[Lang] Change on branch \"${env.BRANCH_NAME}\": ${env.JOB_NAME} - Build # ${env.BUILD_NUMBER} - Back to normal", 102 body: """The Apache Jenkins build system has built ${env.JOB_NAME} (build #${env.BUILD_NUMBER}) 103 104Status: ${currentBuild.result} 105 106Check console output at <a href="${env.BUILD_URL}">${env.BUILD_URL}</a> to view the results. 107""", 108 to: "[email protected]", 109 recipientProviders: [[$class: 'DevelopersRecipientProvider']] 110 ) 111 } 112 } 113 } 114 } 115} 116