jenkins发送emailext 邮件

  1. 发送邮件

https://blog.csdn.net/qq_30141993/article/details/81031151



import jenkins.model.*

@NonCPS
def getJobNames() {
Hudson.instance.getAllItems(org.jenkinsci.plugins.workflow.job.WorkflowJob)*.fullName 
}
    
pipeline {
    agent any
    stages {
        
        stage('Test Stage') {
            steps {
                sh '''
                    pwd
                '''
            }
            
        }
    

        stage('getJobNames') {
            
            steps {
                
                script {
                    
                    def jobNames = getJobNames()
                    def matchjobs = jobNames.findAll{ name -> name =~ /(test)\w*/ }
                    // println matchjobs
                    matchjobs.each {
                        try {
                            println(it)
                            res = jenkins.model.Jenkins.instance.getItem(it).lastBuild.getResult()
                            println res     
                        } catch (NullPointerException e1) {
                                e1.printStackTrace();
                        }
                    }
        
                }  
              
            }
        
        }

        
    }//stages
    
    post {
        always {
            echo 'This will always run'
            script {                   
                    emailext (subject:'${ENV, var ="JOB_NAME"}',
                                body:'${FILE ,path="email.html"}',
                                to:'sgamize@sina.com',)         
                }          
        }
        success {
            echo 'This will run only if successful'
        }
        failure {
            echo 'This will run only if failed'
        }
        unstable {
            echo 'This will run only if the run was marked as unstable'
        }
        changed {
            echo 'This will run only if the state of the Pipeline has changed'
            echo 'For example, if the Pipeline was previously failing but is now successful'
        }
    }
}


上一篇:SharePoint2010 安装时报“未能启动数据库服务 MSSQL$Sharepoint"解决办法


下一篇:关于Java连接redis实现缓存的时候出现READONLY You can‘t write against a read only slave.