微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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:'[email protected]',)         
                }          
        }
        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'
        }
    }
}


版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐