Gawain
Gawain

Reputation: 1092

How can I specify an agent for post action in Jenkins declarative pipeline

I want to run the post part of my declarative pipeline inside a docker container. And I don't know how to set the agent only for post.

Sample of my pipeline

post {
        always {
            echo 'This will always run'
        }
        success {
            mail ## my mail content;
        }
}

And I want to run this mail command in a docker container.

Upvotes: 7

Views: 5829

Answers (1)

Dibakar Aditya
Dibakar Aditya

Reputation: 4203

You can use the node(...){...} block within the post steps, with or without the script {...} block as applicable:

post {
    always {
        echo 'This will always run'
    }
    success {
        node('docker') {
            script {
                mail ## my mail content;
            }
        }
    }
}

Upvotes: 8

Related Questions