├── README.md ├── .gitignore ├── vars ├── sendNotifications.txt └── sendNotifications.groovy └── LICENSE /README.md: -------------------------------------------------------------------------------- 1 | # jenkins-pipeline-shared -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Mobile Tools for Java (J2ME) 4 | .mtj.tmp/ 5 | 6 | # Package Files # 7 | *.jar 8 | *.war 9 | *.ear 10 | 11 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 12 | hs_err_pid* 13 | -------------------------------------------------------------------------------- /vars/sendNotifications.txt: -------------------------------------------------------------------------------- 1 | sendNotifications(buildStatus='STARTED') 2 | 3 |
4 | Sends notifications via HipChat, Slack, and email. 5 | Defaults the sending "Started" notification. 6 | Pass the build status string and it customize the notifications based on status. 7 |
8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Liam Newman 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /vars/sendNotifications.groovy: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env groovy 2 | 3 | /** 4 | * Send notifications based on build status string 5 | */ 6 | def call(String buildStatus = 'STARTED') { 7 | // build status of null means successful 8 | buildStatus = buildStatus ?: 'SUCCESSFUL' 9 | 10 | // Default values 11 | def color = 'RED' 12 | def colorCode = '#FF0000' 13 | def subject = "${buildStatus}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'" 14 | def summary = "${subject} (${env.BUILD_URL})" 15 | def details = """${buildStatus}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':
16 |Check console output at "${env.JOB_NAME} [${env.BUILD_NUMBER}]"
""" 17 | 18 | // Override default values based on build status 19 | if (buildStatus == 'STARTED') { 20 | color = 'YELLOW' 21 | colorCode = '#FFFF00' 22 | } else if (buildStatus == 'SUCCESSFUL') { 23 | color = 'GREEN' 24 | colorCode = '#00FF00' 25 | } 26 | 27 | // Send notifications 28 | slackSend (color: colorCode, message: summary) 29 | 30 | hipchatSend (color: color, notify: true, message: summary) 31 | 32 | emailext ( 33 | to: 'bitwiseman@bitwiseman.com', 34 | subject: subject, 35 | body: details, 36 | recipientProviders: [[$class: 'DevelopersRecipientProvider']] 37 | ) 38 | } 39 | --------------------------------------------------------------------------------