我有一个问题,我在Jenkins管道建设与三个测试。我想运行它们,以便如果第二个示例失败,将执行下一阶段。此外,我在获取所有三个阶段的执行状态信息方面遇到了问题。我想发送一封电子邮件,将返回信息,例如。
Test 1 - success
Test2 - failure
Test3- success
字符串
我有这样的东西:
pipeline {
agent none
parameters {
...
}
environment {
...
def Test1Status
def Test2Status
def Test3Status
}
options {
ansiColor('xterm')
}
stages {
stage('Refresh Jenkins Settings only') {
when {
expression {
return params.RefreshJenkinsSettings == true
}
}
steps {
echo "This is Update Only run to refresh parameters and steps"
echo "System: ${SYSTEM_NAME}"
}
}
stage('Run Test1') {
agent {
label '...'
}
when {
expression {
return params.RefreshJenkinsSettings == false
}
}
steps {
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
sh 'python3 scripts/Test1.py -version "${Version}" '
}
}
}
stage('Test2') {
agent {
label '...'
}
when {
expression {
return params.RefreshJenkinsSettings == false
}
}
steps {
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
sh 'python Scripts\\\\Test2.py -env "${Env}" -s "${Schema}"'
}
}
}
stage('Test3') {
agent {
label '...'
}
when {
expression {
return params.RefreshJenkinsSettings == false
}
}
steps {
bat 'D:\\Pentaho\\Kitchen.bat /rep:git1 /dir:TestCase/Test3 /job:Job "/param:ENV=%Env%" ...'
}
}
}
post {
always {
script {
def emailBody = "Test Email\n\n"
// Check the status of each stage and update the email body accordingly
if (Test1Status == 'SUCCESS') {
emailBody += "Test1: SUCCESS\n"
} else {
emailBody += "Test1: FAILED\n"
}
if (Test2Status == 'SUCCESS') {
emailBody += "Test2: SUCCESS\n"
} else {
emailBody += "Test2: FAILED\n"
}
if (Test3Status == 'SUCCESS') {
emailBody += "Test3: SUCCESS\n"
} else {
emailBody += "Test3: FAILED\n"
}
// Send the email with the updated content
emailext to: "xxx@yyy.com",
subject: "Test Email",
body: emailBody,
mimeType: 'text/html'
}
}
}
}
型
1条答案
按热度按时间wz3gfoph1#
你可以这样做:
字符串
FAILED_STAGES -存储命令名称和状态