Is it possible to get persistent Jenkins Kubernetes pods by just using Jenkinsfile (without configuring a global podTemplate in Jenkins UI)?

168 views Asked by At

We build many projects with the multibranch pipeline. Each project has a Jenkinsfile. Each project should reuse existing pods, to benefit from existing scm checkouts and local maven repo caches.

I am not looking for shared persistent volumes: Each pod should build up its own source and dependency caches. It is ok if that cache is lost when the pod is terminated (controlled via podTemplate idleMinutes setting)

Based on my testing, it looks like when podTemplate is defined in the Jenkinsfile, each project will only use it's own pod, and never one that was created by another project.

https://community.jenkins.io/t/how-to-reuse-pod-across-job-executions-without-the-deprecated-label-option/4579/1 seems to suggest that this is only achievable by configuring the podTemplate in the global Jenkins configuration UI, and then selecting it by its label in the Jenkinsfile.

Would be nice if there was a way to it with configuration as code after all.

node(label: 'pod-label-defined-in-global-pod-template') { // 
  container('container-name-defined-in-global-pod-template') {
    ...
  }
}
0

There are 0 answers