小编典典

如何在多个代理上对Jenkins管道使用发布步骤?

jenkins

当使用詹金斯管道,其中在不同的代理每个阶段的运行,这是很好的做法,以使用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在电子邮件应发送出去时导致错误消息:

[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 noneagent any,它工作正常。

我如何post不使用就可以上班agent any


阅读 297

收藏
2020-07-25

共1个答案

小编典典

step执行邮寄的包裹在一个node步骤中:

post {
  always {
    node('awesome_node_label') {
      step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "test@test.com", sendToIndividuals: true])
    }
  }
}
2020-07-25