如何在多个代理上使用 Jenkins 管道的发布步骤? [英] How to use post steps with Jenkins pipeline on multiple agents?
本文介绍了如何在多个代理上使用 Jenkins 管道的发布步骤?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当使用每个阶段在不同代理上运行的 Jenkins 管道时,它是 良好实践 在开始时使用 agent none
:
When using the Jenkins pipeline where each stage runs on a different agent, it is good practice to use agent none
at the beginning:
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
电子邮件应该发出时的错误消息:
But doing this leads to Required context class hudson.FilePath is missing
error message when the email should go out:
[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
时,它工作正常.
When I change from agent none
to agent any
, it works fine.
如何在不使用 agent any
的情况下让 post
步骤工作?
How can I get the post
step to work without using agent any
?
推荐答案
将发送邮件的 step
包装在 node
步骤中:
wrap the step
that does the mailing in a node
step:
post {
always {
node('awesome_node_label') {
step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "test@test.com", sendToIndividuals: true])
}
}
}
这篇关于如何在多个代理上使用 Jenkins 管道的发布步骤?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文