如何在多个代理上对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
?
推荐答案
在node
步骤中包装用于执行邮件发送的step
:
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屋!
查看全文