当使用詹金斯管道,其中每个阶段都会对不同的代理运行时,它是很好的做法,以使用agent none开头:
pipeline {
agent none
stages {
stage('Checkout') {
agent { label 'master' }
steps { script { currentBuild.result = 'SUCCESS' } }
}
stage('Build') {
agent { label 'someagent' }
steps { bat "exit 1" }
}
}
post {
always {
step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "test@test.com", sendToIndividuals: true])
}
}
}
Run Code Online (Sandbox Code Playgroud)
但这样做会导致Required context class hudson.FilePath is missing电子邮件出现时出现错误消息:
[Pipeline] { (Declarative: Post Actions)
[Pipeline] step
Required context class hudson.FilePath is missing …Run Code Online (Sandbox Code Playgroud) 我开始使用 Jenkins 声明式管道。现在,我希望具有与Mailer 插件的使用中定义的相同的电子邮件通知行为:
- 每个失败的构建都会触发一封新电子邮件。
- 在失败(或不稳定)构建之后成功构建会触发新电子邮件,表明危机已经结束。
- 成功构建后的不稳定构建会触发一封新电子邮件,表明存在回归。
- 除非配置,否则每个不稳定的构建都会触发一封新电子邮件,表明回归仍然存在。
我阅读了Pipelines 中的 Notifications,但它没有根据上述规则进行通知。另外,在构建失败的情况下,消息正文中不包含控制台输出的一部分。
有人知道如何在声明性管道中做到这一点吗?