我正在尝试更改环境变量MSG_INFO的值并将其传递到post:failstage
#!/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}不存在”
1条答案
按热度按时间vtwuwzda1#
你不能在Shell块中设置环境变量。这里有一个方法可以做到这一点。
或者,您可以将消息写入文件,然后在故障后处理步骤中读取该消息。