title: Is there a way to move the entire post {} build section in Jenkinsfile to the global pipeline library?
body: <p>I'm relatively new to Jenkins pipelines, but having implemented already a few, I've realised I need to start using jenkins shared library before I go mad.</p>
  
  <p>Have already figured out how to define some repetitive steps in the library and call them with less clutter from Jenkinsfile, but not sure if the same thing can be done for the entire post build section (thought I've read about to how to <a href="https://jenkins.io/blog/2017/10/02/pipeline-templates-with-shared-libraries/" rel="nofollow noreferrer">define the entire pipeline in the lib</a> and <a href="https://automatingguy.com/2017/12/29/jenkins-pipelines-shared-libraries/" rel="nofollow noreferrer">similar</a>), as this is pretty much static end of every single pipeline code:</p>
  
  <pre><code>@Library('jenkins-shared-library')_
  pipeline {
      agent none
      stages {
          stage ('System Info') { agent any
              steps { printSysInfo() }
          }
  
          stage ('Init'){ agent {label 'WinZipSE'}
              steps { init('SCMroot') }
          }
          stage('Build') { agent any 
              steps { doMagic() }
          }
      }
  
      // This entire 'post {}' section needs to go to a shared lib
      // and be called just with a simple methed call, e.g.
      // doPostBuild()
      post {
          always {
              node ('master') {
                  googlechatnotification (
                  message: '[$BUILD_STATUS] Build $JOB_NAME $BUILD_NUMBER has finished',
                  url: 'id:credential_id_for_Ubuntu')
  
                  step (
                      [$class: 'Mailer',
                      recipients: 'sysadmins@example.com me@example.com',
                      notifyEveryUnstableBuild: true,
                      sendToIndividuals: true]
                  )
              }
          }
          success {
              node ('master') {
                  echo 'This will run only if successful'
              }
          }
          failure {
              node ('master') {
                  echo 'This will run only if failed'
              }
          }
          // and so on
      }
  }
  </code></pre>
  
  <p>I just dunno how to syntactically achieve that. For sure, I can define the entire post build section an a lib/var like: <code>doPotBuild.groovy</code></p>
  
  <pre><code>def call () {
    post {...}
  }
  </code></pre>
  
  <p>but how I will eventually call it from within my Jenkinsfile outside of that defined <code>post {}</code> build block section (AKA stages).</p>
  
  <p>I can call it within some <code>stage('post build){doPostBuild()}</code>, but it won't serve the way how the true <code>post {}</code> section is supposed to work, e.g. it won't get executed it there was failure in one of the previous stages.</p>
  
  <p>Any thoughts on that and mainly working examples?</p>