Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Committed Software
Committed Software

Posted on • Originally published atcommitted.software on

     

Jenkins Slack Notifications

slackNotifications

To add a slack notification from our continuous integration builds on Jenkins Blue Ocean we use theSlack Notification plugin. Adding a set of functions to the Jenkinsfile which is then called in thepost section of the pipeline. We use the git command to extract the committers name and the hash of the commit so we can link to the commit in bitbucket and add the author’s name if the build has failed or is unstable so it will be brought to their attention.

pipeline{agent{...}stages{stage('env'){steps{notifyStarted()}}...}post{success{notifySuccess()}unstable{notifyUnstable()}failure{notifyFailed()}}}defnotifyBuild(StringbuildStatus='STARTED',StringcolorCode='#5492f7',Stringnotify=''){defproject='projectName'defchannel="${project}"defbase="https://bitbucket.org/committed/${project}/commits/"defcommit=sh(returnStdout:true,script:'git log -n 1 --format="%H"').trim()deflink="${base}${commit}"defshortCommit=commit.take(6)deftitle=sh(returnStdout:true,script:'git log -n 1 --format="%s"').trim()defsubject="<${link}|${shortCommit}> ${title}"defsummary="${buildStatus}: Job <${env.RUN_DISPLAY_URL}|${env.JOB_NAME} [${env.BUILD_NUMBER}]>\n${subject} ${notify}"slackSend(channel:"#${channel}",color:colorCode,message:summary)}defauthor(){returnsh(returnStdout:true,script:'git log -n 1 --format="%an" | awk \'{print tolower($1);}\'').trim()}defnotifyStarted(){notifyBuild()}defnotifySuccess(){notifyBuild('SUCCESS','good')}defnotifyUnstable(){notifyBuild('UNSTABLE','warning',"\nAuthor: @${author()} <${RUN_CHANGES_DISPLAY_URL}|Changelog>")}defnotifyFailed(){notifyBuild('FAILED','danger',"\nAuthor: @${author()} <${RUN_CHANGES_DISPLAY_URL}|Changelog>")}
Enter fullscreen modeExit fullscreen mode

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

  • Location
    UK
  • Work
    Developer at Committed Software
  • Joined

Trending onDEV CommunityHot

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp