jenkinsci / google-chat-notification-plugin

Google Chat Notification Jenkins Plugin to send build status
https://plugins.jenkins.io/google-chat-notification/
MIT License
39 stars 20 forks source link

Notify when starting a build pipeline #13

Closed jeroen92 closed 7 months ago

jeroen92 commented 5 years ago

Heya, little feature request.

Would it be possible for to post a Google Chat notification when starting a Jenkins job? It's quite handy to see whether a build pipeline is actually being triggered.

Thanks, Jeroen

chirag-vuclip commented 5 years ago

Are you referring to build job pre-build-step? In pipeline builds you can always invoke the plugin with the necessary message.

gokeefe commented 5 years ago

In my pipeline jobs, I define a function at the start like so:

def notifyChat(String buildStatus = 'STARTED') {
  // Build status of null means success.
  buildStatus = buildStatus ?: 'SUCCESS'

  def msg = "${buildStatus}: `${env.JOB_NAME}` #${env.BUILD_NUMBER}:\n${env.BUILD_URL}"

  googlechatnotification (
    url: "id:${params.GCHAT_CRED}",
    message: "${msg}",
    sameThreadNotification: true,
    suppressInfoLoggers: true
  )
}

And then can just call that function at multiple points during the build, like so:

stage('Build') {
  steps {
    notifyChat("BUILDING")
    sh '''
      for i in $(ls -1 *.md); do
        ./generate.sh $i
      done
    '''
  }
}