Home > Software engineering >  choose Jenkins post actions agent
choose Jenkins post actions agent

Time:08-02

Is there a way to choose where the post build actions will be executed?

pipeline {
    agent windows

    stages {
        stage('Hello') {
            steps {
                echo 'Hello World'
            }
        }
    }
    
    post {
      // agent linux
      always { 
            echo 'I will always say Hello again!'
        }
    }
}

I want to run the post build actions on linux agent is there a way todo that?

CodePudding user response:

This worked for me in a declarative pipeline

post {
    always {
        node('linux') {
            echo 'I will always say Hello again!'
        }
    }
}

CodePudding user response:

What I wanted to do could be achieved like that:

pipeline {
    agent { label 'linux' }
    stages {
        stage('Setup Agent') {
            agent { label 'windows' }
            stages {
                stage('Hello') {
                    steps {
                        echo 'Hello World'
                    }
                }
            }
        }
    }

    post {
        always {
            echo 'I will always say Hello again!'
        }
    }
}

then the post will run on the agent from the top and the inner stages will run on the inner agent.

  • Related