自定义詹金斯电子邮件

问题描述 投票:0回答:0

我正在尝试更改环境变量 MSG_INFO 的值并将其传递给 post:fail 阶段

#!/usr/bin/env groovy
def msg_info = ''
pipeline {
  agent {
        
    }
    
    environment
    {
        MSG_INFO = ""
    }
    
    stages{
            stage('Fetch_sonar_analysis') {
                    steps {
                        container('tools') {
                             
                            sh '''
                            ls -l
                            csv_file_path=$(find . -name *.csv)
                            if [ -z "$csv_file_path" ]; 
                            then
                            env.MSG_INFO=$(echo "${file} doesn't exist")
                                exit 1
                            fi
                            '''
                    }
                }
            }
    }
    post {
        success {
                    emailext attachmentsPattern: '**/*.csv' , body: "Hi,\nPASS : ${env.BUILD_URL}.\nPlease find the csv attached to this email.\nThank you.", 
                    subject: "Sonar_Report_csv :: Pipeline Build JOB :  ${env.BUILD_NUMBER}-- Status: SUCCESS", 
                    mimeType: 'text/plain',to: "mail.com"
                    
                }
        failure {
                    mail to: 'mail.com',
                    subject: "Sonar_Report_csv :: Pipeline Build JOB :  ${env.BUILD_NUMBER}-- Status: FAILED",
                    body: "Hi,\n ${env.MSG_INFO} \nSomething is wrong Here : ${env.BUILD_URL}.\nThank you."
                }

        }
}           

我想自定义电子邮件消息但是当我打印 env.MSG_INFO 时它打印失败而不是“${file} 不存在”

bash shell jenkins jenkins-pipeline jenkins-groovy
© www.soinside.com 2019 - 2024. All rights reserved.