当使用詹金斯管道,其中在不同的代理每个阶段的运行,这是很好的做法,以使用agent none开头:
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]) } } }
但是,这样做会Required context class hudson.FilePath is missing在电子邮件应发送出去时导致错误消息:
Required context class hudson.FilePath is missing
[Pipeline] { (Declarative: Post Actions) [Pipeline] step Required context class hudson.FilePath is missing Perhaps you forgot to surround the code with a step that provides this, such as: node [Pipeline] error [Pipeline] }
当我从改变agent none到agent any,它工作正常。
agent any
我如何post不使用就可以上班agent any?
post
将step执行邮寄的包裹在一个node步骤中:
step
node
post { always { node('awesome_node_label') { step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "test@test.com", sendToIndividuals: true]) } } }