2017-06-13 99 views
5

當使用詹金斯管道,其中每個階段都會對不同的代理運行時,它是good practice在開始使用agent none如何在多個代理上使用Jenkins管道的後續步驟?

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: "[email protected]", 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 none更改爲agent any,它工作正常。

如何在不使用agent any的情況下讓post步驟工作?

回答

6

包裹,做的郵件在node步驟step

post { 
    always { 
    node('awesome_node_label') { 
     step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "[email protected]", sendToIndividuals: true]) 
    } 
    } 
} 
+0

我用'節點( '主')',現在它的工作原理。謝謝。如果我省略標籤,則會收到錯誤「WorkflowScript:15:缺少必需參數:」標籤「'。你能調整你的答案嗎? –

+0

確實如此,謝謝! – burnettk

+0

在我問這個問題之前,我嘗試在'post'後面使用'node',這是不允許的,但是我從來沒有想過只包裝'step'。謝謝你的幫助。 –