小编Ami*_*are的帖子

如何在 jenkinsfile(Groovy 脚本)中发送带有附件的电子邮件?

我想在詹金斯的构建后操作后发送电子邮件。因此我编写了 jenkinsfile 如下。但我需要一些常规脚本 1. zip 文件的附件 2. 在附加文件之前,我需要将文件夹转换为 zip 格式。

注意:请不要建议电子邮件插件程序和配置。我更喜欢 Jenkins 文件方法配置

 pipeline {
    agent any
    stages {
        stage('Testing') {
            steps {
                sh 'chmod +x mvnw'
                sh './mvnw clean verify serenity:aggregate'
            }
        }
    }
    post {
        failure {
            script {
                mail (to: 'email@gmail.com',
                        subject: "Job '${env.JOB_NAME}' (${env.BUILD_NUMBER}) failed",
                        body: "Please visit ${env.BUILD_URL} for further information"
                );
                }
            }
         success {
             script {
                mail (to: 'email@gmail.com',
                        subject: "Job '${env.JOB_NAME}' (${env.BUILD_NUMBER}) success.",
                        body: "Please visit ${env.BUILD_URL} for further information.",


                  );
                } …
Run Code Online (Sandbox Code Playgroud)

groovy post-build-event jenkins jenkins-pipeline

4
推荐指数
1
解决办法
3万
查看次数