简体   繁体   中英

Sonar Qality gates and email Jenkins Pipeline

As I want to configure that if my Quality Gate of Sonar Qube gives status error, it should not allow any thing in the body but Send email from Email Ext in Jenkins Pipeline.

 stage("Quality Gate"){
          steps{

              script{
         timeout(time: 1, unit: 'HOURS') {
             def qg = waitForQualityGate()
             if (qg.status != 'OK') {
                 error "Pipeline aborted due to quality gate failure: ${qg.status}"

         }
      }
  post {
        always {
  emailext attachmentsPattern:'Cucumber HTML Reports/$BUILD_NUMBER/cucumber-html-reports.zip' ,body:"$EMAILTEMPLATE$URLS $SONARQUBE ", mimeType: 'text/html', recipientProviders: [developers()], subject: '$PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS!', to: ' xyz@abc.com'
            }
}

You need to configure webhook on Sonar side to your Jenkins master, otherway it will always wait and failing on timeout. Email will be send cause you configured it in post stage, parametrized and with 'always' condition

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM