我如何从詹金斯管道多次发送电子邮件

时间:2020-01-07 05:48:45

标签: email jenkins plugins jenkins-pipeline action

我有一个jenkins管道,其中定义了阶段,我想在特定阶段号之后和工作结束时发送电子邮件。
例如:假设我有一份工作,我有8个步骤。如果所有6个阶段都成功运行,我希望该工作将在第6个阶段后发送成功电子邮件。在所有阶段执行完之后,同一管道将再次发送状态。

我知道如何在最后阶段(完成所有阶段后)发送电子邮件,但是我找不到在阶段之间发送电子邮件的任何解决方案。

1 个答案:

答案 0 :(得分:0)

您可以使用emailext进行此操作:

以下是示例:

pipeline {
    agent {
        label 'slave'
    }
    stages {
        stage('First Mail') {
            steps {
                emailext    to:     'send.mail@email',
                    from:       'send.from@email',
                    subject:    "First Mail", 
                    body:       "Here is the content of the first Mail"
            }
        }   
        stage('Second Mail') {
            steps {
                emailext    to:     'send.mail@email',
                    from:       'send.from@email',
                    subject:    "Secont Mail", 
                    body:       "Here is the content of the second Mail"
            }
        } 
    }
}

如果您要根据工作结果发送邮件,可以查看以下已回答的问题:Send email on jenkins pipeline failure