Home > Mobile >  How to specify a container / agent to execute on Kubernetes cluster for Jenkins pipeline post condit
How to specify a container / agent to execute on Kubernetes cluster for Jenkins pipeline post condit

Time:10-29

I want to run the post part of my declarative pipeline inside a container which needs to execute on a kubernetes pod using a specific docker image. And I don't know how to set the agent only for post. I'm executing a specific python script which sends an email in the post condition and to execute the script I need python and pip installed on the agent, my docker image has these pre-requites but I don't know how to create an agent with this docker image in the post step. can anyone help me?

Sample of my pipeline

post {
failure {
  echo "job failed"
}
success {
  echo "job succeeded"
}
always {
  node(null) {
    #Python script call to send email
  }
}

}

CodePudding user response:

You can setup a Pod as follows for the post step using the Jenkins Kubernetes plugin.

 podTemplate(yaml: yamlfile, cloud: cloudName){
    node(POD_LABEL) {
      container(containerName) {
        //steps to perform
      }
    }

More info on how to use the podTemplate at this link: https://www.jenkins.io/doc/pipeline/steps/kubernetes/

  • Related