Dan*_*ann 19 jenkins jenkins-pipeline
当使用詹金斯管道,其中每个阶段都会对不同的代理运行时,它是很好的做法,以使用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
Perhaps you forgot to surround the code with a step that provides this, such as: node
[Pipeline] error
[Pipeline] }
Run Code Online (Sandbox Code Playgroud)
当我改为agent none
时agent any
,它工作正常.
如何在post
不使用的情况下使用该步骤agent any
?
bur*_*ttk 27
将step
邮件包装成node
一步:
post {
always {
node('awesome_node_label') {
step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "test@test.com", sendToIndividuals: true])
}
}
}
Run Code Online (Sandbox Code Playgroud)
小智 7
我知道这是旧的,但我偶然发现了这个寻找相关的东西。如果你想在任何节点上运行 post 步骤,你可以使用
post {
always {
node(null) {
step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "test@test.com", sendToIndividuals: true])
}
}
}
Run Code Online (Sandbox Code Playgroud)
https://jenkins.io/doc/pipeline/steps/workflow-durable-task-step/#node-allocate-node说标签可以留空。很多时候在声明性管道中,如果某些内容留空,这会导致错误。要解决此问题,将其设置为 null 通常会起作用。
归档时间: |
|
查看次数: |
13567 次 |
最近记录: |